aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2017-10-24 09:17:49 +0200
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2017-10-24 09:17:49 +0200
commite54cee1bfa049b8d1bff7007967150af665e7b67 (patch)
treeef155b33a9ea38e220b4121ce53e92b99871411b
parentf125c6402c5dc8de2098a89ca73fc329463850bd (diff)
downloadmtest-e54cee1bfa049b8d1bff7007967150af665e7b67.tar.gz
mtest-e54cee1bfa049b8d1bff7007967150af665e7b67.tar.bz2
mtest-e54cee1bfa049b8d1bff7007967150af665e7b67.zip
Added automatic function call before/after test
-rw-r--r--mt_run.39
-rw-r--r--mtest.h13
2 files changed, 18 insertions, 4 deletions
diff --git a/mt_run.3 b/mt_run.3
index f66af33..f15cd04 100644
--- a/mt_run.3
+++ b/mt_run.3
@@ -9,6 +9,11 @@ mt_run - runs specific test
.BI "void (*" function_name ")(void)
.br
.BI "mt_run(" function_name ")"
+.br
+.br
+.BI "static void (*" mt_prepare_test ")(void)"
+.br
+.BI "static void (*" mt_cleanup_test ")(void)"
.sp
.SH DESCRIPTION
@@ -18,6 +23,10 @@ functions is called inside test function, \fBmtest\fR will mark test as
successful. After function finishes its work, \fBmt_run\fR() will print test
status and a \fIfunction_name\fR to know which test passed or failed.
+Optionally user can also set two function pointers \fImt_prepare_test\fR and
+\fImt_cleanup_test\fR that take no argument and return nothing. These functions
+will be called before and after calling test \fIfunction_name\fR.
+
.SH EXAMPLE
.nf
diff --git a/mtest.h b/mtest.h
index 4342264..27b6b39 100644
--- a/mtest.h
+++ b/mtest.h
@@ -4,7 +4,7 @@
========================================================================== */
-/* ==== mtest version v0.2.0 ================================================ */
+/* ==== mtest version v0.1.0 ================================================ */
/* ==========================================================================
@@ -31,7 +31,9 @@
const char *curr_test; \
int mt_test_status; \
int mt_total_tests = 0; \
- int mt_total_failed = 0
+ int mt_total_failed = 0; \
+ static void (*mt_prepare_test)(void); \
+ static void (*mt_cleanup_test)(void)
/* ==========================================================================
@@ -45,7 +47,9 @@
extern const char *curr_test; \
extern int mt_test_status; \
extern int mt_total_tests; \
- extern int mt_total_failed;
+ extern int mt_total_failed; \
+ static void (*mt_prepare_test)(void); \
+ static void (*mt_cleanup_test)(void)
/* ==========================================================================
@@ -57,7 +61,9 @@
curr_test = #f; \
mt_test_status = 0; \
++mt_total_tests; \
+ if (mt_prepare_test) mt_prepare_test(); \
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); \
@@ -120,7 +126,6 @@
mt_fail(errno == errn); \
} while (0)
-
/* ==========================================================================
prints test plan, in format 1..<number_of_test_run>. If all tests have
passed, macro will return current function with code 0, else it returns