aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2018-01-15 17:56:20 +0100
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2018-01-15 17:56:20 +0100
commit0f604c8da38444fa584bf95be6c0230784b0c953 (patch)
tree2560605fbb4daa980e30ebaf33bf7073b54cce98
parent6f14be4895d069e497fc1867067c527342bdd990 (diff)
downloadmtest-0f604c8da38444fa584bf95be6c0230784b0c953.tar.gz
mtest-0f604c8da38444fa584bf95be6c0230784b0c953.tar.bz2
mtest-0f604c8da38444fa584bf95be6c0230784b0c953.zip
add: mt_run_named macro to run test with custom name
-rw-r--r--Makefile1
-rw-r--r--example/Makefile2
-rw-r--r--example/tests.c7
-rw-r--r--mt_assert.32
-rw-r--r--mt_defs.32
-rw-r--r--mt_fok.32
-rw-r--r--mt_return.32
-rw-r--r--mt_run.310
-rw-r--r--mt_run_named.31
-rw-r--r--mtest.h15
-rw-r--r--mtest_overview.74
11 files changed, 39 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index 8344d2a..10b0ac9 100644
--- a/Makefile
+++ b/Makefile
@@ -12,3 +12,4 @@ install:
install -m 0644 -D -t $(DESTDIR)/share/man/man3 mt_assert.3
install -m 0644 -D -t $(DESTDIR)/share/man/man3 mt_return.3
install -m 0644 -D -t $(DESTDIR)/share/man/man3 mt_run.3
+ install -m 0644 -D -t $(DESTDIR)/share/man/man3 mt_run_named.3
diff --git a/example/Makefile b/example/Makefile
index ede4dd4..e166af7 100644
--- a/example/Makefile
+++ b/example/Makefile
@@ -1,4 +1,4 @@
-SRCS = add-tests.c calc.c sub-tests.c tests.c
+SRCS = add-tests.c calc.c sub-tests.c tests.c named-tests.c
OBJS = $(SRCS:.c=.o)
all: example
diff --git a/example/tests.c b/example/tests.c
index f2a7c75..c6bbdec 100644
--- a/example/tests.c
+++ b/example/tests.c
@@ -2,6 +2,7 @@
#include "add-tests.h"
#include "sub-tests.h"
+#include "named-tests.h"
#include "calc.h"
@@ -40,6 +41,12 @@ int main(void)
mt_run(sub_test);
/*
+ * run named tests
+ */
+
+ named_test_in_loop();
+
+ /*
* and at the end we call mt_return, which will print clousure information
* and will exit test program with apropriate return code
*/
diff --git a/mt_assert.3 b/mt_assert.3
index b71d25d..961f21d 100644
--- a/mt_assert.3
+++ b/mt_assert.3
@@ -1,4 +1,4 @@
-.TH "MT_ASSERT" "3" "29 Nov 2017 (v1.0.0)" "bofc.pl"
+.TH "MT_ASSERT" "3" "15 January 2018 (v1.1.0)" "bofc.pl"
.SH NAME
mt_assert, mt_fail - test checks macros
diff --git a/mt_defs.3 b/mt_defs.3
index 3e92b2a..8408842 100644
--- a/mt_defs.3
+++ b/mt_defs.3
@@ -1,4 +1,4 @@
-.TH "MT_DEFS" "3" "29 Nov 2017 (v1.0.0)" "bofc.pl"
+.TH "MT_DEFS" "3" "15 January 2018 (v1.1.0)" "bofc.pl"
.SH NAME
mt_defs, mt_defs_ext - defines variables for test framework
diff --git a/mt_fok.3 b/mt_fok.3
index 83e66ea..70df794 100644
--- a/mt_fok.3
+++ b/mt_fok.3
@@ -1,4 +1,4 @@
-.TH "MT_FOK" "3" "29 Nov 2017 (v1.0.0)" "bofc.pl"
+.TH "MT_FOK" "3" "15 January 2018 (v1.1.0)" "bofc.pl"
.SH NAME
mt_fok, mt_ferr - shortcut macro to test if function executed as expected.
diff --git a/mt_return.3 b/mt_return.3
index 7de5dee..8535642 100644
--- a/mt_return.3
+++ b/mt_return.3
@@ -1,4 +1,4 @@
-.TH "MT_RETURN" "3" "29 Nov 2017 (v1.0.0)" "bofc.pl"
+.TH "MT_RETURN" "3" "15 January 2018 (v1.1.0)" "bofc.pl"
.SH NAME
mt_return - finishes test execution
diff --git a/mt_run.3 b/mt_run.3
index 709c024..7962b84 100644
--- a/mt_run.3
+++ b/mt_run.3
@@ -1,4 +1,4 @@
-.TH "MT_RUN" "3" "29 Nov 2017 (v1.0.0)" "bofc.pl"
+.TH "MT_RUN" "3" "15 January 2018 (v1.1.0)" "bofc.pl"
.SH NAME
mt_run - runs specific test
@@ -12,6 +12,8 @@ c/c++
.br
.BI "mt_run(" function_name ")"
.br
+.BI "mt_run_named(" function_name ", " test_name ")"
+.br
.br
.BI "static void (*" mt_prepare_test ")(void)"
.br
@@ -29,6 +31,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.
+\fBmt_run_named\fR() works similar, but also takes \fItest_name\fR, that will
+be printed instead of \fIfunction_name\fR when reporting test results.
+\fItest_name\fR should be simple \fBconst char *\fR.
+
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.
@@ -56,6 +62,8 @@ static void test(void)
int main(void)
{
mt_run(test);
+ mt_run_named(test, "test param 1");
+ mt_run_named(test, "test_param 2");
mt_return();
}
diff --git a/mt_run_named.3 b/mt_run_named.3
new file mode 100644
index 0000000..7c9fe17
--- /dev/null
+++ b/mt_run_named.3
@@ -0,0 +1 @@
+.so man3/mt_run.3
diff --git a/mtest.h b/mtest.h
index 2efaac5..f578d94 100644
--- a/mtest.h
+++ b/mtest.h
@@ -3,7 +3,7 @@
Author: Michał Łyszczek <michal.lyszczek@bofc.pl>
==========================================================================
__________________________________________________________
- / mtest version v1.0.0 \
+ / mtest version v1.1.0 \
| |
| Simple test framework that uses TAP output format |
\ http://testanything.org /
@@ -85,7 +85,18 @@
#define mt_run(f) do { \
- curr_test = #f; \
+ mt_run_named(f, #f); \
+ } while (0)
+
+
+/* ==========================================================================
+ macro runs test 'f' and instead of printing function name as a test name
+ it allows to provide custom name 'n'
+ ========================================================================== */
+
+
+#define mt_run_named(f, n) do { \
+ curr_test = n; \
mt_test_status = 0; \
++mt_total_tests; \
if (mt_prepare_test) mt_prepare_test(); \
diff --git a/mtest_overview.7 b/mtest_overview.7
index 7356d21..992ef5a 100644
--- a/mtest_overview.7
+++ b/mtest_overview.7
@@ -1,4 +1,4 @@
-.TH "MTEST" "7" "29 Nov 2017 (v1.0.0)" "bofc.pl"
+.TH "MTEST" "7" "15 January 2018 (v1.1.0)" "bofc.pl"
.SH "NAME"
\fBmtest_overview\fR - overview of \fBmtest\fR testing framework
@@ -16,6 +16,8 @@ For c/c++
.br
.BI "mt_run(" function_name ")"
.br
+.BI "mt_run_named(" function_name ", " test_name ")"
+.br
.BI "mt_assert(" expression ")"
.br
.BI "mt_fail(" expression ")"