Skip to content

Commit 7805815

Browse files
committed
Split test_bash_unit
The core assertion tests are in test_core. The command line interface tests are in test_cli.
1 parent a9764ec commit 7805815

File tree

2 files changed

+91
-87
lines changed

2 files changed

+91
-87
lines changed

tests/test_cli.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
3+
test_run_all_tests_even_in_case_of_failure() {
4+
bash_unit_output=$($BASH_UNIT <(cat << EOF
5+
function test_succeed() { assert true ; }
6+
function test_fails() { assert false ; }
7+
EOF
8+
) | sed -e 's:/dev/fd/[0-9]*:test_file:')
9+
10+
assert_equals "\
11+
Running tests in test_file
12+
Running test_fails... FAILURE
13+
test_file:2:test_fails()
14+
Running test_succeed... SUCCESS" "$bash_unit_output"
15+
}
16+
17+
test_exit_code_not_0_in_case_of_failure() {
18+
assert_fail "$BASH_UNIT <(cat << EOF
19+
function test_succeed() { assert true ; }
20+
function test_fails() { assert false ; }
21+
EOF
22+
)"
23+
}
24+
25+
test_run_all_file_parameters() {
26+
bash_unit_output=$($BASH_UNIT \
27+
<(echo "test_one() { echo -n ; }") \
28+
<(echo "test_two() { echo -n ; }") \
29+
| sed -e 's:/dev/fd/[0-9]*:test_file:' \
30+
)
31+
32+
assert_equals "\
33+
Running tests in test_file
34+
Running test_one... SUCCESS
35+
Running tests in test_file
36+
Running test_two... SUCCESS" "$bash_unit_output"
37+
}
38+
39+
test_run_only_tests_that_match_pattern() {
40+
bash_unit_output=$($BASH_UNIT -p one \
41+
<(echo "test_one() { echo -n ; }") \
42+
<(echo "test_two() { echo -n ; }") \
43+
| sed -e 's:/dev/fd/[0-9]*:test_file:' \
44+
)
45+
46+
assert_equals "\
47+
Running tests in test_file
48+
Running test_one... SUCCESS
49+
Running tests in test_file" "$bash_unit_output"
50+
}
51+
52+
test_fails_when_test_file_does_not_exist() {
53+
assert_fail "$BASH_UNIT /not_exist/not_exist"
54+
}
55+
56+
test_display_usage_when_test_file_does_not_exist() {
57+
bash_unit_output=$($BASH_UNIT /not_exist/not_exist 2>&1 >/dev/null | line 1)
58+
59+
assert_equals "file does not exist: /not_exist/not_exist"\
60+
"$bash_unit_output"
61+
}
62+
63+
test_bash_unit_succeed_when_no_failure_even_if_no_teardown() {
64+
#FIX https://github.com/pgrange/bash_unit/issues/8
65+
assert "$BASH_UNIT <(echo 'test_success() { echo -n ; }')"
66+
}
67+
68+
test_bash_unit_runs_teardown_even_in_case_of_failure() {
69+
#FIX https://github.com/pgrange/bash_unit/issues/10
70+
assert_equals "ran teardown" \
71+
"$($BASH_UNIT <(echo 'test_fail() { fail ; } ; teardown() { echo "ran teardown" >&2 ; }') 2>&1 >/dev/null)"
72+
}
73+
74+
test_one_test_should_stop_after_first_assertion_failure() {
75+
#FIX https://github.com/pgrange/bash_unit/issues/10
76+
assert_equals "before failure" \
77+
"$($BASH_UNIT <(echo 'test_fail() { echo "before failure" >&2 ; fail ; echo "after failure" >&2 ; }') 2>&1 >/dev/null)"
78+
}
79+
80+
test_one_test_should_stop_when_assert_fails() {
81+
#FIX https://github.com/pgrange/bash_unit/issues/26
82+
assert_equals "before failure" \
83+
"$($BASH_UNIT <(echo 'test_fail() { echo "before failure" >&2 ; assert false ; echo "after failure" >&2 ; }') 2>&1 >/dev/null)"
84+
}
85+
86+
line() {
87+
line_nb=$1
88+
tail -n +$line_nb | head -1
89+
}
90+
91+
BASH_UNIT="eval FORCE_COLOR=false ../bash_unit"

tests/test_bash_unit.sh renamed to tests/test_core.sh

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -138,91 +138,6 @@ EOF
138138
assert_equals 2 $(ps | grep pts | wc -l)
139139
}
140140

