Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Output return code of last command when a test fails

  • Loading branch information...
commit 05d14a0489ab879fbddf78823818c1fee79c531e 1 parent a5b64b8
@sttts sttts authored committed
Showing with 23 additions and 0 deletions.
  1. +9 −0 roundup-5-test.sh
  2. +14 −0 roundup.sh
View
9 roundup-5-test.sh
@@ -85,6 +85,15 @@ it_runs_after_if_a_test_fails_part_2() {
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
# enumerated in the plans output marked with `[I]`. If roundup does not ignore
# this, result in failure.
View
14 roundup.sh
@@ -95,6 +95,11 @@ roundup_trace() {
# Delete the first two lines that represent roundups execution of the
# test function. They are useless to the user.
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
# roundup executed the function. They also, are useless and confusing.
sed 's/^++//' |
@@ -245,6 +250,15 @@ do
set +x
} &>/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
# exit status in `$?` for capturing.
set +e
Please sign in to comment.
Something went wrong with that request. Please try again.