aboutsummaryrefslogtreecommitdiff
path: root/test/test_framework.h
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_framework.h')
-rw-r--r--test/test_framework.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/test_framework.h b/test/test_framework.h
new file mode 100644
index 0000000..7ab4816
--- /dev/null
+++ b/test/test_framework.h
@@ -0,0 +1,25 @@
+#pragma once
+
+
+#define TEST(name) testfn__ ## name
+
+// Test function should return 0 on success, nonzero value on error
+#ifdef TEST_HEADER_GENERATION
+#define DEFINE_TEST(name) XXTEST_DECLARATION(TEST(name))
+#else
+#define DEFINE_TEST(name) int TEST(name)(void)
+#endif
+
+void test_report_error(
+ const char *type, const char *condition, const char *fname, int lineno);
+
+#define EXPECT(cond_) do { \
+ if (!(cond_)) test_report_error("EXPECT", #cond_, __FILE__, __LINE__); \
+ } while (0)
+
+#define EXPECTRET(cond_, ret_) do { \
+ if (!(cond_)) { \
+ test_report_error("EXPECT", #cond_, __FILE__, __LINE__); \
+ return (ret_); \
+ } \
+ }