File tree Expand file tree Collapse file tree 4 files changed +48
-1
lines changed
Expand file tree Collapse file tree 4 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,12 @@ assert_failure() {
6161
6262 (( $# > 0 )) && local -r expected=" $1 "
6363 if (( status == 0 )) ; then
64- batslib_print_kv_single_or_multi 6 ' output' " $output " \
64+ { local -ir width=6
65+ batslib_print_kv_single_or_multi " $width " ' output' " $output "
66+ if [[ -n " $stderr " ]]; then
67+ batslib_print_kv_single_or_multi " $width " ' stderr' " $stderr "
68+ fi
69+ } \
6570 | batslib_decorate ' command succeeded, but it was expected to fail' \
6671 | fail
6772 elif (( $# > 0 )) && (( status != expected )) ; then
@@ -71,6 +76,9 @@ assert_failure() {
7176 ' actual' " $status "
7277 batslib_print_kv_single_or_multi " $width " \
7378 ' output' " $output "
79+ if [[ -n " $stderr " ]]; then
80+ batslib_print_kv_single_or_multi " $width " ' stderr' " $stderr "
81+ fi
7482 } \
7583 | batslib_decorate ' command failed as expected, but status differs' \
7684 | fail
Original file line number Diff line number Diff line change @@ -37,6 +37,9 @@ assert_success() {
3737 { local -ir width=6
3838 batslib_print_kv_single " $width " ' status' " $status "
3939 batslib_print_kv_single_or_multi " $width " ' output' " $output "
40+ if [[ -n " $stderr " ]]; then
41+ batslib_print_kv_single_or_multi " $width " ' stderr' " $stderr "
42+ fi
4043 } \
4144 | batslib_decorate ' command failed' \
4245 | fail
Original file line number Diff line number Diff line change @@ -21,6 +21,24 @@ output : a
2121ERR_MSG
2222}
2323
24+ @test " assert_failure(): returns 1 and displays \`\$ stderr' if it is set" {
25+ run --separate-stderr \
26+ bash -c ' echo "a"
27+ echo "b" >&2
28+ exit 0'
29+ run assert_failure
30+
31+ echo " Stderr: $stderr " >&3
32+
33+ assert_test_fail << 'ERR_MSG '
34+
35+ -- command succeeded, but it was expected to fail --
36+ output : a
37+ stderr : b
38+ --
39+ ERR_MSG
40+ }
41+
2442@test " assert_failure(): displays \`\$ output' in multi-line format if it is longer then one line" {
2543 run bash -c ' printf "a 0\na 1"
2644 exit 0'
@@ -73,3 +91,4 @@ output (2 lines):
7391--
7492ERR_MSG
7593}
94+
Original file line number Diff line number Diff line change @@ -38,3 +38,20 @@ output (2 lines):
3838--
3939ERR_MSG
4040}
41+
42+ @test " assert_success(): displays \`\$ stderr' if it is set" {
43+ run --separate-stderr \
44+ bash -c ' echo "a"
45+ echo "b" >&2
46+ exit 1'
47+ run assert_success
48+
49+ assert_test_fail << 'ERR_MSG '
50+
51+ -- command failed --
52+ status : 1
53+ output : a
54+ stderr : b
55+ --
56+ ERR_MSG
57+ }
You can’t perform that action at this time.
0 commit comments