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