Repository navigation
Description
Description
On bats 1.12.0 (the flake's batsWithLibs), a failing teardown_file is reported as not ok N teardown_file failed in the TAP stream but the bats process exits 0. Verified during the #1694 spike with a minimal file:
teardown_file() { return 1; }
@test "noop" { true; }1..1
ok 1 noop
not ok 2 teardown_file failed
# (from function `teardown_file' in test file t.bats, line 1)
# `return 1' failed
$ echo $?
0
Consequence for this repo: any invariant checked in a teardown_file (the natural place for a "the suite left the world unchanged" pin, which is exactly what #1694 first considered) can go red in the log while CI stays green. test-project/action.yml runs bats -j "$(nproc)" tests/bats/ and gates on the exit code only.
Steps to Reproduce
- Save the two-line file above as
t.bats nix develop --command bats t.bats; echo $?
Expected Behavior
A teardown_file failure fails the run (non-zero exit), the same way a setup_file failure does.
Actual Behavior
not ok line printed, exit code 0.
Environment
- OS: any
- Container Runtime: n/a
- Image Version/Tag: dev-shell bats 1.12.0 from the flake
- Architecture: any
Additional Context
Found while spiking #1694 (a teardown_file snapshot of the live <repo>-worktrees directory was rejected as the red-first pin for this reason; the pin landed as a per-test assertion instead). No test in tests/bats/ currently relies on teardown_file failing, so this is a latent hole, not a live one.
Possible Solution
- Check whether bats upstream tracks this (bats-core issue tracker,
teardown_fileexit code) and whether a newer bats in nixpkgs fixes it; if so, the pin advance is the fix. - Otherwise, guard in
test-project/action.ymlandjust test-bats: capture TAP output and fail on^not ok .* teardown_file failedregardless of the exit code. - Either way, a shape test that greps
tests/bats/*.batsand refuses assertions insideteardown_fileuntil the hole is closed.
Changelog Category
No changelog needed
Activity
c-vigo commentedon Sep 25, 2026
Triage 2026-09-25: the reported exit code does not reproduce
The two-line repro from the description, run against the flake's
bats(1.12.0), exits 1 in every mode tried — plain,-j 4, directory target,--formatter tapandpretty, and the exactnix develop --command bats t.bats; echo $?form:Same result on bats 1.14.0 (the
nixpkgs-unstableinput). The exit code is set explicitly inbats-exec-file(bats_file_exit_trap,bats_exec_file_status=1on theteardown_filebranch) and propagated bybats-exec-suiteon both the serial and the parallel path. Every upstreamteardown_fileexit-code issue (bats-core #588, #615, #623, #695, #916) is closed. Note the pasted output in the description lacks thebats warning: Executed 2 instead of expected 1 testsline bats always prints here, so$?in the spike was most likely read after a pipeline (| teeor similar), not from bats.Three genuine silent-pass paths do exist (all reproduced, exit 0, and none prints
not ok):setup_filecallsskip→ a failingteardown_fileis swallowed entirely (deliberate upstream, bats-core#695).--filter/--filter-statusselecting zero tests in a file → the file body never runs.teardown_file(false | cat) → plain bash pipeline status, nopipefail.A TAP-grep guard (Possible Solution 2) would catch none of these and would add output parsing to both invocation sites for a code path that already works; a pin advance (Possible Solution 1) has nothing to fix.
Disposition: land only the shape pin (Possible Solution 3):
tests/test_bats_shape.pyrefusesteardown_fileintests/bats/*.bats(empty allowlist), with the three swallow paths documented in its docstring. Noteardown_fileexists in the suite today, so the gate starts green.test(bats): refuse teardown_file assertions in the BATS suite
test(bats): match a teardown_file defined after a semicolon
test(bats): refuse teardown_file assertions in the BATS suite (#1720)
c-vigo commentedon Sep 25, 2026
Closing as not reproducible as filed: a failing
teardown_fileexits 1 on bats 1.12.0 and 1.14.0 in every mode (evidence in the triage comment above). The three real swallow paths are now guarded by a shape pin refusingteardown_fileintests/bats(#1720, merged todevat ac90505).