aboutsummaryrefslogtreecommitdiffstats
path: root/man/mt_assert.3
blob: f88eca8f5d03f5d0853a3538df7458fa9f73b015 (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
.TH "MT_ASSERT" "3" "29 April 2020 (v1.3.0)" "bofc.pl"
.SH NAME
.PP
.BR mt_assert ,
.B mt_fail
- test checks macros
.SH SYNOPSIS
.PP
c/c++
.PP
.B #include <mtest.h>
.PP
.BI "mt_assert(" expression ")"
.br
.BI "mt_fail(" expression ")"
.PP
shell
.PP
.BI "mt_fail <" expression "> [" error_message "]"
.br
.BI "mt_dfail <" command "> [" argumnet "] ..."
.SH DESCRIPTION
.PP
Macro
.BR mt_assert (3)
evaluates
.I expression
and if it evaluates to false, test will be marked as failed and information
about assert will be printed.
Information contains
.BR function_name ,
line where assert occured, and
.I expression
that caused test to fail.
Also macro forces function it was called in to immediately return.
.PP
.BR mt_fail (3)
works just as
.BR mt_assert (3)
but function is not forced to exit and can continue execution.
This is good when test allocates some memory and we need to clean up before
returning.
.PP
For shell scripting,
.BR mt_fail (3)
passed
.I expression
to eval.
.I expression
must be single argument, so it should be closed in "" to preserve spaces.
If
.I expression
is easy and does not require
.B eval
to process, one can use
.BR mt_dfail (3)
which passes all arguments directly to if statement
.BR """if ! ${@}""" .
Normally when
.BR mt_fail (3)
fails, it prints
.B # assert
.I expression
on stderr, but you can instead print own message by passing second argument
to
.BR mt_fail (3).
This string will be directly passed to
.B echo
command.
.SH EXAMPLE
.PP
Proper example can be found in
.BR mtest_overview (7).
.SH "SEE ALSO"
.PP
.BR mt_defs (3),
.BR mt_defs_ext (3),
.BR mt_run (3),
.BR mt_run_named (3),
.BR mt_run_param (3),
.BR mt_run_param_named (3),
.BR mt_fok (3),
.BR mt_ferr (3),
.BR mt_return (3),
.BR mtest_overview (7)