diff options
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; |