feat(snapshot): add --no-snapshot-create to fail on a missing snapshot - #910
Merged
Conversation
A missing snapshot is written and counted as a snapshot assertion, and the run exits 0. So a snapshot that was never committed — gitignored, lost, or simply forgotten — is re-created by CI on the fly, and the green run asserted nothing. Nothing let a caller make that state fail. Add --no-snapshot-create / BASHUNIT_SNAPSHOT_CREATE=false: a missing snapshot fails the test, and the failure names the resolved path, which is derived from the test file and function name and so cannot be guessed from the source. Default behaviour is unchanged. A separate flag rather than folding it into --strict, which means `set -euo pipefail` for test bodies — a different axis, as the issue notes. It pairs with --snapshot-update: one records deliberately, the other forbids recording by accident. The tail shared by both snapshot assertions is now one function instead of two copies, since this is the second branch to be added to it. Closes #901
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.
🤔 Background
Related #901
A missing snapshot is recorded on the fly and the run exits 0. So a snapshot that was never committed — gitignored, lost or forgotten — gets re-created by CI, and the green run asserted nothing. Nothing let a caller make that state fail.
💡 Changes
--no-snapshot-create/BASHUNIT_SNAPSHOT_CREATE=false: a missing snapshot fails the test and the message names the resolved path (which is derived, not visible in the test source). Default behaviour is unchanged.assert_match_snapshotandassert_match_snapshot_ignore_colors; the tail they share is now one function rather than two copies.Kept as a separate flag rather than folded into
--strict, which meansset -euo pipefailfor test bodies — a different axis, as the issue notes. It pairs with--snapshot-update: one records deliberately, the other forbids recording by accident.