Skip to content

Commit 61a4dd3

Browse files
authored
Merge pull request #71 from wolframroesler/overall_result
Output "Overall result" line at the end
2 parents e57dc71 + eb48633 commit 61a4dd3

File tree

5 files changed

+56
-13
lines changed

5 files changed

+56
-13
lines changed

README.adoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Running tests in tests/test_core.sh
108108
Running test_fake_echo_stdin_when_no_params ... SUCCESS
109109
Running test_fake_exports_faked_in_subshells ... SUCCESS
110110
Running test_fake_transmits_params_to_fake_code ... SUCCESS
111+
Overall result: SUCCESS
111112
```
112113

113114
You might also want to run only specific tests, you may do so with the
@@ -133,6 +134,7 @@ Running tests in tests/test_core.sh
133134
Running test_assert_status_code_succeeds ... SUCCESS
134135
Running test_assert_succeeds ... SUCCESS
135136
Running test_fail_fails ... SUCCESS
137+
Overall result: SUCCESS
136138
```
137139

138140
*bash_unit* supports the http://testanything.org/[Test Anything Protocol] so you can ask for a tap formatted
@@ -597,7 +599,7 @@ With bash, the result code of a pipeline equals the result code of the last comm
597599

598600
An alternative may be to activate bash _pipefail_ option but this may introduce unwanted side effects. We can also simply not output anything in __ps_ so that _grep_ fails:
599601

600-
```test
602+
```shell
601603
code() {
602604
ps a | grep apache
603605
}
@@ -619,7 +621,7 @@ bad, don't do that.
619621

620622
Moreover, *assert_equals* output is captured by _ps_ and this just messes with the display of our test results:
621623

622-
```output
624+
```shell
623625
Running test_code_gives_ps_appropriate_parameters ...
624626
```
625627

bash_unit

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,14 @@ text_format() {
306306
notify_stack() {
307307
color "$YELLOW"
308308
}
309+
notify_suites_succeded() {
310+
echo -n "Overall result: SUCCESS" | pretty_success
311+
echo
312+
}
313+
notify_suites_failed() {
314+
echo -n "Overall result: FAILURE" | pretty_failure
315+
echo
316+
}
309317
}
310318

311319
tap_format() {
@@ -314,7 +322,7 @@ tap_format() {
314322
echo "# Running tests in $test_file"
315323
}
316324
notify_test_starting() {
317-
echo -n
325+
:
318326
}
319327
notify_test_pending() {
320328
local test="$1"
@@ -343,13 +351,19 @@ tap_format() {
343351
notify_stack() {
344352
"$SED" 's:^:# :' | color "$YELLOW"
345353
}
354+
notify_suites_succeded() {
355+
:
356+
}
357+
notify_suites_failed() {
358+
:
359+
}
346360
}
347361

348362
output_format=text
349363
test_pattern=""
350364
separator=""
351365
randomise=0
352-
while getopts "vp:f:r" option
366+
while getopts "vp:f:or" option
353367
do
354368
case "$option" in
355369
p)
@@ -411,4 +425,12 @@ do
411425
)
412426
failure=$(( $? || failure))
413427
done
428+
429+
if ((failure))
430+
then
431+
notify_suites_failed
432+
else
433+
notify_suites_succeded
434+
fi
435+
414436
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: FAILURE\
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: SUCCESS\
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: SUCCESS" "$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: SUCCESS" \
8185
"$bash_unit_output"
8286
}
8387

tests/test_core.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,6 @@ mute() {
251251
notify_stack () { echo -n ; }
252252
notify_stdout () { echo -n ; }
253253
notify_stderr () { echo -n ; }
254+
notify_suites_succeded () { echo -n ; }
255+
notify_suites_failed () { echo -n ; }
254256
}

tests/test_doc.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ prepare_tests() {
2020

2121
while grep -E '^'"$TEST_PATTERN"'$' $remaining >/dev/null
2222
do
23-
block=$(($block+1))
23+
((++block))
2424
run_doc_test $remaining $swap |& sed '$a\' > $test_output$block
2525
doc_to_output $remaining $swap > $expected_output$block
26-
eval 'function test_block_'"$block"'() {
26+
eval 'function test_block_'"$(printf %02d $block)"'() {
2727
assert "diff -u '"$expected_output$block"' '"$test_output$block"'"
2828
}'
2929
done
@@ -32,12 +32,25 @@ prepare_tests() {
3232
function run_doc_test() {
3333
local remaining="$1"
3434
local swap="$2"
35-
$BASH_UNIT <(
36-
cat "$remaining" | _next_code "$swap"
37-
) | tail -n +2 | sed -e 's:/dev/fd/[0-9]*:doc:g'
35+
$BASH_UNIT <(cat "$remaining" | _next_code "$swap") \
36+
| clean_bash_unit_running_header \
37+
| clean_bash_pseudo_files_name \
38+
| clean_bash_unit_overall_result
3839
cat "$swap" > "$remaining"
3940
}
4041
42+
function clean_bash_unit_running_header() {
43+
tail -n +2
44+
}
45+
46+
function clean_bash_pseudo_files_name() {
47+
sed -e 's:/dev/fd/[0-9]*:doc:g'
48+
}
49+
50+
function clean_bash_unit_overall_result() {
51+
sed '$d'
52+
}
53+
4154
function doc_to_output() {
4255
local remaining="$1"
4356
local swap="$2"

0 commit comments

Comments
 (0)