aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2021-02-13 02:36:55 +0100
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2021-02-13 02:36:55 +0100
commite50dcd700919804e1256b60d39f25c5fc790476b (patch)
tree344fb6a98b0446939b604d039ceb25517dbc6682
parent4ea0f429948bb78f6984d1c2d66fee4f2b2a3f98 (diff)
downloadmtest-e50dcd700919804e1256b60d39f25c5fc790476b.tar.gz
mtest-e50dcd700919804e1256b60d39f25c5fc790476b.tar.bz2
mtest-e50dcd700919804e1256b60d39f25c5fc790476b.zip
mtest.h: move common code to macro to not repeat myself
Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
-rw-r--r--mtest.h44
1 files changed, 24 insertions, 20 deletions
diff --git a/mtest.h b/mtest.h
index d835691..3c7c425 100644
--- a/mtest.h
+++ b/mtest.h
@@ -74,6 +74,26 @@
/* ==========================================================================
+ Some common code to init and finish tests. Internal use only.
+ ========================================================================== */
+
+
+#define _mt_test_init(n) \
+ curr_test = n; \
+ mt_test_status = 0; \
+ ++mt_total_tests; \
+ if (mt_prepare_test) mt_prepare_test();
+
+#define _mt_test_finish() \
+ if (mt_cleanup_test) mt_cleanup_test(); \
+ if (mt_test_status != 0) { \
+ fprintf(stdout, "not ok %d - %s\n", mt_total_tests, curr_test); \
+ ++mt_total_failed; \
+ } else \
+ fprintf(stdout, "ok %d - %s\n", mt_total_tests, curr_test);
+
+
+/* ==========================================================================
macro runs test 'f'. 'f' is just a function (without parenthesis ()).
========================================================================== */
@@ -98,17 +118,9 @@
#define mt_run_named(f, n) do { \
- curr_test = n; \
- mt_test_status = 0; \
- ++mt_total_tests; \
- if (mt_prepare_test) mt_prepare_test(); \
+ _mt_test_init(n); \
f(); \
- if (mt_cleanup_test) mt_cleanup_test(); \
- if (mt_test_status != 0) { \
- fprintf(stdout, "not ok %d - %s\n", mt_total_tests, curr_test); \
- ++mt_total_failed; \
- } else \
- fprintf(stdout, "ok %d - %s\n", mt_total_tests, curr_test); \
+ _mt_test_finish(); \
} while(0)
@@ -121,17 +133,9 @@
#define mt_run_param_named(f, p, n) do { \
- curr_test = n; \
- mt_test_status = 0; \
- ++mt_total_tests; \
- if (mt_prepare_test) mt_prepare_test(); \
+ _mt_test_init(n); \
f(p); \
- if (mt_cleanup_test) mt_cleanup_test(); \
- if (mt_test_status != 0) { \
- fprintf(stdout, "not ok %d - %s\n", mt_total_tests, curr_test); \
- ++mt_total_failed; \
- } else \
- fprintf(stdout, "ok %d - %s\n", mt_total_tests, curr_test); \
+ _mt_test_finish(); \
} while(0)