aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKenny Levinsen <kl@kl.wtf>2020-08-31 14:30:28 +0200
committerKenny Levinsen <kl@kl.wtf>2020-08-31 14:40:58 +0200
commitaef19fe383a70f47fa83a70cfce70fa4a713c1d1 (patch)
tree521611c3bb6f44b2b8978380fd53248025c621e1 /include
parent8610ec4aac6027e702d0aaea0331ccaa41489834 (diff)
test: Add test_run and test_assert macros
test_run and test_assert replaces regular assert with better logging which include the currently running test name. The tests can now also be built without DEBUG.
Diffstat (limited to 'include')
-rw-r--r--include/test.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/include/test.h b/include/test.h
new file mode 100644
index 0000000..64716cc
--- /dev/null
+++ b/include/test.h
@@ -0,0 +1,23 @@
+#ifndef _TEST_H
+#define _TEST_H
+
+char *__curtestname = "<none>";
+
+#define test_run(func) \
+ do { \
+ char *orig = __curtestname; \
+ __curtestname = #func; \
+ func(); \
+ __curtestname = orig; \
+ } while (0)
+
+#define test_assert(cond) \
+ do { \
+ if (!(cond)) { \
+ fprintf(stderr, "%s:%d: %s: test_assert failed: %s\n", __FILE__, __LINE__, \
+ __curtestname, #cond); \
+ abort(); \
+ } \
+ } while (0)
+
+#endif