Skip to content

Show a text diff in the exception message for a text mismatch - #1947

Merged
SimonCropp merged 2 commits into
mainfrom
text-diff
Sep 30, 2026
Merged

SimonCropp merged 2 commits into
mainfrom
text-diff

Conversation

@SimonCropp

Copy link
Copy Markdown
Member

When a text snapshot doesn't match and no string comparer returned a message, the exception now shows a line diff instead of both texts in full. The diff comes from DiffEngine's new TextDiff.Format (VerifyTests/DiffEngine#909, released in 20.6.0). This gives the equivalent of Verify.DiffPlex without installing it.

Received: Tests.Foo.received.txt
Verified: Tests.Foo.verified.txt
Diff:
2 line 2
- line 3
+ line three
4 line 4

Settings

  • VerifierSettings.UseTextDiffFormat(TextDiffFormat): Compact (the default), Full or Minimal. These match Verify.DiffPlex's OutputType layouts.
  • VerifierSettings.DisableTextDiff(): show both texts in full, as before.

Behaviour

  • Where the diff is built. It's in VerifyExceptionMessageBuilder, not in a default string comparer, so it doesn't change how equality is decided.
  • Comparers still win. A comparer's message still takes precedence, so existing Verify.DiffPlex users see no change until they remove it.
  • Exact comparison. Lines compare exactly, whitespace and case included. Verify.DiffPlex ignored whitespace, so a failure caused only by whitespace showed no changed lines.
  • Fallback. Texts that differ only in line endings produce an empty diff, and the message falls back to both texts in full.
  • Inline snapshots are unchanged. They still show received and expected in full.

Other changes

  • DiffEngine 20.5.2 → 20.6.0.
  • Docs: a new "Text Diff Format" section in exception-message-format. The verify-options text and the Verify.DiffPlex entry in comparer are updated.

Tests

  • New VerifyExceptionMessageBuilderTests cover each format, the diff disabled, a whitespace-only change, and the line-endings fallback.
  • Eight existing message snapshots changed. The only difference in each is that the full text became a Diff: block.
  • Verify.ExceptionParsing.Tests pass on net11.0 and net48, and Verify.Tests pass on net11.0.

When two bumps edit adjacent lines in Directory.Packages.props, the second
can't be merged after the first lands, and gh pr merge failed the run.
Dependabot rebases conflicting PRs itself and the rebase reruns Build, so
log a warning and exit instead of failing.
When a text file does not match and no string comparer supplied a message,
the exception now shows a line diff from DiffEngine's TextDiff.Format rather
than the received and verified text in full. The format is set with
VerifierSettings.UseTextDiffFormat (Compact by default, Full or Minimal), and
VerifierSettings.DisableTextDiff restores the full text. A comparer's message
still takes precedence, and texts that differ only in line endings fall back
to the full text.

Bumps DiffEngine to 20.6.0, which adds TextDiff.
@SimonCropp SimonCropp added this to the 33.2.0 milestone Sep 30, 2026
@SimonCropp
SimonCropp merged commit d7428c1 into main Sep 30, 2026
6 checks passed
@SimonCropp
SimonCropp deleted the text-diff branch September 30, 2026 04:13
This was referenced Sep 30, 2026
This was referenced Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant