aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/test.h26
-rw-r--r--src/include/util.h2
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. */