1
1
'\" t
2
2
.\" Title: bash_unit
3
3
.\" Author: [see the "AUTHOR(S)" section]
4
- .\" Generator: Asciidoctor 2.0.18
5
- .\" Date: 2023-03-03
4
+ .\" Generator: Asciidoctor 2.0.21
5
+ .\" Date: 2024-02-22
6
6
.\" Manual: \ \&
7
7
.\" Source: \ \&
8
8
.\" Language: English
9
9
.\"
10
- .TH "BASH_UNIT" "1" "2023-03-03 " "\ \& " "\ \& "
10
+ .TH "BASH_UNIT" "1" "2024-02-22 " "\ \& " "\ \& "
11
11
.ie \n( .g .ds Aq \(aq
12
12
.el .ds Aq '
13
13
.ss \n[ .ss ] 0
31
31
bash_unit \- bash unit testing enterprise edition framework for professionals!
32
32
.SH "SYNOPSIS"
33
33
.sp
34
- \fB bash_unit \fP [\- f tap] [\- p <pattern>] [\- r] [test_file]
34
+ \fB bash_unit \fP [\- f tap] [\- p <pattern>] [\- s <pattern>] [ \- r] [test_file]
35
35
.SH "DESCRIPTION"
36
36
.sp
37
37
\fB bash_unit \fP allows you to write unit tests (functions starting with \fB test \fP ),
@@ -55,6 +55,15 @@ You can specify several patterns by repeating this option
55
55
for each pattern.
56
56
.RE
57
57
.sp
58
+ \fB \- s \fP \fI pattern \fP
59
+ .RS 4
60
+ skip tests which name matches the given pattern.
61
+ You can specify several patterns by repeating this option
62
+ for each pattern.
63
+ Tests will appear in \fB bash_unit \fP output as \fI skipped \fP .
64
+ (see also \fI skip_if \fP )
65
+ .RE
66
+ .sp
58
67
\fB \- r \fP
59
68
.RS 4
60
69
executes test cases in random order.
@@ -68,6 +77,58 @@ command line).
68
77
specify an alternative output format.
69
78
The only supported value is \fB tap \fP .
70
79
.RE
80
+ .SS "\c .URL "https://pre\- commit.com" "pre\- commit" hook"
81
+ .sp
82
+ You can run \f(CR bash_unit \fP as a \c
83
+ .URL " https://pre\- commit.com" " pre\- commit" ""
84
+ hook.
85
+ .sp
86
+ Add the following to your \c
87
+ .URL " https://pre\- commit.com" " pre\- commit" ""
88
+ configuration. By default it will run scripts that are identified as shell scripts that match the path \f(CR ^tests/(.*/)?test_.* \(rs .sh$ \fP .
89
+ .sp
90
+ .if n .RS 4
91
+ .nf
92
+ .fam C
93
+ repos:
94
+ \- repo: https://github.com/pgrange/bash_unit
95
+ rev: v1.7.0
96
+ hooks:
97
+ \- id: bash\- unit
98
+ .fam
99
+ .fi
100
+ .if n .RE
101
+ .SH "RUNNING \f(CR bash_unit \fP IN THE TEST SCRIPT"
102
+ .sp
103
+ In some cases you want to run \f(CR bash_unit \fP from inside the test script.
104
+ .sp
105
+ One example is this project’s \f(CR test_doc.sh \fP test script.
106
+ .sp
107
+ One method to define a \f(CR BASH_UNIT \fP variable is shown below:
108
+ .sp
109
+ .if n .RS 4
110
+ .nf
111
+ .fam C
112
+ # Function to recursively search upwards for file
113
+ _find_file() {
114
+ local dir="$1"
115
+ local file="$2"
116
+ while [ "${dir}" != "/" ]; do
117
+ if [ \- f "${dir}/${file}" ]; then
118
+ echo "${dir}/${file}"
119
+ return 0
120
+ fi
121
+ dir=$(dirname "${dir}")
122
+ done
123
+ return 1
124
+ }
125
+
126
+ B_U=$(_find_file "$(dirname "$(realpath "$0")")" bash_unit)
127
+ # shellcheck disable=2089
128
+ BASH_UNIT="eval FORCE_COLOR=false \(rs "$B_U\(rs ""
129
+ .fam
130
+ .fi
131
+ .if n .RE
71
132
.SH "HOW TO RUN TESTS"
72
133
.sp
73
134
To run tests, simply call \fB bash_unit \fP with all your tests files as parameter. For instance to run some \fB bash_unit \fP tests, from \fB bash_unit \fP directory:
@@ -161,6 +222,47 @@ Overall result: SUCCESS
161
222
.fi
162
223
.if n .RE
163
224
.sp
225
+ You can combine the \fI \- p \fP option with \fI \- s \fP to skip some of the tests. This option accepts a pattern
226
+ as parameter and mark as skipped any test function which matches this pattern.
227
+ .sp
228
+ .if n .RS 4
229
+ .nf
230
+ .fam C
231
+ \& ./bash_unit \- p fail_fails \- p assert \- s no \- s status tests/test_core.sh
232
+ .fam
233
+ .fi
234
+ .if n .RE
235
+ .sp
236
+ .if n .RS 4
237
+ .nf
238
+ .fam C
239
+ Running tests in tests/test_core.sh
240
+ Running test_assert_equals_fails_when_not_equal ... SKIPPED
241
+ Running test_assert_matches_fails_when_not_matching ... SKIPPED
242
+ Running test_assert_no_diff_fails_when_diff ... SKIPPED
243
+ Running test_assert_no_diff_succeeds_when_no_diff ... SKIPPED
244
+ Running test_assert_not_equals_fails_when_equal ... SKIPPED
245
+ Running test_assert_not_equals_succeeds_when_not_equal ... SKIPPED
246
+ Running test_assert_not_matches_fails_when_matching ... SKIPPED
247
+ Running test_assert_not_matches_succeed_when_not_matching ... SKIPPED
248
+ Running test_assert_status_code_fails ... SKIPPED
249
+ Running test_assert_status_code_succeeds ... SKIPPED
250
+ Running test_assert_equals_succeed_when_equal ... SUCCESS
251
+ Running test_assert_fails ... SUCCESS
252
+ Running test_assert_fails_fails ... SUCCESS
253
+ Running test_assert_fails_succeeds ... SUCCESS
254
+ Running test_assert_matches_succeed_when_matching ... SUCCESS
255
+ Running test_assert_shows_stderr_on_failure ... SUCCESS
256
+ Running test_assert_shows_stdout_on_failure ... SUCCESS
257
+ Running test_assert_succeeds ... SUCCESS
258
+ Running test_assert_within_delta_fails ... SUCCESS
259
+ Running test_assert_within_delta_succeeds ... SUCCESS
260
+ Running test_fail_fails ... SUCCESS
261
+ Overall result: SUCCESS
262
+ .fam
263
+ .fi
264
+ .if n .RE
265
+ .sp
164
266
\fB bash_unit \fP supports the \c
165
267
.URL " http://testanything.org/" " Test Anything Protocol" ""
166
268
so you can ask for a tap formatted
@@ -690,6 +792,46 @@ doc:2:test_obvious_notmatching_with_assert_no_diff()
690
792
.fam
691
793
.fi
692
794
.if n .RE
795
+ .SH "\fB SKIP_IF \fP FUNCTION"
796
+ .sp
797
+ .if n .RS 4
798
+ .nf
799
+ .fam C
800
+ skip_if <condition> <pattern>
801
+ .fam
802
+ .fi
803
+ .if n .RE
804
+ .sp
805
+ If \fI condition \fP is true, will skip all the tests in the current file which match the given \fI pattern \fP .
806
+ .sp
807
+ This can be useful when one has tests that are dependent on system environment, for instance:
808
+ .sp
809
+ .if n .RS 4
810
+ .nf
811
+ .fam C
812
+ skip_if "uname | grep Darwin" linux
813
+ skip_if "uname | grep Linux" darwin
814
+
815
+ test_linux_proc_exists() {
816
+ assert "ls /proc/" "there should exist /proc on Linux"
817
+ }
818
+ test_darwin_proc_does_not_exist() {
819
+ assert_fail "ls /proc/" "there should not exist /proc on Darwin"
820
+ }
821
+ .fam
822
+ .fi
823
+ .if n .RE
824
+ .sp
825
+ will output, on a Linux system:
826
+ .sp
827
+ .if n .RS 4
828
+ .nf
829
+ .fam C
830
+ Running test_darwin_proc_does_not_exist ... SKIPPED
831
+ Running test_linux_proc_exists ... SUCCESS
832
+ .fam
833
+ .fi
834
+ .if n .RE
693
835
.SH "\fB FAKE \fP FUNCTION"
694
836
.sp
695
837
.if n .RS 4
@@ -1094,4 +1236,4 @@ test_get_data_from_fake() {
1094
1236
doc:13:test_get_data_from_fake()
1095
1237
.fam
1096
1238
.fi
1097
- .if n .RE
1239
+ .if n .RE
0 commit comments