From 2c6fed18385d762fd49f0867c436cf1c327934a1 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 12 Aug 2014 17:28:03 -0500 Subject: [PATCH] Print the outermost, not innermost, failed command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The outermost command—i.e. the line that failed inside the test case function itself—is more likely to be meaningful at a glance than the innermost command, which might be e.g. the implementation of a helper assertion. --- libexec/bats-exec-test | 2 +- test/bats.bats | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libexec/bats-exec-test b/libexec/bats-exec-test index 49b8281..5a07665 100755 --- a/libexec/bats-exec-test +++ b/libexec/bats-exec-test @@ -253,7 +253,7 @@ bats_exit_trap() { if [ -z "$BATS_TEST_COMPLETED" ] || [ -z "$BATS_TEARDOWN_COMPLETED" ]; then echo "not ok $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION" >&3 bats_print_stack_trace "${BATS_ERROR_STACK_TRACE[@]}" >&3 - bats_print_failed_command "${BATS_ERROR_STACK_TRACE[0]}" "$BATS_ERROR_STATUS" >&3 + bats_print_failed_command "${BATS_ERROR_STACK_TRACE[${#BATS_ERROR_STACK_TRACE[@]}-1]}" "$BATS_ERROR_STATUS" >&3 sed -e "s/^/# /" < "$BATS_OUT" >&3 status=1 else diff --git a/test/bats.bats b/test/bats.bats index acc435b..dbc08d6 100755 --- a/test/bats.bats +++ b/test/bats.bats @@ -71,7 +71,7 @@ fixtures bats [ "${lines[1]}" = 'not ok 1 failing helper function' ] [ "${lines[2]}" = "# (from function \`failing_helper' in file $RELATIVE_FIXTURE_ROOT/test_helper.bash, line 6," ] [ "${lines[3]}" = "# in test file $RELATIVE_FIXTURE_ROOT/failing_helper.bats, line 5)" ] - [ "${lines[4]}" = "# \`false' failed" ] + [ "${lines[4]}" = "# \`failing_helper' failed" ] } @test "test environments are isolated" {