From 6a966d621c48118ab1a97db13473b78b2884ace1 Mon Sep 17 00:00:00 2001 From: c Date: Wed, 13 Dec 2023 14:49:19 -0500 Subject: Added tests again. --- src/include/test.h | 26 ++++++++++++++++++++++++++ src/include/util.h | 2 ++ 2 files changed, 28 insertions(+) create mode 100644 src/include/test.h (limited to 'src/include') 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. */ -- cgit v1.2.3