Summary
The default snapshot path is derived only from the test file and function name.
Two assert_match_snapshot calls in the same test therefore resolve to the same
file unless the author manually constructs explicit paths.
The suite already records this limitation in TODOs such as
tests/acceptance/bashunit_fail_test.sh: "option to choose snapshot name?".
A mismatch also prints a diff without naming the snapshot file or reminding the
author about --snapshot-update. Missing-snapshot failures provide the path, so
the two failure modes have inconsistent guidance.
Proposal
Named snapshots
Add a backward-compatible named API rather than changing the existing second
argument, which is already a public explicit-file path:
assert_match_named_snapshot "verbose" "$output"
assert_match_named_snapshot_ignore_colors "simple" "$colored_output"
Derive names beside the existing default snapshot using a normalized suffix,
for example:
<test-file>.<test-function>.verbose.snapshot
Names must be normalized through the existing helper so spaces and punctuation
are safe and path traversal is impossible. Explicit paths on the existing
assertions remain unchanged.
Mismatch guidance
On failure, print:
- the resolved snapshot path
- a concise hint to re-record deliberately with
--snapshot-update
Keep the readable diff as the primary content.
Constraints
- Bash 3.0+
- Existing assertion signatures and snapshot filenames remain unchanged
- New assertions stay fork-free apart from the snapshot comparison behavior
- Named and default snapshots can coexist in one test
- Both completion scripts and assertion documentation remain in sync
- Machine-report contents must remain valid
Acceptance criteria
Summary
The default snapshot path is derived only from the test file and function name.
Two
assert_match_snapshotcalls in the same test therefore resolve to the samefile unless the author manually constructs explicit paths.
The suite already records this limitation in TODOs such as
tests/acceptance/bashunit_fail_test.sh: "option to choose snapshot name?".A mismatch also prints a diff without naming the snapshot file or reminding the
author about
--snapshot-update. Missing-snapshot failures provide the path, sothe two failure modes have inconsistent guidance.
Proposal
Named snapshots
Add a backward-compatible named API rather than changing the existing second
argument, which is already a public explicit-file path:
Derive names beside the existing default snapshot using a normalized suffix,
for example:
Names must be normalized through the existing helper so spaces and punctuation
are safe and path traversal is impossible. Explicit paths on the existing
assertions remain unchanged.
Mismatch guidance
On failure, print:
--snapshot-updateKeep the readable diff as the primary content.
Constraints
Acceptance criteria
snapshots/--snapshot-updatedocs/snapshots.md,docs/assertions.md, generated doc snapshots and both completion scriptsCHANGELOG.mdunder## Unreleasedmake sa·make lint·./bashunit --parallel --simple --strict tests/·bash build.sh bin -v