diff --git a/9unit.c b/9unit.c index 4ed2b8a..166fd72 100644 --- a/9unit.c +++ b/9unit.c @@ -389,7 +389,8 @@ reindex(TestState *s) else if (s->last_log) // we have a last log but no first? { s->first_log = s->last_log; - fprint(2, "potential memory leak in test log\n"); + log_test_context(s); + append_test_log(s, "potential memory leak in test log"); } } diff --git a/test/append-test-log.c b/test/append-test-log.c index b3e0aea..3ce40f1 100644 --- a/test/append-test-log.c +++ b/test/append-test-log.c @@ -48,6 +48,9 @@ static void chk_empty_first(TestState *, void *); static void chk_first(TestState *, void *); static void chk_second(TestState *, void *); static void chk_last(TestState *, void *); +static void mf_chk_first(TestState *, void *); +static void mf_chk_second(TestState *, void *); +static void mf_chk_third(TestState*, void *); static void mk_log_data(LogData *); static void chk_ptr_chg( @@ -123,7 +126,7 @@ missing_first(TestState *s) mk_log_data(&ld); ld.state.first_log = 0; append_test_log(&ld.state, "baz"); - chk_ptr_eq(s, "first_log", ld.state.first_log, &ld.second); + test_context_with(s, "first_log", mf_chk_first, &ld); test_context_with(s, "last_log", chk_last, &ld); } @@ -198,6 +201,37 @@ chk_last(TestState *s, void *ptr) free(ld->state.last_log); } +static void +mf_chk_first(TestState *s, void *ptr) +{ + LogData *ld = ptr; + chk_ptr_eq(s, 0, ld->state.first_log, &ld->second); + test_context_with(s, "next", mf_chk_second, ptr); +} + +static void +mf_chk_second(TestState *s, void *ptr) +{ + LogData *ld = ptr; + TestLogEntry *e = ld->second.next; + chk_str_eq(s, "text", e->text, ""); + test_context_with(s, "next", mf_chk_third, ptr); +} + +static void +mf_chk_third(TestState *s, void *ptr) +{ + LogData *ld = ptr; + TestLogEntry *e = ld->second.next->next; + chk_str_eq( + s, + "text", + e->text, + "potential memory leak in test log" + ); + chk_ptr_eq(s, "next", e->next, ld->state.last_log); +} + static void mk_log_data(LogData *ld) {