diff --git a/lib/bats-core/test_functions.bash b/lib/bats-core/test_functions.bash index 72a337f7202..6ec6a9189f8 100644 --- a/lib/bats-core/test_functions.bash +++ b/lib/bats-core/test_functions.bash @@ -271,24 +271,36 @@ run() { # [!|-N] [--keep-empty-lines] [--separate-stderr] [--] &2'' failed, expected exit code 1, got 0" ] + [ "${lines[3]}" == "# (in test file $RELATIVE_FIXTURE_ROOT/print_output_on_failure_with_stderr.bats, line 8)" ] + [ "${lines[4]}" == "# \`false' failed" ] [ "${lines[5]}" == '# Last output:' ] [ "${lines[6]}" == '# fail hard' ] [ "${lines[7]}" == '# Last stderr:' ] [ "${lines[8]}" == '# with stderr' ] [ "${lines[9]}" == 'not ok 3 empty output on failure' ] - [ "${lines[10]}" == "# (in test file $RELATIVE_FIXTURE_ROOT/print_output_on_failure_with_stderr.bats, line 11)" ] + [ "${lines[10]}" == "# (in test file $RELATIVE_FIXTURE_ROOT/print_output_on_failure_with_stderr.bats, line 12)" ] [ "${lines[11]}" == "# \`false' failed" ] [ ${#lines[@]} -eq 12 ] } diff --git a/test/fixtures/bats/print_output_on_failure.bats b/test/fixtures/bats/print_output_on_failure.bats index e7f9168fad7..6a2c44d3ad8 100644 --- a/test/fixtures/bats/print_output_on_failure.bats +++ b/test/fixtures/bats/print_output_on_failure.bats @@ -3,7 +3,8 @@ } bats_require_minimum_version 1.5.0 # don't be fooled by order, this will run before the test above! @test "failure prints output" { - run -1 echo "fail hard" + run echo "fail hard" + false } @test "empty output on failure" { diff --git a/test/fixtures/bats/print_output_on_failure_with_stderr.bats b/test/fixtures/bats/print_output_on_failure_with_stderr.bats index 4ad5e412dc8..ed74dbbc2fd 100644 --- a/test/fixtures/bats/print_output_on_failure_with_stderr.bats +++ b/test/fixtures/bats/print_output_on_failure_with_stderr.bats @@ -4,7 +4,8 @@ @test "failure prints output" { bats_require_minimum_version 1.5.0 - run -1 --separate-stderr bash -c 'echo "fail hard"; echo with stderr >&2' + run --separate-stderr bash -c 'echo "fail hard"; echo with stderr >&2' + false } @test "empty output on failure" { diff --git a/test/run.bats b/test/run.bats index 10a0595249c..b3fc6a0db0b 100644 --- a/test/run.bats +++ b/test/run.bats @@ -96,15 +96,16 @@ print-stderr-stdout() { [ "${lines[4]}" == "not ok 2 run -1 echo hi" ] [ "${lines[5]}" == "# (in test file ${RELATIVE_FIXTURE_ROOT}/failing.bats, line 7)" ] [ "${lines[6]}" == "# \`run -1 echo hi' failed, expected exit code 1, got 0" ] - [ "${lines[7]}" == "not ok 3 run -2 exit 3" ] - [ "${lines[8]}" == "# (in test file ${RELATIVE_FIXTURE_ROOT}/failing.bats, line 11)" ] - [ "${lines[9]}" == "# \`run -2 exit 3' failed, expected exit code 2, got 3" ] - [ "${lines[10]}" == "not ok 4 run ! true" ] - [ "${lines[11]}" == "# (in test file ${RELATIVE_FIXTURE_ROOT}/failing.bats, line 15)" ] - [ "${lines[12]}" == "# \`run ! true' failed, expected nonzero exit code!" ] - [ "${lines[13]}" == "not ok 5 run multiple pass/fails" ] - [ "${lines[14]}" == "# (in test file ${RELATIVE_FIXTURE_ROOT}/failing.bats, line 22)" ] - [ "${lines[15]}" == "# \`run -1 /etc' failed, expected exit code 1, got 126" ] + [ "${lines[7]}" == "# hi" ] + [ "${lines[8]}" == "not ok 3 run -2 exit 3" ] + [ "${lines[9]}" == "# (in test file ${RELATIVE_FIXTURE_ROOT}/failing.bats, line 11)" ] + [ "${lines[10]}" == "# \`run -2 exit 3' failed, expected exit code 2, got 3" ] + [ "${lines[11]}" == "not ok 4 run ! true" ] + [ "${lines[12]}" == "# (in test file ${RELATIVE_FIXTURE_ROOT}/failing.bats, line 15)" ] + [ "${lines[13]}" == "# \`run ! true' failed, expected nonzero exit code!" ] + [ "${lines[14]}" == "not ok 5 run multiple pass/fails" ] + [ "${lines[15]}" == "# (in test file ${RELATIVE_FIXTURE_ROOT}/failing.bats, line 22)" ] + [ "${lines[16]}" == "# \`run -1 /etc' failed, expected exit code 1, got 126" ] } @test "run invalid exit code check error message" {