check next value for append_test_log() on empty log

This commit is contained in:
jlamothe 2023-11-21 20:55:58 +00:00
parent e5cad7cd20
commit cb3788cf02
2 changed files with 20 additions and 3 deletions

View File

@ -350,7 +350,7 @@ print_log(TestState *s)
TestLogEntry *e = s->first_log; TestLogEntry *e = s->first_log;
while(e) while(e)
{ {
if(e->text) print("%s\n", e->text); if(e->text) print("\n%s", e->text);
else print("(empty message)\n"); else print("(empty message)\n");
e = e->next; e = e->next;
} }

View File

@ -39,6 +39,7 @@ struct LogData
// Local Prototypes // Local Prototypes
static void append_to_empty(TestState *); static void append_to_empty(TestState *);
static void chk_empty_first(TestState *, void *);
static void append_to_existing(TestState *); static void append_to_existing(TestState *);
static void missing_last(TestState *); static void missing_last(TestState *);
static void missing_first(TestState *); static void missing_first(TestState *);
@ -77,11 +78,27 @@ append_to_empty(TestState *s)
TestState test; TestState test;
mk_sample_state(&test); mk_sample_state(&test);
append_test_log(&test, "foo"); 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); 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 static void
append_to_existing(TestState *s) append_to_existing(TestState *s)
{ {