Shizuka Kamishima avatar Shizuka Kamishima committed d942362 Draft

ex30 - unit testing

Comments (0)

Files changed (1)

c-skeleton/tests/minunit.h

+#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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.