diff options
-rw-r--r-- | lily-test.c | 37 | ||||
-rw-r--r-- | lily-test.h | 8 |
2 files changed, 45 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); diff --git a/lily-test.h b/lily-test.h index 7a46cd9..7270272 100644 --- a/lily-test.h +++ b/lily-test.h @@ -26,6 +26,14 @@ struct lily_globals_t { extern struct lily_globals_t _lily_globals; void lily_init(); +typedef void (*lily_test_t)(void); + +#define lily_run_test(test) _lily_run_test(#test, test) +void _lily_run_test(const char *name, lily_test_t test); + +#define lily_run_suite(suite) _lily_run_suite(#suite, suite); +void _lily_run_suite(const char *name, lily_test_t suite); + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * |