Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions bash_unit
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/test_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down