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() {
61
61
62
62
(( $# > 0 )) && local -r expected=" $1 "
63
63
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
+ } \
65
70
| batslib_decorate ' command succeeded, but it was expected to fail' \
66
71
| fail
67
72
elif (( $# > 0 )) && (( status != expected )) ; then
@@ -71,6 +76,9 @@ assert_failure() {
71
76
' actual' " $status "
72
77
batslib_print_kv_single_or_multi " $width " \
73
78
' output' " $output "
79
+ if [[ -n " $stderr " ]]; then
80
+ batslib_print_kv_single_or_multi " $width " ' stderr' " $stderr "
81
+ fi
74
82
} \
75
83
| batslib_decorate ' command failed as expected, but status differs' \
76
84
| fail
Original file line number Diff line number Diff line change @@ -37,6 +37,9 @@ assert_success() {
37
37
{ local -ir width=6
38
38
batslib_print_kv_single " $width " ' status' " $status "
39
39
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
40
43
} \
41
44
| batslib_decorate ' command failed' \
42
45
| fail
Original file line number Diff line number Diff line change @@ -21,6 +21,24 @@ output : a
21
21
ERR_MSG
22
22
}
23
23
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
+
24
42
@test " assert_failure(): displays \`\$ output' in multi-line format if it is longer then one line" {
25
43
run bash -c ' printf "a 0\na 1"
26
44
exit 0'
@@ -73,3 +91,4 @@ output (2 lines):
73
91
--
74
92
ERR_MSG
75
93
}
94
+
Original file line number Diff line number Diff line change @@ -38,3 +38,20 @@ output (2 lines):
38
38
--
39
39
ERR_MSG
40
40
}
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