Skip to content

feat(mocktail): show argument diffs on verify mismatch failures - #273

Open
theprantadutta wants to merge 1 commit into
felangel:mainfrom
theprantadutta:feat/string-diffs-on-call-failures
Open

feat(mocktail): show argument diffs on verify mismatch failures#273
theprantadutta wants to merge 1 commit into
felangel:mainfrom
theprantadutta:feat/string-diffs-on-call-failures

Conversation

@theprantadutta

Copy link
Copy Markdown

Status

READY

Breaking Changes

NO — the richer message is only appended when a call to the same member (with the same shape) mismatches on a long/multiline string or a larger collection. For small values the failure message is byte-for-byte identical to today's, and the existing mockito-compat test suite passes unchanged.

Description

Implements the string diffs discussed in #208, following @renancaraujo's suggestion to reuse package:matcher's describeMismatch (I proposed this plan on the issue on May 22).

When verify finds no matching call, mocktail now looks for the closest unverified call — same member, same positional arity / named keys / type arguments, fewest mismatched arguments — and appends a per-argument mismatch description produced by the same Matcher that failed the comparison (equals(value) for concrete values, the wrapped matcher for any(that: ...)).

For the exact scenario from the issue (a long log message that differs only by trailing whitespace), the failure goes from a wall of text you have to eyeball twice, to:

No matching calls. All calls: MockLogger.info(Your next step is to upload the app bundle to the Play Store: build/app/outputs/bundle/release/app-release.aab )
Closest matching call: info
  positional argument #0: is different. Both strings start the same, but the actual value also has the following trailing characters:
(If you called `verify(...).called(0);`, please instead use `verifyNever(...);`.)

Mid-string differences get package:matcher's windowed diff with the ^ marker and Differ at offset N; collections get the mismatched index/key (was <9> instead of <4> at location [3]).

To keep noise down (and existing messages stable), the diff section only triggers when a mismatched value is "large": a string that is multiline or longer than 40 chars, or a collection with more than 5 elements. Small values keep the current short form, since the plain call listing already makes those differences obvious. Both thresholds are constants — happy to tune them or always show the diff if you'd prefer.

Fixes #208

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

@theprantadutta

Copy link
Copy Markdown
Author

Gentle bump @felangel — this is ready for review whenever you have a moment. It adds argument diffs to verify failures via package:matcher's describeMismatch (following @renancaraujo's suggestion on #208), with the short form preserved for small values so existing failure output is unchanged. 232/232 tests pass and the analyzer is clean. Happy to rebase if it's drifted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mocktail could offer string diffs on call failures?

1 participant