aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2018-10-08 19:39:40 +0200
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2018-10-08 19:39:40 +0200
commit4f1e81a392e82cc0971bb4ffc4adc125a3c61fa6 (patch)
tree3b0990dfde340643814f56c9f719bfd0d833161c
parenteb40d208ef372acec5a1db82516a072f0afea4c9 (diff)
downloadmtest-4f1e81a392e82cc0971bb4ffc4adc125a3c61fa6.tar.gz
mtest-4f1e81a392e82cc0971bb4ffc4adc125a3c61fa6.tar.bz2
mtest-4f1e81a392e82cc0971bb4ffc4adc125a3c61fa6.zip
add: mt_run_param to run tests with parameters
-rw-r--r--mtest.h39
1 files changed, 36 insertions, 3 deletions
diff --git a/mtest.h b/mtest.h
index 2838e83..132971a 100644
--- a/mtest.h
+++ b/mtest.h
@@ -88,9 +88,17 @@
========================================================================== */
-#define mt_run(f) do { \
- mt_run_named(f, #f); \
- } while (0)
+#define mt_run(f) mt_run_named(f, #f)
+
+
+/* ==========================================================================
+ macro runs test 'f' with parameter 'p'.
+
+ 'p' can be of any type, as long as it matches prototype of 'f' function.
+ ========================================================================== */
+
+
+#define mt_run_param(f, p) mt_run_named_param(f, p, #f)
/* ==========================================================================
@@ -117,6 +125,31 @@
/* ==========================================================================
+ macro runs test 'f' with parameter 'p' and instead of printing function
+ name as a test name, it allows to provide custom name 'n'.
+
+ 'p' can be of any type, as long as it matches prototype of 'f' function.
+ ========================================================================== */
+
+
+#define mt_run_named_param(f, p, n) do { \
+ curr_test = n; \
+ mt_test_status = 0; \
+ ++mt_total_tests; \
+ if (mt_prepare_test) mt_prepare_test(); \
+ 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); \
+ } while(0)
+
+
+/* ==========================================================================
simple assert, when expression 'e' is evaluated to false, assert message
will be logged, and macro will force function to return
========================================================================== */