Skip to content

Commit a31880a

Browse files
committed
Add setup_suite and teardown_suite for file level setup/teardown
1 parent 184c6bb commit a31880a

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

bash_unit

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#
1717
# https://github.com/pgrange/bash_unit
1818

19-
VERSION=v1.5.0
19+
VERSION=v1.6.0
2020

2121
ESCAPE=$(printf "\033")
2222
NOCOLOR="${ESCAPE}[0m"

docs/man/man1/bash_unit.1

+18-12
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
.\" Title: bash_unit
33
.\" Author: [see the "AUTHORS" section]
44
.\" Generator: Asciidoctor 1.5.5
5-
.\" Date: 2017-07-07
5+
.\" Date: 2017-09-01
66
.\" Manual: \ \&
77
.\" Source: \ \&
88
.\" Language: English
99
.\"
10-
.TH "BASH_UNIT" "1" "2017-07-07" "\ \&" "\ \&"
10+
.TH "BASH_UNIT" "1" "2017-09-01" "\ \&" "\ \&"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0
@@ -72,9 +72,9 @@ To run tests, simply call \fBbash_unit\fP with all your tests files as parameter
7272
Running tests in tests/test_core.sh
7373
Running test_assert_equals_fails_when_not_equal... SUCCESS
7474
Running test_assert_equals_succeed_when_equal... SUCCESS
75-
Running test_assert_fail_fails... SUCCESS
76-
Running test_assert_fail_succeeds... SUCCESS
7775
Running test_assert_fails... SUCCESS
76+
Running test_assert_fails_fails... SUCCESS
77+
Running test_assert_fails_succeeds... SUCCESS
7878
Running test_assert_not_equals_fails_when_equal... SUCCESS
7979
Running test_assert_not_equals_succeeds_when_not_equal... SUCCESS
8080
Running test_assert_shows_stderr_on_failure... SUCCESS
@@ -116,9 +116,9 @@ functions against this pattern.
116116
Running tests in tests/test_core.sh
117117
Running test_assert_equals_fails_when_not_equal... SUCCESS
118118
Running test_assert_equals_succeed_when_equal... SUCCESS
119-
Running test_assert_fail_fails... SUCCESS
120-
Running test_assert_fail_succeeds... SUCCESS
121119
Running test_assert_fails... SUCCESS
120+
Running test_assert_fails_fails... SUCCESS
121+
Running test_assert_fails_succeeds... SUCCESS
122122
Running test_assert_not_equals_fails_when_equal... SUCCESS
123123
Running test_assert_not_equals_succeeds_when_not_equal... SUCCESS
124124
Running test_assert_shows_stderr_on_failure... SUCCESS
@@ -154,9 +154,9 @@ output with the \fI\-f\fP option.
154154
# Running tests in tests/test_core.sh
155155
ok \- test_assert_equals_fails_when_not_equal
156156
ok \- test_assert_equals_succeed_when_equal
157-
ok \- test_assert_fail_fails
158-
ok \- test_assert_fail_succeeds
159157
ok \- test_assert_fails
158+
ok \- test_assert_fails_fails
159+
ok \- test_assert_fails_succeeds
160160
ok \- test_assert_not_equals_fails_when_equal
161161
ok \- test_assert_not_equals_succeeds_when_not_equal
162162
ok \- test_assert_shows_stderr_on_failure
@@ -186,7 +186,13 @@ You may write a \fBsetup\fP function that will be exectuted before each test is
186186
.sp
187187
You may write a \fBteardown\fP function that will be exectuted after each test is run.
188188
.sp
189-
If you need to set someting up only once for all tests, simply write your code outside any test function, this is a bash script.
189+
You may write a \fBsetup_suite\fP function that will be executed only once before all the tests of your test file.
190+
.sp
191+
You may write a \fBteardown_suite\fP function that will be executed only once after all the tests of your test file.
192+
.sp
193+
If you write code outside of any bash function, this code will be executed once at test file loading time since
194+
your file is a bash script and \fBbash_unit\fP sources it before running your tests. It is suggested to write a
195+
\fBsetup_suite\fP function and avoid any code outside a bash function.
190196
.sp
191197
If you want to keep an eye on a test not yet implemented, prefix the name of the function by \fBtodo\fP instead of test.
192198
Test to do are not executed and do not impact the global status of your test suite but are displayed in \fBbash_unit\fP output.
@@ -382,13 +388,13 @@ code() {
382388
test_code_does_not_write_cool_in_the_file() {
383389
code
384390

385-
assert_fail "grep cool /tmp/the_file" "should not write \(aqcool\(aq in /tmp/the_file"
391+
assert_fails "grep cool /tmp/the_file" "should not write \(aqcool\(aq in /tmp/the_file"
386392
}
387393

388394
test_code_does_not_write_this_in_the_file() {
389395
code
390396

391-
assert_fail "grep this /tmp/the_file" "should not write \(aqthis\(aq in /tmp/the_file"
397+
assert_fails "grep this /tmp/the_file" "should not write \(aqthis\(aq in /tmp/the_file"
392398
}
393399
.fi
394400
.if n \{\
@@ -630,7 +636,7 @@ test_code_fails_if_apache_does_not_run() {
630636
24162 pts/7 00:00:00 ps
631637
EOF
632638

633-
assert_fail code "code should fail when apache is not running"
639+
assert_fails code "code should fail when apache is not running"
634640
}
635641
.fi
636642
.if n \{\

0 commit comments

Comments
 (0)