Skip to content

Commit

Permalink
Output return code of last command when a test fails
Browse files Browse the repository at this point in the history
  • Loading branch information
sttts authored and bmizerany committed Jul 17, 2012
1 parent a5b64b8 commit 05d14a0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions roundup-5-test.sh
Expand Up @@ -85,6 +85,15 @@ it_runs_after_if_a_test_fails_part_2() {
test "!" -f foo.txt test "!" -f foo.txt
} }


# Output the correct return code of a failing command of a testcase.
it_outputs_the_return_code_7() {
function f() { return 42; }
x=$(echo asdf)

function g() { return 7; }
g
}

# Roundup will ignore tests starting with `x`. Ignored tests are still # Roundup will ignore tests starting with `x`. Ignored tests are still
# enumerated in the plans output marked with `[I]`. If roundup does not ignore # enumerated in the plans output marked with `[I]`. If roundup does not ignore
# this, result in failure. # this, result in failure.
Expand Down
14 changes: 14 additions & 0 deletions roundup.sh
Expand Up @@ -95,6 +95,11 @@ roundup_trace() {
# Delete the first two lines that represent roundups execution of the # Delete the first two lines that represent roundups execution of the
# test function. They are useless to the user. # test function. They are useless to the user.
sed '1d' | sed '1d' |
# Delete the last line which is the "set +x" of the error trap
sed '$d' |
# Replace the rc=$? of the error trap with an verbose string appended
# to the failing command trace line.
sed '$s/.*rc=/exit code /' |
# Trim the two left most `+` signs. They represent the depth at which # Trim the two left most `+` signs. They represent the depth at which
# roundup executed the function. They also, are useless and confusing. # roundup executed the function. They also, are useless and confusing.
sed 's/^++//' | sed 's/^++//' |
Expand Down Expand Up @@ -245,6 +250,15 @@ do
set +x set +x
} &>/dev/null } &>/dev/null


# exit subshell with return code of last failing command. This
# is needed to see the return code 253 on failed assumptions.
# But, only do this if the error handling is activated.
set -E
trap 'rc=$?; set +x; set -o | grep "errexit.*on" >/dev/null && exit $rc' ERR

# If `before` wasn't redefined, then this is `:`.
before

# Momentarily turn off auto-fail to give us access to the tests # Momentarily turn off auto-fail to give us access to the tests
# exit status in `$?` for capturing. # exit status in `$?` for capturing.
set +e set +e
Expand Down

0 comments on commit 05d14a0

Please sign in to comment.