summaryrefslogtreecommitdiffstats
path: root/nserver/tests
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2019-08-24 19:26:17 -0400
committerrsiddharth <s@ricketyspace.net>2020-04-17 20:56:33 -0400
commit0c5b08ea58f88252e950ecaf40125a22b79fa83c (patch)
tree89508d0e0d6afc6cb6379bde9139777af5341160 /nserver/tests
Add nserver.
For now it contains only "statserve".
Diffstat (limited to 'nserver/tests')
-rw-r--r--nserver/tests/minunit.h33
-rw-r--r--nserver/tests/runtests.sh19
2 files changed, 52 insertions, 0 deletions
diff --git a/nserver/tests/minunit.h b/nserver/tests/minunit.h
new file mode 100644
index 0000000..a7cb280
--- /dev/null
+++ b/nserver/tests/minunit.h
@@ -0,0 +1,33 @@
+#undef NDEBUG
+#ifndef _minunit_h
+#define _minunit_h
+
+#include <stdio.h>
+#include <dbg.h>
+#include <stdlib.h>
+
+#define mu_suite_start() char *message = NULL
+
+#define mu_assert(test, message) if (!(test)) {\
+ log_err(message); return message; }
+#define mu_run_test(test) debug("\n-----%s", " " #test); \
+ message = test(); tests_run++; if (message) return message;
+
+#define RUN_TESTS(name) int main(int argc, char *argv[]) {\
+ argc = 1; \
+ debug("----- RUNNING: %s", argv[0]); \
+ printf("----\nRUNNING: %s\n", argv[0]);\
+ char *result = name();\
+ if (result != 0) {\
+ printf("FAILED: %s\n", result); \
+ }\
+ else {\
+ printf("ALL TESTS PASSED\n");\
+ }\
+ printf("Tests run: %d\n", tests_run);\
+ exit(result != 0);\
+ }
+
+int tests_run;
+
+#endif
diff --git a/nserver/tests/runtests.sh b/nserver/tests/runtests.sh
new file mode 100644
index 0000000..ff579a3
--- /dev/null
+++ b/nserver/tests/runtests.sh
@@ -0,0 +1,19 @@
+echo "Running unit tests:"
+
+for i in tests/*_tests
+do
+ if test -f $i
+ then
+ if $VALGRIND ./$i 2>> tests/tests.log
+ then
+ echo $i PASS
+ else
+ echo "ERROR in test $i: here's tests/tests.log"
+ echo "------"
+ tail tests/tests.log
+ exit 1
+ fi
+ fi
+done
+
+echo ""