Skip to content

Commit b0a3e79

Browse files
authored
Merge pull request #622 from TypedDevs/fix/383-stop-on-failure-illegal-optiond
fix(runner): honour --stop-on-failure on runtime errors
2 parents a3837cf + 4672fb7 commit b0a3e79

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Allow most assert functions to accept an optional trailing label parameter to override the failure message title (e.g. `assert_same "a" "$b" "checking user name"`) (#77)
88

99
### Fixed
10+
- Fix `--stop-on-failure` not stopping when a test errors with a runtime error (e.g. `command not found`, `illegal option`) (#383)
1011
- Fix spying on `echo` or `printf` causing bashunit to hang due to infinite recursion (#607)
1112
- Fix invalid `.env.example` coverage threshold entry and copy `.env.example` to `.env` in CI test workflows so configuration parse errors are caught during automated test runs
1213
- Fix `clock::now` shell-time parsing when `EPOCHREALTIME` uses a comma decimal separator

src/runner.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,14 @@ function bashunit::runner::run_test() {
782782
bashunit::reports::add_test_failed "$test_file" "$failure_label" "$duration" "$total_assertions" "$error_message"
783783
bashunit::runner::write_failure_result_output "$test_file" "$failure_function" "$error_message" "$runtime_output"
784784
bashunit::internal_log "Test error" "$failure_label" "$error_message"
785+
786+
if bashunit::env::is_stop_on_failure_enabled; then
787+
if bashunit::parallel::is_enabled; then
788+
bashunit::parallel::mark_stop_on_failure
789+
else
790+
exit "$EXIT_CODE_STOP_ON_FAILURE"
791+
fi
792+
fi
785793
return
786794
fi
787795

tests/acceptance/bashunit_stop_on_failure_test.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,15 @@ function test_bashunit_when_stop_on_failure_env_simple_output() {
3131
assert_match_snapshot "$(./bashunit --no-parallel --env "$TEST_ENV_FILE_STOP_ON_FAILURE" "$test_file" --simple)"
3232
assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE_STOP_ON_FAILURE" "$test_file" --simple)"
3333
}
34+
35+
function test_bashunit_stop_on_failure_with_runtime_error() {
36+
local test_file=./tests/acceptance/fixtures/test_bashunit_stop_on_failure_runtime_error.sh
37+
local output=""
38+
local exit_code=0
39+
40+
output="$(./bashunit --no-parallel --env "$TEST_ENV_FILE" --stop-on-failure "$test_file")" || exit_code=$?
41+
42+
assert_same 1 "$exit_code"
43+
assert_contains "A runtime error" "$output"
44+
assert_not_contains "B not executed" "$output"
45+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
function test_a_runtime_error() {
4+
nonexistent_command_bashunit_383_xyz
5+
}
6+
7+
function test_b_not_executed() {
8+
assert_same 1 1
9+
}

0 commit comments

Comments
 (0)