From cb3788cf02ebc4f8ad4b10c6de9dedc12cffa31f Mon Sep 17 00:00:00 2001 From: jlamothe Date: Tue, 21 Nov 2023 20:55:58 +0000 Subject: [PATCH] check next value for append_test_log() on empty log --- 9unit.c | 2 +- test/append-test-log.c | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/9unit.c b/9unit.c index c9870f1..4ed2b8a 100644 --- a/9unit.c +++ b/9unit.c @@ -350,7 +350,7 @@ print_log(TestState *s) TestLogEntry *e = s->first_log; while(e) { - if(e->text) print("%s\n", e->text); + if(e->text) print("\n%s", e->text); else print("(empty message)\n"); e = e->next; } diff --git a/test/append-test-log.c b/test/append-test-log.c index c616591..5168e95 100644 --- a/test/append-test-log.c +++ b/test/append-test-log.c @@ -39,6 +39,7 @@ struct LogData // Local Prototypes static void append_to_empty(TestState *); +static void chk_empty_first(TestState *, void *); static void append_to_existing(TestState *); static void missing_last(TestState *); static void missing_first(TestState *); @@ -77,11 +78,27 @@ append_to_empty(TestState *s) TestState test; mk_sample_state(&test); append_test_log(&test, "foo"); - chk_ptr_ne(s, "first_log", test.first_log, 0); - chk_str_eq(s, "first_log->text", test.first_log->text, "foo"); + + // first_log + test_context_with( + s, + "first_log", + chk_empty_first, + &test + ); + + // last_log chk_ptr_eq(s, "last_log", test.last_log, test.first_log); } +static void +chk_empty_first(TestState *s, void *ptr) +{ + TestState *test = ptr; + chk_str_eq(s, "text", test->first_log->text, "foo"); + chk_ptr_eq(s, "next", test->first_log->next, 0); +} + static void append_to_existing(TestState *s) {