display pass/fail/pend status in realtime

This commit is contained in:
jlamothe 2023-11-21 20:02:53 +00:00
parent da33bd8955
commit e5cad7cd20

15
9unit.c
View File

@ -119,10 +119,10 @@ run_tests(void (*tests)(TestState *))
s.report = report; s.report = report;
(*tests)(&s); (*tests)(&s);
print_log(&s); print_log(&s);
printf("Tests run: %d\n", s.run); print("\n\nTests run: %d\n", s.run);
printf("Tests passed: %d\n", s.passed); print("Tests passed: %d\n", s.passed);
printf("Tests failed: %d\n", s.failed); print("Tests failed: %d\n", s.failed);
printf("Tests pending: %d\n", s.pending); print("Tests pending: %d\n", s.pending);
clear_log(&s); clear_log(&s);
if (s.failed) exits("test(s) failed"); if (s.failed) exits("test(s) failed");
} }
@ -182,12 +182,15 @@ run_test(TestState *s, TestResult (*t)(TestState *))
{ {
case test_success: case test_success:
s->passed++; s->passed++;
s->report(" [PASS]");
break; break;
case test_failure: case test_failure:
s->failed++; s->failed++;
s->report(" [FAIL]");
break; break;
case test_pending: case test_pending:
s->pending++; s->pending++;
s->report(" [PEND]");
break; break;
default: default:
exits("test returned an invalid response"); exits("test returned an invalid response");
@ -347,7 +350,7 @@ print_log(TestState *s)
TestLogEntry *e = s->first_log; TestLogEntry *e = s->first_log;
while(e) while(e)
{ {
if(e->text) printf("%s\n", e->text); if(e->text) print("%s\n", e->text);
else print("(empty message)\n"); else print("(empty message)\n");
e = e->next; e = e->next;
} }
@ -419,10 +422,10 @@ build_new_context(TestState *s, ContextData *cd)
static void static void
display_context(TestState *s) display_context(TestState *s)
{ {
s->report("\n");
for (int i = 1; i < s->depth; i++) for (int i = 1; i < s->depth; i++)
s->report("\t"); s->report("\t");
s->report(s->context); s->report(s->context);
s->report("\n");
} }
static void static void