diff --git a/bash_unit b/bash_unit index b43050b..325e5f7 100755 --- a/bash_unit +++ b/bash_unit @@ -55,7 +55,8 @@ fail() { [[ -n "$stderr" ]] && [ -s "$stderr" ] && notify_stderr < "$stderr" stacktrace | notify_stack - exit 1 + # Exit with special code 99 to signal that notify_test_failed was already called + exit 99 } assert() { @@ -303,8 +304,12 @@ run_test() { ) local status=$? if (( status != 0 )); then - # notify_test_failed "$__bash_unit_current_test__" - exit $status + # Check if fail() was called (exit code 99 means notification already done) + if [[ ${status} -ne 99 ]]; then + notify_test_failed "$__bash_unit_current_test__" + fi + # Always exit with 1 for failure + exit 1 else notify_test_succeeded "$__bash_unit_current_test__" fi diff --git a/tests/test_cli.sh b/tests/test_cli.sh index 5959348..8f7f2bf 100644 --- a/tests/test_cli.sh +++ b/tests/test_cli.sh @@ -204,6 +204,11 @@ test_one_test_should_stop_when_assert_fails() { "$($BASH_UNIT <(echo 'test_fail() { echo "before failure" >&2 ; assert false ; echo "after failure" >&2 ; }') 2>&1 >/dev/null)" } +test_failure_status_printed_after_test_name() { + assert_matches "Running test_fail_should_print_failure ... FAILURE"$'\n'"Overall result: FAILURE" \ + "$($BASH_UNIT <(echo 'test_fail_should_print_failure() { false; }'))" +} + setup() { # fake basic unix commands bash_unit relies on so that # we ensure bash_unit keeps working when people fake