Why
assert_equals/assert_same failures print the full expected and actual values on single quoted lines (bashunit::console_results::print_failed_test, src/console_results.sh:305). For multiline strings (command output, file contents) this is unreadable — you get two blobs and hunt for the difference by eye.
Snapshot failures already solve this: print_failed_snapshot_test (src/console_results.sh:332) renders a git diff of expected vs actual when git is available (bashunit::dependencies::has_git), falling back to plain output otherwise. Reuse that machinery.
Proposal
When both of these hold in print_failed_test:
- expected or actual contains a newline, and
bashunit::dependencies::has_git (same gate as snapshots),
render a unified diff (same temp-file + git diff --no-index approach as the snapshot path — extract the shared logic into one helper instead of duplicating) after the existing Expected/but got header, possibly truncating the inline quoted values to their first line + … when the diff is shown.
Single-line values keep the current output byte-identical — a large body of acceptance/snapshot tests depends on it, and so do users parsing output.
Design notes
- Extract the diff-rendering block from
print_failed_snapshot_test into e.g. bashunit::console_results::render_diff expected_text actual_text and use it from both call sites (one commit for the extraction, no behavior change; next commit adds the multiline hook).
- Respect
--no-color / BASHUNIT_NO_COLOR (git diff must be called with color flags consistent with src/colors.sh state).
- Machine formats (JUnit/TAP/JSON reports) must keep receiving the raw expected/actual values, not the diff — only the console renderer changes.
- Add an opt-out env (
BASHUNIT_NO_DIFF=true) for users who scrape console output.
Tests first (TDD)
Acceptance test: multiline assert_equals failure shows a diff hunk; with BASHUNIT_NO_DIFF=true or without git shows current format; single-line failure output unchanged (snapshot test). Unit test the extracted render_diff helper.
Constraints
- Bash 3.0+; git remains optional (graceful fallback).
- CHANGELOG.md entry (user-visible).
Acceptance criteria
Line references valid at commit 1ae3e82.
Why
assert_equals/assert_samefailures print the full expected and actual values on single quoted lines (bashunit::console_results::print_failed_test,src/console_results.sh:305). For multiline strings (command output, file contents) this is unreadable — you get two blobs and hunt for the difference by eye.Snapshot failures already solve this:
print_failed_snapshot_test(src/console_results.sh:332) renders agit diffof expected vs actual when git is available (bashunit::dependencies::has_git), falling back to plain output otherwise. Reuse that machinery.Proposal
When both of these hold in
print_failed_test:bashunit::dependencies::has_git(same gate as snapshots),render a unified diff (same temp-file +
git diff --no-indexapproach as the snapshot path — extract the shared logic into one helper instead of duplicating) after the existingExpected/but gotheader, possibly truncating the inline quoted values to their first line +…when the diff is shown.Single-line values keep the current output byte-identical — a large body of acceptance/snapshot tests depends on it, and so do users parsing output.
Design notes
print_failed_snapshot_testinto e.g.bashunit::console_results::render_diff expected_text actual_textand use it from both call sites (one commit for the extraction, no behavior change; next commit adds the multiline hook).--no-color/BASHUNIT_NO_COLOR(git diff must be called with color flags consistent withsrc/colors.shstate).BASHUNIT_NO_DIFF=true) for users who scrape console output.Tests first (TDD)
Acceptance test: multiline
assert_equalsfailure shows a diff hunk; withBASHUNIT_NO_DIFF=trueor without git shows current format; single-line failure output unchanged (snapshot test). Unit test the extractedrender_diffhelper.Constraints
Acceptance criteria
./bashunit tests/and./bashunit --parallel tests/pass.make sa,make lintpass;shfmt -w .produces no diff.Line references valid at commit 1ae3e82.