/// Minimal testing library tweaked with /// reference from `minunit.h` from /// Jera Design LLC: /// https://jera.com/techinfo/jtns/jtn002 #include #define mt_assert(test, message) do { if (!(test)) return message; } while (0) #define mt_assert_eq(left, right) do { \ if (left != right) \ return "`" #left "` didn't match `" #right "`"; \ } while (0) #define mt_run_test(test) do { \ char *message = test(); \ if (message) { \ fprintf(stderr, "[FAIL] " #test ": %s\n", message); \ tests_failed++; \ } else { \ fprintf(stderr, "[PASS] " #test "\n"); \ } \ tests_run++; \ } while (0) #define mt_test_report() do { \ if (tests_failed == 0) \ fprintf(stderr, "[REPORT] All %d tests passed.\n", tests_run); \ else \ fprintf(stderr, "[REPORT] Failure. %d/%d tests failed.\n", tests_failed, tests_run); \ } while (0) extern int tests_run; extern int tests_failed;