Repository navigation
test(bats): refuse teardown_file assertions in the BATS suite - #1720
Merged
Merged
Conversation
The exit-code claim in #1699 did not reproduce: a plainly failing teardown_file exits 1 on bats 1.12.0 and on 1.14.0, in serial, parallel and both formatters, so there is nothing to guard in the runners. Three paths do swallow such a failure whole (exit 0, no `not ok` line): a `skip` in setup_file (deliberate upstream, bats-core#695), a `--filter`/`--filter-status` that selects zero tests in the file, and a command failing inside a pipeline (bats sets no `pipefail`). Pin the shape instead: no .bats file defines teardown_file, allowlist empty, so no future invariant is asserted where it can go unchecked while the run stays green. Refs: #1699
`setup() { :; }; teardown_file() { false; }` slipped past the
line-anchored pattern. Search for the definition at line start or after
a `;`; the comment skip now does real work.
Refs: #1699
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
#1699 reported that a failing
teardown_fileprintsnot okbut leavesbatsexiting 0. That does not reproduce. The two-line file from the issue exits 1 on the flake's bats 1.12.0 in every mode tried — plain,-j 4, directory target, both formatters, and the exactnix develop --command bats t.bats; echo $?form — and on bats 1.14.0 from thenixpkgs-unstableinput. The exit code is set inbats-exec-fileand propagated bybats-exec-suiteon both the serial and the parallel path; every upstreamteardown_fileexit-code issue is closed. The pasted output in the issue lacks thebats warning: Executed 2 instead of expected 1 testsline bats always prints here, so the spike most likely read$?after a pipeline.What is real: three paths swallow a
teardown_filefailure whole — exit 0 and nonot okline either — so neither a pin advance nor a TAP-grep guard (the issue's options 1 and 2) has anything to catch:setup_filecallsskip→ the file'steardown_filestatus is discarded (deliberate upstream, bats-core#695)--filter/--filter-statusselects zero tests in the file → the file body never runsteardown_file(false | cat) → plain bash pipeline status, nopipefailSo this lands only option 3: a shape pin in
tests/test_bats_shape.pyrefusingteardown_fileintests/bats/*.bats, with an empty allowlist and the three swallow paths documented where the next reader will look. No file definesteardown_filetoday, so the gate starts green.Type of Change
feat-- New featurefix-- Bug fixdocs-- Documentation onlychore-- Maintenance task (deps, config, etc.)refactor-- Code restructuring (no behavior change)test-- Adding or updating testsci-- CI/CD pipeline changesbuild-- Build system or dependency changesrevert-- Reverts a previous commitstyle-- Code style (formatting, whitespace)Modifiers
!) -- This change breaks backward compatibilityChanges Made
tests/test_bats_shape.pyTEARDOWN_FILE_ALLOWLIST: frozenset[str] = frozenset()and a definition matcher coveringteardown_file() {,teardown_file () {and bothfunctionspellings, ignoring comment linestest_bats_file_defines_no_teardown_file, parametrized over the suite like the existing minimum-version pintest_teardown_file_matcher: 7 positive spellings (including a definition after a;, a review finding) and 7 non-matches (commented-out definitions, a quoted mention,teardown,teardown_file_helper)Refs: #1697, #1699Changelog Entry
No changelog needed — test-only, per the issue.
Testing
just test)Manual Testing Details
uv run pytest tests/test_bats_shape.py -q→ 57 passed (1 discovery + 21 min-version + 21 no-teardown-file + 14 matcher)teardown_file() { true; }totests/bats/clean.bats→FAILED …[clean.bats], reverted; nothing temporary left in the treenot ok 2 teardown_file failedand exit 1, in every mode listed aboveruff check/ruff format --checkclean;prek run --all-files→ all hooks passedChecklist
docs/templates/, then runjust docs)CHANGELOG.mdin the[Unreleased]section (and pasted the entry above)Additional Notes
The issue is closed with this PR as "not reproducible as filed; shape pin landed", with the reproduction evidence on the issue.
Refs: #1699