Skip to content

Commit 055954b

Browse files
Pascal Grangewolframroesler
authored andcommitted
Display overall result in text mode
See https://github.com/pgrange/bash_unit/pull/71/files We add a notify_suites_succeded and notify_suites_failed so that this events may be displayed by any formatter. We use SUCCESS and FAILURE instead of PASS and FAIL just to stick with the lingo used in the rest of bash_unit.
1 parent 4730cb8 commit 055954b

File tree

5 files changed

+44
-37
lines changed

5 files changed

+44
-37
lines changed

README.adoc

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +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
105+
Overall result: SUCCESS
106106
```
107107

108108
You might also want to run only specific tests, you may do so with the
@@ -128,18 +128,7 @@ Running tests in tests/test_core.sh
128128
Running test_assert_status_code_succeeds ... SUCCESS
129129
Running test_assert_succeeds ... SUCCESS
130130
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
131+
Overall result: SUCCESS
143132
```
144133

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

bash_unit

Lines changed: 19 additions & 16 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,12 +351,17 @@ 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=""
351-
overall=1
352365
randomise=0
353366
while getopts "vp:f:or" option
354367
do
@@ -360,9 +373,6 @@ do
360373
f)
361374
output_format="${OPTARG}"
362375
;;
363-
o)
364-
overall=0
365-
;;
366376
r)
367377
randomise=1
368378
;;
@@ -389,7 +399,6 @@ case "$output_format" in
389399
;;
390400
tap)
391401
tap_format
392-
overall=0
393402
;;
394403
*)
395404
usage "unsupported output format: $output_format"
@@ -417,17 +426,11 @@ do
417426
failure=$(( $? || failure))
418427
done
419428

420-
# Show the overall result
421-
if ((overall))
429+
if ((failure))
422430
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+
notify_suites_failed
432+
else
433+
notify_suites_succeded
431434
fi
432435

433436
exit $failure

tests/test_cli.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Running tests in code
77
Running test_fails ... FAILURE
88
code:2:test_fails()
99
Running test_succeed ... SUCCESS
10-
Overall resultcode: FAIL\
10+
Overall resultcode: FAILURE\
1111
" \
1212
"$(bash_unit_out_for_code << EOF
1313
function test_succeed() { assert true ; }
@@ -44,7 +44,7 @@ Running tests in test_file
4444
Running test_one ... SUCCESS
4545
Running tests in test_file
4646
Running test_two ... SUCCESS
47-
Overall result: PASS\
47+
Overall result: SUCCESS\
4848
" \
4949
"$bash_unit_output"
5050
}
@@ -60,7 +60,7 @@ test_run_only_tests_that_match_pattern() {
6060
Running tests in test_file
6161
Running test_one ... SUCCESS
6262
Running tests in test_file
63-
Overall result: PASS" "$bash_unit_output"
63+
Overall result: SUCCESS" "$bash_unit_output"
6464
}
6565

6666
test_do_not_run_pending_tests() {
@@ -81,7 +81,7 @@ test_pending_tests_appear_in_output() {
8181
Running tests in test_file
8282
Running pending_should_not_run ... PENDING
8383
Running todo_should_not_run ... PENDING
84-
Overall result: PASS" \
84+
Overall result: SUCCESS" \
8585
"$bash_unit_output"
8686
}
8787

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: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LANG=C.UTF-8
66

77
export FORCE_COLOR=false
88
export STICK_TO_CWD=true
9-
BASH_UNIT="eval ./bash_unit -o"
9+
BASH_UNIT="eval ./bash_unit"
1010
#BASH_UNIT="eval FORCE_COLOR=false ./bash_unit"
1111

1212
prepare_tests() {
@@ -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)