diff options
| author | nasr <nsrddyn@gmail.com> | 2026-04-13 15:33:05 +0200 |
|---|---|---|
| committer | nasr <nsrddyn@gmail.com> | 2026-04-13 15:36:24 +0200 |
| commit | 9d09d66a273f68fae7efb71504bf40c664b91983 (patch) | |
| tree | 41a46c52a01338bf22d5f3ebdf0bb27dc3d33cc1 /source/base/base_test.h | |
feature(main): init
feature(main): init
feature(main): init
feature(main): init
Diffstat (limited to 'source/base/base_test.h')
| -rw-r--r-- | source/base/base_test.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/source/base/base_test.h b/source/base/base_test.h new file mode 100644 index 0000000..fd47abc --- /dev/null +++ b/source/base/base_test.h | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | // TODO(nasr): metaprogram that takes an expected output and generates a test for that specified | ||
| 2 | // function | ||
| 3 | /* base library testing framework */ | ||
| 4 | #ifndef BASE_TEST_H | ||
| 5 | #define BASE_TEST_H | ||
| 6 | |||
| 7 | // helper macro | ||
| 8 | #define show \ | ||
| 9 | do \ | ||
| 10 | { \ | ||
| 11 | write(STDOUT_FILENO, __FILE__, sizeof(__FILE__) - 1); \ | ||
| 12 | write(STDOUT_FILENO, ":", 1); \ | ||
| 13 | write(STDOUT_FILENO, __func__, sizeof(__func__) - 1); \ | ||
| 14 | write(STDOUT_FILENO, ":", 1); \ | ||
| 15 | write_int(__LINE__); \ | ||
| 16 | write(STDOUT_FILENO, "\n", 1); \ | ||
| 17 | } while (0) | ||
| 18 | |||
| 19 | #define test(expr) \ | ||
| 20 | { \ | ||
| 21 | if ((expr) != 0) \ | ||
| 22 | { \ | ||
| 23 | write(STDERR_FILENO, "[FAILED] ", LEN("[FAILED] ")); \ | ||
| 24 | show; \ | ||
| 25 | _exit(1); \ | ||
| 26 | } \ | ||
| 27 | } | ||
| 28 | |||
| 29 | #define verify(expr) \ | ||
| 30 | { \ | ||
| 31 | if ((expr) != 0) \ | ||
| 32 | { \ | ||
| 33 | write(STDERR_FILENO, RED "[ERROR] ", LEN(RED "[ERROR] ")); \ | ||
| 34 | show; \ | ||
| 35 | write(STDERR_FILENO, RESET, LEN(RESET)); \ | ||
| 36 | _exit(1); \ | ||
| 37 | } \ | ||
| 38 | else \ | ||
| 39 | { \ | ||
| 40 | write(STDERR_FILENO, GREEN "[SUCCESS] ", LEN(GREEN "[SUCCESS] ")); \ | ||
| 41 | show; \ | ||
| 42 | write(STDERR_FILENO, RESET, LEN(RESET)); \ | ||
| 43 | } \ | ||
| 44 | } | ||
| 45 | |||
| 46 | #endif /* BASE_TEST_H */ | ||
