diff --git a/src/assert_failure.bash b/src/assert_failure.bash index d906059..31f89ce 100644 --- a/src/assert_failure.bash +++ b/src/assert_failure.bash @@ -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 @@ -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 diff --git a/src/assert_success.bash b/src/assert_success.bash index a8b2a38..eaadf95 100644 --- a/src/assert_success.bash +++ b/src/assert_success.bash @@ -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 diff --git a/test/assert_failure.bats b/test/assert_failure.bats index 6291afe..0882c4a 100755 --- a/test/assert_failure.bats +++ b/test/assert_failure.bats @@ -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' @@ -73,3 +91,4 @@ output (2 lines): -- ERR_MSG } + diff --git a/test/assert_success.bats b/test/assert_success.bats index 66f5aa7..5907b66 100755 --- a/test/assert_success.bats +++ b/test/assert_success.bats @@ -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 +} \ No newline at end of file