aboutsummaryrefslogtreecommitdiffstats
path: root/man/mt_run.3
blob: 648c7d2cc20bceca3dfb2a14668b88ebfc3849af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
.TH "MT_RUN" "3" "29 April 2020 (v1.3.0)" "bofc.pl"
.SH NAME
.PP
.B mt_run
- runs specific test
.SH SYNOPSIS
.PP
c/c++
.PP
.B #include <mtest.h>
.PP
.BI "void (*" function_name ")(void)"
.br
.BI "void (*" function_name_param ")(void *" parameter ")"
.PP
.BI "mt_run(" function_name ")"
.br
.BI "mt_run_param(" function_name_param ", " parameter ")"
.br
.BI "mt_run_named(" function_name ", " test_name ")"
.br
.BI "mt_run_param_named(" function_name_param ", " parameter ", " test_name ")"
.PP
.BI "static void (*" mt_prepare_test ")(void)"
.br
.BI "static void (*" mt_cleanup_test ")(void)"
.PP
shell
.PP
.BI "mt_run <" function_name "> [" param1 "] [" ... "]"
.br
.BI "mt_run_named <" function_name "> <" test_name "> [" param1 "] \
[" ... "]"
.SH DESCRIPTION
.PP
.BR mt_run (3)
runs a single test specified in
.IR function_name .
Inside function you can call
.BR mt_assert (3)
and
.BR mt_fail (3).
If none if these functions are called inside test function,
.B mtest
will mark test as successful.
After function finishes its work,
.BR mt_run (3)
will print test status and a
.I function_name
to know which test passed or failed.
.PP
.BR mt_run_named (3)
works similar, but also takes
.IR test_name ,
that will be printed instead of
.I function_name
when reporting test results.
.I test_name
should be simple
.B const char *.
.PP
.BR mt_run_param (3)
and
.BR mt_run_param_named (3)
works in the same way as they non-parameter counterpart, but
.I parameter
will be passed to
.IR function_name_param .
When using shell functions, there is no
.I param
functions, but you can pass unspecified number of parameters to both
.BR mt_run (3)
and
.BR mt_run_named (3).
Since
.I function_name
is run via
.B eval
program, when you want to pass parameter with spaces, you need to use
double quotes like
.BR """'parameter\ with\ spaces'""" .
.PP
Optionally user can also set two function pointers
.I mt_prepare_test
and
.I mt_cleanup_test
that take no argument and return nothing.
These functions will be called before and after calling test
.IR function_name .
.PP
When testing from shell, it is only neccessary to define functions
.I mt_prepare_test
and
.I mt_cleanup_test
and
.B mtest
will use then automatically
.SH EXAMPLE
.PP
c/c++
.PP
.EX
    #include <mtest.h>
    #include "foo.h"

    mt_defs();

    static void test_param(void *param)
    {
        mt_assert(bar((int *)i) == 0);
    }

    static void test(void)
    {
        mt_assert(foo() == 0);
    }

    int main(void)
    {
        int i;

        mt_run(test);
        mt_run_named(test, "test param 1");
        mt_run_named(test, "test_param 2");

        for (i = 0; i != 5; ++i)
        {
            mt_run_param(test_param, &i);
        }

        mt_return();
    }
.EX
.PP
shell
.PP
.EX
    #!/bin/sh

    . ./mtest.sh

    test_two()
    {
        a=$1
        b=$2
        c=$((a + b))
        mt_fail "[ $b -eq $(( c - a )) ]"
    }

    test_one()
    {
        a=1
        a=$((a + 1))
        mt_fail "[ $a -eq 2 ]"
    }

    mt_run test_one
    mt_run test_two 5 3

    mt_return
.EE
.SH "SEE ALSO"
.PP
.BR mt_defs (3),
.BR mt_defs_ext (3),
.BR mt_assert (3),
.BR mt_fail (3),
.BR mt_fok (3),
.BR mt_ferr (3),
.BR mt_return (3)
.BR mtest_overview (7),