Skip to content

assert: show diff for one unmatched struct pair - #1960

Open
fzlzjerry wants to merge 1 commit into
stretchr:masterfrom
fzlzjerry:fix/1376-single-struct-element-diff
Open

assert: show diff for one unmatched struct pair#1960
fzlzjerry wants to merge 1 commit into
stretchr:masterfrom
fzlzjerry:fix/1376-single-struct-element-diff

Conversation

@fzlzjerry

Copy link
Copy Markdown

Summary

Add a field-level diff when ElementsMatch leaves one unmatched struct on each side, following the narrow case discussed in #1376.

Changes

  • Reuse the existing unified-diff formatter for same-type struct values and non-nil struct pointers.
  • Retain the existing list dumps. Primitive values, nils, incompatible types and multiple unmatched elements keep their current diagnostics.
  • Add 27 regression and boundary cases covering reordering, arrays, slices, interfaces, pointers and duplicate counts. Matching behavior is unchanged.

For example, a boolean field change now includes:

- Enabled: (bool) true,
+ Enabled: (bool) false,

Validation

  • Full go test -race -count=1 ./... passes on Go 1.17.13, 1.23.12, 1.25.14, 1.26.8 and 1.27.1.

  • The repository's generation, formatting and vet scripts pass on Go 1.26.8 and 1.27.1; regeneration produces no changes.

  • A 500-case before/after comparison preserves every matching result. The 400 non-target diagnostic reports are byte-identical; the remaining 100 single-pair cases gain the field diff.

  • The unchanged All builds workflow on the fork passed all 12 jobs on this commit.

Related issues

Closes #1376.

Append the existing unified diff when each list has exactly one unmatched
non-nil struct or struct pointer of the same type. Keep list matching and
all other diagnostics unchanged.

Fixes stretchr#1376
Copilot AI lite review requested due to automatic review settings September 9, 2026 07:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

ElementsMatch should shows exact difference (per line)

2 participants