#ifndef TEST_UTILS_H #define TEST_UTILS_H #include #include static int _tests_run = 0; static int _tests_failed = 0; #define ASSERT(expr) do { \ _tests_run++; \ if (!(expr)) { \ fprintf(stderr, "\033[1;31mFAIL\033[0m %s:%d: %s\n", __FILE__, __LINE__, #expr); \ _tests_failed++; \ } \ } while(0) #define TEST_RUN(func) do { \ fprintf(stderr, " RUN %s\n", #func); \ func(); \ } while(0) static inline int test_summary(void) { fprintf(stderr, "\n%d tests, %d passed, %d failed\n", _tests_run, _tests_run - _tests_failed, _tests_failed); return _tests_failed > 0 ? 1 : 0; } #endif