Repository navigation
assert: avoid false changes to map entries in equality diffs - #2016
Open
businessdeveloper69 wants to merge 1 commit into
Open
businessdeveloper69 wants to merge 1 commit into
businessdeveloper69 wants to merge 1 commit into
Conversation
atishay-kasliwal
left a comment
There was a problem hiding this comment.
Compared diff() for maps on master and here. When an entry is added or changed at the end, master also marked the entry before it as changed (only the comma differed). Here only the real change shows, for nested maps too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
An unchanged map entry can appear on both sides of an
assert.Equaldiff when a new final key moves the comma. The existingTestDiffexpectation showed this for the unchanged"three": 3entry.Changes
Use a trailing comma for every map entry when building a unified assertion diff. Enable this in the local dump configuration used by
diff. The existing regression now shows"three"as a context line.Motivation and verification
I replayed the timestamp map from #288 through public
assert.Equalon v1.12.1, master and this commit. Appending and removing keys produced two false edit lines on the release and master, and zero with this change. Genuine value edits still appear.I also ran Viper v1.21.0’s unchanged test, then repeated it with one extra YAML key. The original fixture passed in all runs. With the extra key, the test still failed correctly. Before the fix, the diff also removed and added the unchanged
trousers: denimentry. With the fix, the only changed map entry was the addedwaistcoat: wool. Viper’s map assertionThe full Linux race suite passed on every Go minor from 1.17 through 1.27. The project’s generation, formatting and vet checks passed on Go 1.26.11 and 1.27.4.
Closes #288. The earlier go-spew proposal and the later decision to vendor the formatter provide the background for this change. Original formatter proposal · Vendoring discussion
AI assisted.