From e26279107edf7012e6b9cd558aaa09a8f0ca4764 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sat, 23 Mar 2024 17:56:49 +0200 Subject: Initial commit --- minitest.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 minitest.h (limited to 'minitest.h') 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 +#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; -- cgit v1.2.3