Errors setup teardown still not caught correctly#513
Conversation
|
@Chemaclass Thanks a lot for the super quick fix! I can confirm that bashunit now correctly displays errors and does not execute the test function when the However, we still have to handle errors explicitly. The following function set_up() {
false
true
}In order to detect the function set_up() {
false || return -1
true
}IMO this is not ideal, because it bears the risk of potential errors being overlooked and However, I am open for a discussion here, since at least it is possible now to detect errors in these functions. I think that we should detect any failing statement, though, in order to force robust and clean test implementations. |
|
@carlfriedrich, thanks for the feedback, I implemented the fix here #515 | release 0.27 |
📚 Description
Closes #512
Fixed lifecycle hooks not catching failing commands (non-zero exit codes) in
set_up,tear_down,set_up_before_script, andtear_down_after_script.Problem: Failing commands like
git checkout non-existing-ref,ls /non/existing/path, orfalsewere silently ignored in lifecycle hooks, allowing tests to run even when setup failed.Root cause: Using
if ! command; then status=$?- the$?inside the if block returns 0 (success of the conditional) instead of the command's actual exit code.Solution: Changed to
command || exit $?to capture the exit code immediately.🔖 Changes
src/runner.sh:349- Changedif ! runner::run_set_uptorunner::run_set_up || exit $?The Real Fix
Both set_up and tear_down were broken for the same reason - they both call runner::execute_test_hook which was working correctly. The actual bug that affected BOTH was that runner::execute_test_hook wasn't catching failing commands.
But once
runner::execute_test_hookreturns the correct error code:set_upneeded the fix at line 349 to properly exit on errortear_downwas already correctly using|| teardown_status=$?in the trapSo both are fixed now, but through different mechanisms:
runner::execute_test_hooknow correctly detects all failing commandsset_up fix: || exit $?ensures we exit when setup failstear_down"fix": It was already correctly written with|| teardown_status=$?✅ To-do list
CHANGELOG.mdto reflect the new feature or fix