From 05d14a0489ab879fbddf78823818c1fee79c531e Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Wed, 27 Jun 2012 11:14:14 +0200 Subject: [PATCH] Output return code of last command when a test fails --- roundup-5-test.sh | 9 +++++++++ roundup.sh | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/roundup-5-test.sh b/roundup-5-test.sh index 0e6b322..250a586 100644 --- a/roundup-5-test.sh +++ b/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. diff --git a/roundup.sh b/roundup.sh index f6e7412..94b3929 100755 --- a/roundup.sh +++ b/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