From 10e56d32931ad26d79ac726a36366664cf4d8b63 Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 24 Apr 2022 12:49:07 -0500 Subject: add test- and suite-running functions --- lily-test.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'lily-test.c') diff --git a/lily-test.c b/lily-test.c index 1e7e5f4..9711399 100644 --- a/lily-test.c +++ b/lily-test.c @@ -7,6 +7,7 @@ struct lily_globals_t _lily_globals; +/* set the initial values of lily globals */ void lily_init() { _lily_globals.error_msg_len = 0; @@ -14,6 +15,40 @@ void lily_init() _lily_globals.error_location = ""; } +/* run an individual test */ +void _lily_run_test(const char *name, lily_test_t test) +{ + printf(" %s: ", name); + + _lily_globals.error_msg = NULL; + _lily_globals.error_location = ""; + int val = setjmp(_lily_globals.env); + + test(); + + if (val == 0) { + /* test succeeded */ + printf("OK\n"); + } + else { + /* test failed */ + printf("FAIL - %s (%s)\n", + _lily_globals.error_msg, + _lily_globals.error_location); + free(_lily_globals.error_msg); /* error message was allocated! */ + } +} + +/* run a suite */ +void _lily_run_suite(const char *name, lily_test_t suite) +{ + printf("=== %s ===\n", name); + suite(); + printf("\n"); +} + + +/* ======== ASSERTIONS ======== */ static void _lily_assert_msg(bool statement, const char *location, const char *format_string, va_list args) @@ -187,6 +222,8 @@ void _lily_assert_memory_not_equal(const char *name_a, const char *name_b, } +/* ======== MOCKS ======== */ + lily_queue_t* lily_queue_create() { const size_t size = 256 * sizeof(uint8_t); -- cgit v1.2.1