Part of #761.
Problem
assert_match_snapshot forks ~6-8 times even when the snapshot matches (the common case):
src/assert_snapshot.sh:5 — $(echo -n "$1" | tr -d '\r'): 2 forks to strip carriage returns.
src/assert_snapshot.sh:7 — $(bashunit::helper::find_test_function_name): capture fork around a pure-bash helper.
src/assert_snapshot.sh:8 — $(bashunit::snapshot::resolve_file ...), which internally (src/assert_snapshot.sh:62-64) forks dirname once, basename once, and normalize_variable_name twice.
src/assert_snapshot.sh:83 — snapshot=$(tr -d '\r' <"$snapshot_path"): subshell + external tr per compare.
assert_match_snapshot_ignore_colors (src/assert_snapshot.sh:19) adds a sed on top.
Task — checklist, one commit each
Tests first (TDD)
tests/unit/snapshot_test.sh (or nearest existing snapshot tests — grep first) is the spec. Add cases: content containing \r, snapshot file with \r\n line endings, custom file hint vs derived path, ANSI-colored input for the ignore-colors variant. Snapshot files on disk must remain byte-compatible with ones created by the current version.
Constraints
- Bash 3.0+ only.
- Existing
.snapshot files must keep matching (no format/normalization change).
Acceptance criteria
Line references valid at commit 1ae3e82.
Part of #761.
Problem
assert_match_snapshotforks ~6-8 times even when the snapshot matches (the common case):src/assert_snapshot.sh:5—$(echo -n "$1" | tr -d '\r'): 2 forks to strip carriage returns.src/assert_snapshot.sh:7—$(bashunit::helper::find_test_function_name): capture fork around a pure-bash helper.src/assert_snapshot.sh:8—$(bashunit::snapshot::resolve_file ...), which internally (src/assert_snapshot.sh:62-64) forksdirnameonce,basenameonce, andnormalize_variable_nametwice.src/assert_snapshot.sh:83—snapshot=$(tr -d '\r' <"$snapshot_path"): subshell + externaltrper compare.assert_match_snapshot_ignore_colors(src/assert_snapshot.sh:19) adds asedon top.Task — checklist, one commit each
\rstripping with pure-bash${var//$'\r'/}atsrc/assert_snapshot.sh:5and for the file content at:83(read with$(<"$snapshot_path")— no external exec — then strip in bash).find_test_function_nameandnormalize_test_function_name/normalize_variable_name(add slots if they don't exist yet; coordinate with the assert hot-path issue which adds some of the same slots).resolve_file(src/assert_snapshot.sh:55), replacedirname/basenamewith parameter expansion (${path%/*},${path##*/}) and convert the function itself to a return slot. Watch the edge caseBASH_SOURCEwithout a slash.ignore_colorsvariant: reusebashunit::str::strip_ansi(src/str.sh:4) instead of a bespokesed, so plain input takes its pure-bash fast path. Verify the sed patterns match ([mK]suffixes) before swapping; if they differ, align deliberately and cover with a test.Tests first (TDD)
tests/unit/snapshot_test.sh(or nearest existing snapshot tests — grep first) is the spec. Add cases: content containing\r, snapshot file with\r\nline endings, custom file hint vs derived path, ANSI-colored input for the ignore-colors variant. Snapshot files on disk must remain byte-compatible with ones created by the current version.Constraints
.snapshotfiles must keep matching (no format/normalization change).Acceptance criteria
./bashunit tests/and./bashunit --parallel tests/pass after every commit.make sa,make lintpass;shfmt -w .produces no diff.Line references valid at commit 1ae3e82.