43 #include <sys/clock.h> 50 const char *
const descr;
51 const char *
const test_file;
59 typedef void (*unit_test_report_function_t)(
const unit_test_t *);
71 #define UNIT_TEST_REGISTER(name, description) \ 72 static unit_test_t unit_test_##name = \ 73 {.descr = (description), \ 74 .test_file = __FILE__, \ 101 #define UNIT_TEST(name) static void unit_test_function_##name(unit_test_t *unit_test_ptr) 106 #define UNIT_TEST_BEGIN() do { \ 107 unit_test_ptr->start = clock_time(); \ 108 unit_test_ptr->assertions = 0; \ 109 unit_test_ptr->passed = true; \ 115 #define UNIT_TEST_END() UNIT_TEST_SUCCEED(); \ 117 unit_test_ptr->end = clock_time() 125 #ifndef UNIT_TEST_PRINT_FUNCTION 126 #define UNIT_TEST_PRINT_FUNCTION unit_test_print_report 134 #define UNIT_TEST_PRINT_REPORT(name) UNIT_TEST_PRINT_FUNCTION(&unit_test_##name) 141 #define UNIT_TEST_RUN(name) do { \ 142 unit_test_function_##name(&unit_test_##name); \ 143 UNIT_TEST_PRINT_REPORT(name); \ 157 #define UNIT_TEST_SUCCEED() do { \ 158 unit_test_ptr->exit_line = __LINE__; \ 159 goto unit_test_end; \ 169 #define UNIT_TEST_FAIL() do { \ 170 unit_test_ptr->exit_line = __LINE__; \ 171 unit_test_ptr->passed = false; \ 172 goto unit_test_end; \ 180 #define UNIT_TEST_ASSERT(expr) do { \ 181 unit_test_ptr->assertions++; \ 197 #define UNIT_TEST_PASSED(name) (unit_test_##name.passed) 200 void UNIT_TEST_PRINT_FUNCTION(
const unit_test_t *unit_test_ptr);
struct unit_test unit_test_t
The unit_test structure describes the results of a unit test.
The unit_test structure describes the results of a unit test.