aboutsummaryrefslogtreecommitdiff
path: root/src/include/test.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/test.h')
-rw-r--r--src/include/test.h26
1 files changed, 26 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