diff options
author | c | 2023-12-13 14:49:19 -0500 |
---|---|---|
committer | c | 2023-12-13 14:49:19 -0500 |
commit | 6a966d621c48118ab1a97db13473b78b2884ace1 (patch) | |
tree | f0607da8284f4081970325c37eb7ea409de68a9f /src/include | |
parent | d8fcdcc5491ae053ebf0586a8093cda6781af51a (diff) |
Added tests again.
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/test.h | 26 | ||||
-rw-r--r-- | src/include/util.h | 2 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/include/test.h b/src/include/test.h new file mode 100644 index 0000000..0b60add --- /dev/null +++ b/src/include/test.h @@ -0,0 +1,26 @@ +#ifndef TEST_H +#define TEST_H + +#include "util.h" + +#ifdef TEST + +unsigned int TESTS_RUN = 0; +unsigned int TESTS_PASSED = 0; + +#define ASSERT(EXPR) \ + TESTS_RUN++; \ + (EXPR && ++TESTS_PASSED) ? \ + log_yay("Assertion passed!") : \ + log_err("%s:%d: Assertion failed:\n\t%s", __FILE__, __LINE__, #EXPR); + +#define TEST_REPORT \ + (TESTS_RUN == TESTS_PASSED) ? \ + log_yay("All %d tests passed!", TESTS_RUN) : \ + log_err("%d/%d tests failed.", TESTS_RUN - TESTS_PASSED, TESTS_RUN); + +#else +#define ASSERT(EXPR) NULL; +#endif + +#endif diff --git a/src/include/util.h b/src/include/util.h index cf59a44..15f862e 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -8,6 +8,8 @@ /* Log some debug information. */ void log_dbg(const char*, ...); +/* Log some congratulatory information. */ +void log_yay(const char*, ...); /* Log some information. */ void log_inf(const char*, ...); /* Log something with no formatting. */ |