diff options
author | Joel Kronqvist <joelkronqvist@proton.me> | 2024-03-23 17:56:49 +0200 |
---|---|---|
committer | Joel Kronqvist <joelkronqvist@proton.me> | 2024-03-23 18:00:51 +0200 |
commit | e26279107edf7012e6b9cd558aaa09a8f0ca4764 (patch) | |
tree | 2bcd2eb3c6c2ade2e85c9f52ca1fc41d3c720811 /minitest.h | |
download | stdu-e26279107edf7012e6b9cd558aaa09a8f0ca4764.tar.gz stdu-e26279107edf7012e6b9cd558aaa09a8f0ca4764.zip |
Initial commit
Diffstat (limited to 'minitest.h')
-rw-r--r-- | minitest.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/minitest.h b/minitest.h new file mode 100644 index 0000000..c566e48 --- /dev/null +++ b/minitest.h @@ -0,0 +1,31 @@ + +/// Minimal testing library tweaked with +/// reference from `minunit.h` from +/// Jera Design LLC: +/// https://jera.com/techinfo/jtns/jtn002 + +#include <stdio.h> +#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 "`"; \ + return 0; \ +} 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; |