Skip to content

fix(test): fail loudly when BATS_LOAD names a file that is not there - #179

Open
fentas wants to merge 1 commit into
mainfrom
fix/bats-load-loud-failure
Open

fix(test): fail loudly when BATS_LOAD names a file that is not there#179
fentas wants to merge 1 commit into
mainfrom
fix/bats-load-loud-failure

Conversation

@fentas

@fentas fentas commented Aug 6, 2026

Copy link
Copy Markdown
Member

load_source treated a missing file as "skip, silently" regardless of how it was chosen.

For the default path that is right — the .sh beside a .bats is a convention, and suites legitimately have none.

For an explicit BATS_LOAD it is not: the caller named a file, and return 0 sources nothing, so the suite runs against whatever the environment already provides. That is how BATS_LOAD=argsh.min.sh from the wrong directory reports on a bundle it never read.

Measured

run before after
BATS_LOAD=/nonexistent 136 failures, all command not found, none mentioning BATS_LOAD 1 failure naming the file and the cwd
BATS_LOAD=argsh.min.sh 3 failures 3 failures (unchanged)
default (no BATS_LOAD) 2 failures 2 failures (unchanged)

Worse than the noise: under a misdirected BATS_LOAD, any test file that happens not to touch the source still passed.

Notes

  • No automated regression test — exercising this needs bats-inside-bats against the helper bats itself loads, which is more machinery than the guard is worth. Verified by the before/after measurement above.
  • shellcheck was not available locally; CI's lint job covers it.
  • Found while investigating the argsh.min.sh / CI item in a downstream backlog. Separately worth knowing: on main, test, minify (including its "Test minified" step) and lint all pass — the only failing job is coverage (argsh coverage builtin exits 1 with no output), and it has been red since 2026-05-10.

🤖 Generated with Claude Code

`load_source` treated a missing file as "skip, silently" regardless of how it
was chosen. For the DEFAULT path that is right — the `.sh` beside a `.bats` is
a convention, and suites legitimately have none. For an EXPLICIT `BATS_LOAD`
it is not: the caller named a file, and returning 0 sources NOTHING, so the
suite runs against whatever the environment already provides.

That is how `BATS_LOAD=argsh.min.sh` from the wrong directory reports on a
bundle it never read.

Measured on this tree: a misdirected BATS_LOAD turned 370 passing tests into
136 failures, every one of them `command not found` with no mention of
BATS_LOAD anywhere — and any test file that happens not to touch the source
still PASSED. After this change the same run stops at one failure that names
the cause and the cwd.

Unchanged where it should be: the default run still reports its usual 2
failures, and BATS_LOAD=argsh.min.sh still loads the bundle and reports its
usual 3. Only the unhonourable case moved.

No automated regression test: exercising this needs bats-inside-bats against
the helper that bats itself loads, which is more machinery than the guard.
Verified by before/after measurement instead, quoted above.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 6, 2026 03:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Bats test helper to treat a missing BATS_LOAD target as a hard error, while keeping the existing “silent skip” behavior for the default adjacent .sh convention. This prevents tests from accidentally running against whatever happens to already be in the environment when an explicit source file was intended.

Changes:

  • Add an explicit guard: if BATS_LOAD is set and the resolved file is missing, print a clear error (including cwd) and return non-zero.
  • Preserve the existing behavior for the default source path (no BATS_LOAD): missing file returns success and remains silent.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/helper.bash
Comment on lines +39 to +41
# EXPLICIT (BATS_LOAD set): the caller named a file. Returning 0 sources
# NOTHING and runs the suite against whatever the environment already
# provides, so `BATS_LOAD=argsh.min.sh` from the wrong directory reports on a
Comment thread test/helper.bash
Comment on lines +42 to +45
# bundle it never read. Measured: a misdirected BATS_LOAD turns 370 passing
# tests into 136 failures that say `command not found` and never mention
# BATS_LOAD — and any test file that does not happen to touch the source
# still PASSES. An explicit request that cannot be honoured is an error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants