Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/assert_failure.bash
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ assert_failure() {

(( $# > 0 )) && local -r expected="$1"
if (( status == 0 )); then
batslib_print_kv_single_or_multi 6 'output' "$output" \
{ local -ir width=6
batslib_print_kv_single_or_multi "$width" 'output' "$output"
if [[ -n "$stderr" ]]; then
batslib_print_kv_single_or_multi "$width" 'stderr' "$stderr"
fi
} \
| batslib_decorate 'command succeeded, but it was expected to fail' \
| fail
elif (( $# > 0 )) && (( status != expected )); then
Expand All @@ -71,6 +76,9 @@ assert_failure() {
'actual' "$status"
batslib_print_kv_single_or_multi "$width" \
'output' "$output"
if [[ -n "$stderr" ]]; then
batslib_print_kv_single_or_multi "$width" 'stderr' "$stderr"
fi
} \
| batslib_decorate 'command failed as expected, but status differs' \
| fail
Expand Down
3 changes: 3 additions & 0 deletions src/assert_success.bash
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ assert_success() {
{ local -ir width=6
batslib_print_kv_single "$width" 'status' "$status"
batslib_print_kv_single_or_multi "$width" 'output' "$output"
if [[ -n "$stderr" ]]; then
batslib_print_kv_single_or_multi "$width" 'stderr' "$stderr"
fi
} \
| batslib_decorate 'command failed' \
| fail
Expand Down
19 changes: 19 additions & 0 deletions test/assert_failure.bats
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ output : a
ERR_MSG
}

@test "assert_failure(): returns 1 and displays \`\$stderr' if it is set" {
run --separate-stderr \
bash -c 'echo "a"
echo "b" >&2
exit 0'
run assert_failure

echo "Stderr: $stderr" >&3

assert_test_fail <<'ERR_MSG'

-- command succeeded, but it was expected to fail --
output : a
stderr : b
--
ERR_MSG
}

@test "assert_failure(): displays \`\$output' in multi-line format if it is longer then one line" {
run bash -c 'printf "a 0\na 1"
exit 0'
Expand Down Expand Up @@ -73,3 +91,4 @@ output (2 lines):
--
ERR_MSG
}

17 changes: 17 additions & 0 deletions test/assert_success.bats
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,20 @@ output (2 lines):
--
ERR_MSG
}

@test "assert_success(): displays \`\$stderr' if it is set" {
run --separate-stderr \
bash -c 'echo "a"
echo "b" >&2
exit 1'
run assert_success

assert_test_fail <<'ERR_MSG'

-- command failed --
status : 1
output : a
stderr : b
--
ERR_MSG
}