141-
test_run_all_tests_even_in_case_of_failure() {
142-
bash_unit_output=$($BASH_UNIT <(cat << EOF
143-
function test_succeed() { assert true ; }
144-
function test_fails() { assert false ; }
145-
EOF
146-
) | sed -e 's:/dev/fd/[0-9]*:test_file:')
147-
148-
assert_equals "\
149-
Running tests in test_file
150-
Running test_fails... FAILURE
151-
test_file:2:test_fails()
152-
Running test_succeed... SUCCESS" "$bash_unit_output"
153-
}
154-
155-
test_exit_code_not_0_in_case_of_failure() {
156-
assert_fail "$BASH_UNIT <(cat << EOF
157-
function test_succeed() { assert true ; }
158-
function test_fails() { assert false ; }
159-
EOF
160-
)"
161-
}
162-
163-
test_run_all_file_parameters() {
164-
bash_unit_output=$($BASH_UNIT \
165-
<(echo "test_one() { echo -n ; }") \
166-
<(echo "test_two() { echo -n ; }") \
167-
| sed -e 's:/dev/fd/[0-9]*:test_file:' \
168-
)
169-
170-
assert_equals "\
171-
Running tests in test_file
172-
Running test_one... SUCCESS
173-
Running tests in test_file
174-
Running test_two... SUCCESS" "$bash_unit_output"
175-
}
176-
177-
test_run_only_tests_that_match_pattern() {
178-
bash_unit_output=$($BASH_UNIT -p one \
179-
<(echo "test_one() { echo -n ; }") \
180-
<(echo "test_two() { echo -n ; }") \
181-
| sed -e 's:/dev/fd/[0-9]*:test_file:' \
182-
)
183-
184-
assert_equals "\
185-
Running tests in test_file
186-
Running test_one... SUCCESS
187-
Running tests in test_file" "$bash_unit_output"
188-
}
189-
190-
test_fails_when_test_file_does_not_exist() {
191-
assert_fail "$BASH_UNIT /not_exist/not_exist"
192-
}
193-
194-
test_display_usage_when_test_file_does_not_exist() {
195-
bash_unit_output=$($BASH_UNIT /not_exist/not_exist 2>&1 >/dev/null | line 1)
196-
197-
assert_equals "file does not exist: /not_exist/not_exist"\
198-
"$bash_unit_output"
199-
}
200-
201-
test_bash_unit_succeed_when_no_failure_even_if_no_teardown() {
202-
#FIX https://github.com/pgrange/bash_unit/issues/8
203-
assert "$BASH_UNIT <(echo 'test_success() { echo -n ; }')"
204-
}
205-
206-
test_bash_unit_runs_teardown_even_in_case_of_failure() {
207-
#FIX https://github.com/pgrange/bash_unit/issues/10
208-
assert_equals "ran teardown" \
209-
"$($BASH_UNIT <(echo 'test_fail() { fail ; } ; teardown() { echo "ran teardown" >&2 ; }') 2>&1 >/dev/null)"
210-
}
211-
212-
test_one_test_should_stop_after_first_assertion_failure() {
213-
#FIX https://github.com/pgrange/bash_unit/issues/10
214-
assert_equals "before failure" \
215-
"$($BASH_UNIT <(echo 'test_fail() { echo "before failure" >&2 ; fail ; echo "after failure" >&2 ; }') 2>&1 >/dev/null)"
216-
217-
}
218-
219-
test_one_test_should_stop_when_assert_fails() {
220-
#FIX https://github.com/pgrange/bash_unit/issues/26
221-
assert_equals "before failure" \
222-
"$($BASH_UNIT <(echo 'test_fail() { echo "before failure" >&2 ; assert false ; echo "after failure" >&2 ; }') 2>&1 >/dev/null)"
223-
224-
}
225-
226141
test_bash_unit_changes_cwd_to_current_test_file_directory() {
227142
assert "ls ../tests/$(basename "$BASH_SOURCE")" \
228143
"bash_unit should change current working directory to match the directory of the currenlty running test"
@@ -312,5 +227,3 @@ mute() {
312227
notify_stdout () { echo -n ; }
313228
notify_stderr () { echo -n ; }
314229
}
315-
316-
BASH_UNIT="eval FORCE_COLOR=false ../bash_unit"

0 commit comments

Comments
 (0)