Skip to content

Commit de0130a

Browse files
committed
assert_fails is more consistent than assert_fail
Fix #35 assert_fails is more consistent than assret_fail. Keeping an assert_fail function to avoid compatibility issue.
1 parent 53733c7 commit de0130a

File tree

5 files changed

+30
-25
lines changed

5 files changed

+30
-25
lines changed

README.adoc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ To run tests, simply call *bash_unit* with all your tests files as parameter. Fo
7676
Running tests in tests/test_core.sh
7777
Running test_assert_equals_fails_when_not_equal... SUCCESS
7878
Running test_assert_equals_succeed_when_equal... SUCCESS
79-
Running test_assert_fail_fails... SUCCESS
80-
Running test_assert_fail_succeeds... SUCCESS
8179
Running test_assert_fails... SUCCESS
80+
Running test_assert_fails_fails... SUCCESS
81+
Running test_assert_fails_succeeds... SUCCESS
8282
Running test_assert_not_equals_fails_when_equal... SUCCESS
8383
Running test_assert_not_equals_succeeds_when_not_equal... SUCCESS
8484
Running test_assert_shows_stderr_on_failure... SUCCESS
@@ -108,9 +108,9 @@ functions against this pattern.
108108
Running tests in tests/test_core.sh
109109
Running test_assert_equals_fails_when_not_equal... SUCCESS
110110
Running test_assert_equals_succeed_when_equal... SUCCESS
111-
Running test_assert_fail_fails... SUCCESS
112-
Running test_assert_fail_succeeds... SUCCESS
113111
Running test_assert_fails... SUCCESS
112+
Running test_assert_fails_fails... SUCCESS
113+
Running test_assert_fails_succeeds... SUCCESS
114114
Running test_assert_not_equals_fails_when_equal... SUCCESS
115115
Running test_assert_not_equals_succeeds_when_not_equal... SUCCESS
116116
Running test_assert_shows_stderr_on_failure... SUCCESS
@@ -132,9 +132,9 @@ output with the _-f_ option.
132132
# Running tests in tests/test_core.sh
133133
ok - test_assert_equals_fails_when_not_equal
134134
ok - test_assert_equals_succeed_when_equal
135-
ok - test_assert_fail_fails
136-
ok - test_assert_fail_succeeds
137135
ok - test_assert_fails
136+
ok - test_assert_fails_fails
137+
ok - test_assert_fails_succeeds
138138
ok - test_assert_not_equals_fails_when_equal
139139
ok - test_assert_not_equals_succeeds_when_not_equal
140140
ok - test_assert_shows_stderr_on_failure
@@ -287,13 +287,13 @@ code() {
287287
test_code_does_not_write_cool_in_the_file() {
288288
code
289289

290-
assert_fail "grep cool /tmp/the_file" "should not write 'cool' in /tmp/the_file"
290+
assert_fails "grep cool /tmp/the_file" "should not write 'cool' in /tmp/the_file"
291291
}
292292

293293
test_code_does_not_write_this_in_the_file() {
294294
code
295295

296-
assert_fail "grep this /tmp/the_file" "should not write 'this' in /tmp/the_file"
296+
assert_fails "grep this /tmp/the_file" "should not write 'this' in /tmp/the_file"
297297
}
298298
```
299299

@@ -444,7 +444,7 @@ test_code_fails_if_apache_does_not_run() {
444444
24162 pts/7 00:00:00 ps
445445
EOF
446446

447-
assert_fail code "code should fail when apache is not running"
447+
assert_fails code "code should fail when apache is not running"
448448
}
449449

450450
```

bash_unit

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ assert() {
4848
"\"$message\""
4949
}
5050

51-
assert_fail() {
51+
assert_fails() {
5252
local assertion=$1
5353
local message=$2
5454

@@ -58,6 +58,11 @@ assert_fail() {
5858
"\"$message\""
5959
}
6060

61+
assert_fail() {
62+
#deprecated, use assert_fails instead
63+
assert_fails "$@"
64+
}
65+
6166
assert_status_code() {
6267
local expected_status=$1
6368
local assertion="$2"

tests/test_cli.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ EOF
1616
}
1717

1818
test_exit_code_not_0_in_case_of_failure() {
19-
assert_fail "$BASH_UNIT <(cat << EOF
19+
assert_fails "$BASH_UNIT <(cat << EOF
2020
function test_succeed() { assert true ; }
2121
function test_fails() { assert false ; }
2222
EOF
@@ -75,7 +75,7 @@ Running todo_should_not_run... PENDING" \
7575
}
7676

7777
test_fails_when_test_file_does_not_exist() {
78-
assert_fail "$BASH_UNIT /not_exist/not_exist"
78+
assert_fails "$BASH_UNIT /not_exist/not_exist"
7979
}
8080

8181
test_display_usage_when_test_file_does_not_exist() {

tests/test_core.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,28 @@ test_fail_fails() {
1111

1212
#fail can now be used in the following tests
1313

14-
test_assert_fail_succeeds() {
15-
(assert_fail false) || fail 'assert_fail should succeed'
14+
test_assert_fails_succeeds() {
15+
(assert_fails false) || fail 'assert_fails should succeed'
1616
}
1717

18-
test_assert_fail_fails() {
19-
with_bash_unit_muted assert_fail true && fail 'assert_fail should fail' || true
18+
test_assert_fails_fails() {
19+
with_bash_unit_muted assert_fails true && fail 'assert_fails should fail' || true
2020
}
2121

22-
#assert_fail can now be used in the following tests
22+
#assert_fails can now be used in the following tests
2323

2424
test_assert_succeeds() {
2525
assert true || fail 'assert should succeed'
2626
}
2727

2828
test_assert_fails() {
29-
assert_fail "with_bash_unit_muted assert false" "assert should fail"
29+
assert_fails "with_bash_unit_muted assert false" "assert should fail"
3030
}
3131

3232
#assert can now be used in the following tests
3333

3434
test_assert_equals_fails_when_not_equal() {
35-
assert_fail \
35+
assert_fails \
3636
"with_bash_unit_muted assert_equals toto tutu" \
3737
"assert_equals should fail"
3838
}
@@ -46,7 +46,7 @@ test_assert_equals_succeed_when_equal() {
4646
#assert_equals can now be used in the following tests
4747

4848
test_assert_not_equals_fails_when_equal() {
49-
assert_fail \
49+
assert_fails \
5050
"with_bash_unit_muted assert_not_equals toto toto" \
5151
"assert_not_equals should fail"
5252
}
@@ -75,7 +75,7 @@ test_assert_status_code_succeeds() {
7575
}
7676

7777
test_assert_status_code_fails() {
78-
assert_fail "with_bash_unit_muted assert_status_code 3 true" \
78+
assert_fails "with_bash_unit_muted assert_status_code 3 true" \
7979
"assert_status_code should fail"
8080
}
8181

tests/test_tap_format

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test_bash_unit_accepts_tap_format_option() {
55
}
66

77
test_bash_unit_rejects_invalid_format() {
8-
assert_fail "$BASH_UNIT -f invalid_format"
8+
assert_fails "$BASH_UNIT -f invalid_format"
99
}
1010

1111
test_tap_format_for_one_succesfull_test() {
@@ -62,7 +62,7 @@ not ok - test_not_ok
6262
" \
6363
"$(bash_unit_out_for_code <<EOF
6464
test_not_ok() {
65-
assert_fail "echo message on stdout ; echo message on stderr >&2"
65+
assert_fails "echo message on stdout ; echo message on stderr >&2"
6666
}
6767
EOF
6868
)"
@@ -78,7 +78,7 @@ not ok - test_not_ok
7878
" \
7979
"$(bash_unit_out_for_code <<EOF
8080
test_not_ok() {
81-
assert_fail true "obvious failure"
81+
assert_fails true "obvious failure"
8282
}
8383
EOF
8484
)"
@@ -95,7 +95,7 @@ not ok - test_not_ok
9595
" \
9696
"$(bash_unit_out_for_code <<EOF
9797
test_not_ok() {
98-
assert_fail true "obvious failure\non multiple lines"
98+
assert_fails true "obvious failure\non multiple lines"
9999
}
100100
EOF
101101
)"

0 commit comments

Comments
 (0)