summaryrefslogtreecommitdiff
path: root/examples/redis-unstable/src/testhelp.h
diff options
context:
space:
mode:
Diffstat (limited to 'examples/redis-unstable/src/testhelp.h')
-rw-r--r--examples/redis-unstable/src/testhelp.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/examples/redis-unstable/src/testhelp.h b/examples/redis-unstable/src/testhelp.h
new file mode 100644
index 0000000..aeae372
--- /dev/null
+++ b/examples/redis-unstable/src/testhelp.h
@@ -0,0 +1,44 @@
+/* This is a really minimal testing framework for C.
+ *
+ * Example:
+ *
+ * test_cond("Check if 1 == 1", 1==1)
+ * test_cond("Check if 5 > 10", 5 > 10)
+ * test_report()
+ *
+ * ----------------------------------------------------------------------------
+ *
+ * Copyright (c) 2009-Present, Redis Ltd.
+ * All rights reserved.
+ *
+ * Licensed under your choice of (a) the Redis Source Available License 2.0
+ * (RSALv2); or (b) the Server Side Public License v1 (SSPLv1); or (c) the
+ * GNU Affero General Public License v3 (AGPLv3).
+ */
+
+#ifndef __TESTHELP_H
+#define __TESTHELP_H
+
+#define REDIS_TEST_ACCURATE (1<<0)
+#define REDIS_TEST_LARGE_MEMORY (1<<1)
+#define REDIS_TEST_VALGRIND (1<<2)
+#define REDIS_TEST_VERBOSE (1<<3)
+
+
+extern int __failed_tests;
+extern int __test_num;
+
+#define test_cond(descr,_c) do { \
+ __test_num++; printf("%d - %s: ", __test_num, descr); \
+ if(_c) printf("PASSED\n"); else {printf("FAILED\n"); __failed_tests++;} \
+} while(0)
+#define test_report() do { \
+ printf("%d tests, %d passed, %d failed\n", __test_num, \
+ __test_num-__failed_tests, __failed_tests); \
+ if (__failed_tests) { \
+ printf("=== WARNING === We have failed tests here...\n"); \
+ exit(1); \
+ } \
+} while(0)
+
+#endif