Skip to content

Commit 4751861

Browse files
author
Wolfram Rösler
committed
Output "Overall result" line at the end
Example: ``` $ ./bash_unit tests/test_tap_format Running tests in tests/test_tap_format /home/wolfram/src/bash_unit/tests Running test_assertion_message_is_tap_formatted ... SUCCESS ✓ Running test_bash_unit_accepts_tap_format_option ... SUCCESS ✓ Running test_bash_unit_rejects_invalid_format ... SUCCESS ✓ Running test_multi_lines_assertion_message_is_tap_formatted ... SUCCESS ✓ Running test_tap_format_for_failing_test_with_stdout_stderr_outputs ... SUCCESS ✓ Running test_tap_format_for_one_failing_test ... SUCCESS ✓ Running test_tap_format_for_one_pending_test ... SUCCESS ✓ Running test_tap_format_for_one_succesfull_test ... SUCCESS ✓ Overall result: PASS ✓ ``` So when you've got a lot of tests (more than a screenful) you don't have to scroll up or check $? to tell if any test has failed.
1 parent dd4b40f commit 4751861

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

README.adoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Running tests in tests/test_core.sh
102102
Running test_fake_echo_stdin_when_no_params ... SUCCESS
103103
Running test_fake_exports_faked_in_subshells ... SUCCESS
104104
Running test_fake_transmits_params_to_fake_code ... SUCCESS
105+
Overall result: PASS
105106
```
106107

107108
You might also want to run only specific tests, you may do so with the
@@ -127,6 +128,18 @@ Running tests in tests/test_core.sh
127128
Running test_assert_status_code_succeeds ... SUCCESS
128129
Running test_assert_succeeds ... SUCCESS
129130
Running test_fail_fails ... SUCCESS
131+
Overall result: PASS
132+
```
133+
134+
The "Overall result:" line at the end can be suppressed with the _-o_ option:
135+
136+
```test
137+
./bash_unit -o -p test_assert_succeeds tests/test_core.sh
138+
```
139+
140+
```output
141+
Running tests in tests/test_core.sh
142+
Running test_assert_succeeds ... SUCCESS
130143
```
131144

132145
*bash_unit* supports the http://testanything.org/[Test Anything Protocol] so you can ask for a tap formatted

bash_unit

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,9 @@ tap_format() {
348348
output_format=text
349349
test_pattern=""
350350
separator=""
351+
overall=1
351352
randomise=0
352-
while getopts "vp:f:r" option
353+
while getopts "vp:f:or" option
353354
do
354355
case "$option" in
355356
p)
@@ -359,6 +360,9 @@ do
359360
f)
360361
output_format="${OPTARG}"
361362
;;
363+
o)
364+
overall=0
365+
;;
362366
r)
363367
randomise=1
364368
;;
@@ -385,6 +389,7 @@ case "$output_format" in
385389
;;
386390
tap)
387391
tap_format
392+
overall=0
388393
;;
389394
*)
390395
usage "unsupported output format: $output_format"
@@ -411,4 +416,18 @@ do
411416
)
412417
failure=$(( $? || failure))
413418
done
419+
420+
# Show the overall result
421+
if ((overall))
422+
then
423+
echo -n "Overall result: "
424+
if ((failure))
425+
then
426+
echo -n "FAIL" | pretty_failure
427+
else
428+
echo -n "PASS" | pretty_success
429+
fi
430+
echo
431+
fi
432+
414433
exit $failure

tests/test_cli.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ test_run_all_tests_even_in_case_of_failure() {
66
Running tests in code
77
Running test_fails ... FAILURE
88
code:2:test_fails()
9-
Running test_succeed ... SUCCESS\
9+
Running test_succeed ... SUCCESS
10+
Overall resultcode: FAIL\
1011
" \
1112
"$(bash_unit_out_for_code << EOF
1213
function test_succeed() { assert true ; }
@@ -42,7 +43,8 @@ test_run_all_file_parameters() {
4243
Running tests in test_file
4344
Running test_one ... SUCCESS
4445
Running tests in test_file
45-
Running test_two ... SUCCESS\
46+
Running test_two ... SUCCESS
47+
Overall result: PASS\
4648
" \
4749
"$bash_unit_output"
4850
}
@@ -57,7 +59,8 @@ test_run_only_tests_that_match_pattern() {
5759
assert_equals "\
5860
Running tests in test_file
5961
Running test_one ... SUCCESS
60-
Running tests in test_file" "$bash_unit_output"
62+
Running tests in test_file
63+
Overall result: PASS" "$bash_unit_output"
6164
}
6265

6366
test_do_not_run_pending_tests() {
@@ -77,7 +80,8 @@ test_pending_tests_appear_in_output() {
7780
assert_equals "\
7881
Running tests in test_file
7982
Running pending_should_not_run ... PENDING
80-
Running todo_should_not_run ... PENDING" \
83+
Running todo_should_not_run ... PENDING
84+
Overall result: PASS" \
8185
"$bash_unit_output"
8286
}
8387

0 commit comments

Comments
 (0)