assert: include map key in InDeltaMapValues error message#1898
Open
gaurav0107 wants to merge 2 commits into
Open
assert: include map key in InDeltaMapValues error message#1898gaurav0107 wants to merge 2 commits into
gaurav0107 wants to merge 2 commits into
Conversation
When InDeltaMapValues fails for a particular map entry, the failure
message did not say which key produced the mismatch. The output looked
like:
Error: Max difference between 3 and 4 allowed is 0.01, but difference was -1
leaving the user to bisect their map by hand. Inline the relevant
InDelta math so the failure message can be prefixed with key[<k>]:,
producing:
Error: key[a]: Max difference between 3 and 4 allowed is 0.01, but difference was -1
The behaviour for valid input is unchanged.
Fixes stretchr#1254
Replace the single-case test with a table covering: - string-keyed map with int values - int-keyed map with float values - non-numerical value at a key (Parameters must be numerical) - NaN actual value This pins the new key[<k>]: prefix across the four message branches introduced for stretchr#1254.
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
Closes #1254.
assert.InDeltaMapValuesnow prefixes per-key delta failures withkey[<k>]:so users can immediately see which entry diverged.Why
Without the key, a failing
InDeltaMapValuesagainst a multi-entry map gives no hint about which key broke. Previously:After this change:
The reporter showed the same before/after on the issue and even prototyped the fix; this PR finishes that work.
Changes
assert/assertions.go: inline the relevantInDeltamath insideInDeltaMapValuesso the failure message can include the map key. The numeric/NaN/delta branches mirrorInDeltaexactly, with the only addition being akey[<k>]:prefix.assert/assertions_test.go: addTestInDeltaMapValues_ErrorIncludesKeycovering the new message format.assert/assertion_format.go,assert/assertion_forward.go,require/require.go,require/require_forward.go: regenerated bygo generate ./...to propagate the updated doc comment.Testing
go test -v -race ./...— all packages pass./.ci.gofmt.sh,./.ci.govet.sh,./.ci.gogenerate.sh— passTestInDeltaMapValues_ErrorIncludesKeyassertskey[a]:appears in the captured failure output.Backward compatibility
Behaviour for valid input is unchanged — only the failure-message text is enriched.
True/Falsesemantics are preserved. No tests in the repo pattern-match the previous message text.