Skip to content

--stop-on-failure skips tear_down_after_script in sequential runs #1321

Description

@Chemaclass
Q A
OS macOS 26.5.2 (arm64)
Shell & version bash 3.2.57
bashunit version 0.50.0

Summary

--stop-on-failure ends a sequential run with exit from inside the test loop. The file's tear_down_after_script never runs, so anything set_up_before_script acquired is leaked.

Same class as #1318. That one fixed the setup-failure path. This is the stop-on-failure path, and it leaks the same way.

The --parallel path is not affected: it raises a flag file instead of exiting.

Current behavior

The first failing test triggers exit "$EXIT_CODE_STOP_ON_FAILURE". The EXIT trap renders the summary and exits. No file-scoped hook runs, and the output says nothing about it.

How to reproduce

sof_test.sh:

RESOURCE=""

function set_up_before_script() {
  RESOURCE="$CLEANUP_MARKER"
  : >"$RESOURCE"
}

function tear_down_after_script() {
  rm -f "$RESOURCE"
}

function test_a_fails() { assert_true false; }
function test_b() { assert_true true; }
$ CLEANUP_MARKER=/tmp/bu-sof.marker ./bashunit --no-parallel --stop-on-failure sof_test.sh
Stop on failure enabled...
Tests:      1 failed, 1 total

$ ls /tmp/bu-sof.marker
/tmp/bu-sof.marker

The same file under --parallel --stop-on-failure releases the resource.

Expected behavior

tear_down_after_script runs before the process exits, so a file-scoped resource can be released in the one place meant for it. Exit code and summary output stay as they are.

Where it happens

  • src/runner/diagnostics.sh:75: exit "$EXIT_CODE_STOP_ON_FAILURE"
  • Called from src/runner/exec.sh:689, :710, :751
  • Sequential runs execute call_test_functions in the main shell, so that exit leaves src/runner/discovery.sh:235 unreached
  • The EXIT trap at src/main/run.sh:83 dispatches bashunit::main::handle_stop_on_failure_sync (src/main/run.sh:395), which prints and exits

Acceptance criteria

  • An acceptance test: a file with a failing test and a tear_down_after_script that releases a resource. Under --no-parallel --stop-on-failure the resource is gone.
  • Exit code stays EXIT_CODE_STOP_ON_FAILURE.
  • The "Stop on failure enabled..." output and the failure summary are unchanged. The existing stop-on-failure snapshots still pass.
  • --parallel --stop-on-failure behaviour unchanged.
  • A tear_down_after_script that itself fails on this path does not swallow the stop-on-failure exit code.
  • CHANGELOG.md gets a Fixed entry.

Notes for the implementer

  • Two shapes. Set a flag that the loop checks after call_test_functions returns, so the normal cleanup block at discovery.sh:235 runs and then the loop breaks. Or run the hook from handle_stop_on_failure_sync, which then needs the current test file in a global the trap can read.
  • The first shape keeps one cleanup path for the whole loop, which is the point tear_down_after_script is not run when set_up_before_script fails #1318 made. Prefer it unless something blocks it. Ctrl-C does not run tear_down_after_script for the file in flight #1323 needs a "current file" global for the same reason. Build it once and use it in both.
  • Careful with the flag: --stop-on-failure must still stop, and must not run the remaining files.
  • Bash 3.0+ only. See .claude/rules/bash-style.md.
  • make sa, make lint, ./bashunit tests/, ./bashunit --parallel tests/.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions