Skip to content

bashunit bench aborts on a malformed annotation without running tear_down_after_script #1322

Description

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

Summary

A malformed benchmark annotation aborts bashunit bench with exit 1 from inside the per-file loop. set_up_before_script has already run at that point, and tear_down_after_script never does.

Same class as #1318, in the bench runner. #1319 paired setup with teardown on the bench setup-failure path. This is the other early exit on the same loop.

Current behavior

bashunit::benchmark::parse_annotations rejects the bad value, the runner exits 1, and the file's teardown hook is skipped.

How to reproduce

bench_bad.sh:

RESOURCE=""

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

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

# @revs=abc
function bench_bad() { :; }
$ CLEANUP_MARKER=/tmp/bu-bench.marker ./bashunit bench bench_bad.sh
● set_up_before_script                                                      10ms
Running bench_bad.sh
Error: @revs in '# @revs=abc' is not a valid value.

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

Expected behavior

The annotation error still aborts the run with a non-zero status, and tear_down_after_script runs for the file whose setup already ran.

Where it happens

  • src/runner/bench.sh:124: parsed_annotations=$(bashunit::benchmark::parse_annotations "$fn_name" "$script") || exit 1
  • That sits inside bashunit::runner::call_bench_functions, called directly at src/runner/bench.sh:84
  • bashunit::runner::run_tear_down_after_script on src/runner/bench.sh:85 is never reached

Acceptance criteria

  • A test in tests/acceptance/bashunit_bench_test.sh following the shape of test_bench_cleans_up_when_set_up_before_script_fails: a bench file with a malformed annotation whose tear_down_after_script releases a resource, asserted gone with assert_file_not_exists.
  • The error message text and the non-zero exit code are unchanged. Existing annotation tests still pass.
  • CHANGELOG.md gets a Fixed entry.

Notes for the implementer

  • Return non-zero from call_bench_functions and let the loop finish the file, instead of exiting from the inner frame.
  • Keep the guarantee Malformed benchmark annotations are silently ignored #884 added: the exit status of $(...) inside read <<< is discarded, which is why the capture is separate and the failure is explicit. A malformed annotation must not be silently ignored.
  • 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