diff options
Diffstat (limited to 'lily-test.c')
-rw-r--r-- | lily-test.c | 37 |
1 files changed, 37 insertions, 0 deletions
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); |