void CuAssertStrNotEqual_LineMsg(CuTest* tc, const char* file, int line, const char* message, const char* expected, const char* actual) { char *string = NULL; if (expected != NULL && actual != NULL && strcmp(expected, actual) != 0) return; if (message != NULL) { asprintf_or_die(&string, "%s: expected <%s> but was <%s>", message, expected, actual); } else { asprintf_or_die(&string, "expected <%s> but was <%s>", expected, actual); } CuFailInternal(tc, file, line, string); }
static void CuFailInternal(CuTest* tc, const char* file, int line, const char *string) { char *buf = NULL; asprintf_or_die(&buf, "%s:%d: %s", file, line, string); tc->failed = 1; tc->message = buf; if (tc->jumpBuf != 0) longjmp(*(tc->jumpBuf), 0); }
void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, const char* message) { char *string = NULL; if (message2 != NULL) { asprintf_or_die(&string, "%s:%s", message2, message); } else { string = strdup(message); } CuFailInternal(tc, file, line, string); }
void CuSuiteDetails(CuSuite* testSuite, char **details) { int i; int failCount = 0; char *s = NULL; if (testSuite->failCount == 0) { int passCount = testSuite->count - testSuite->failCount; const char* testWord = passCount == 1 ? "test" : "tests"; asprintf_or_die(&s, "OK (%d %s)\n", passCount, testWord); string_append(details, s); free(s); } else { if (testSuite->failCount == 1) string_append(details, "There was 1 failure:\n"); else { asprintf_or_die(&s, "There were %d failures:\n", testSuite->failCount); string_append(details, s); free(s); } for (i = 0 ; i < testSuite->count ; ++i) { CuTest* testCase = testSuite->list[i]; if (testCase->failed) { failCount++; asprintf_or_die(&s, "%d) %s:\n%s\n", failCount, testCase->name, testCase->message); string_append(details, s); free(s); } } string_append(details, "\n!!!FAILURES!!!\n"); asprintf_or_die(&s, "Runs: %d ", testSuite->count); string_append(details, s); free(s); asprintf_or_die(&s, "Passes: %d ", testSuite->count - testSuite->failCount); string_append(details, s); free(s); asprintf_or_die(&s, "Fails: %d\n", testSuite->failCount); string_append(details, s); free(s); } }