fix(assert): forward msgAndArgs through InEpsilonSlice - #1931
Open
mvanhorn wants to merge 1 commit into
Open
Conversation
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.
Motivation
InEpsilonSlicecallsInEpsilononce per element with the literal hint"at index %d", so the caller'smsgAndArgsnever reaches the failure output. The reader is left with only the relative-error line and no way to tell which assertion in a test produced it. Its siblingInDeltaSlicealready forwardsmsgAndArgs..., so the two slice helpers behave differently for identical caller code.Summary
Forward the caller's message to each per-element
InEpsiloncall while keeping the index hint, so a failure names both the mismatching element and the caller's context.Changes
assert/assertions.go: build the per-element message asat index Nplus the caller's renderedmsgAndArgs(via the existingmessageFromMsgAndArgs) when any were supplied, and pass that toInEpsilon.assert/assertions_test.go: addTestInEpsilonSliceMessage, asserting the complete rendered failure output for a call with a formatted message, for a call without one, and that a passing comparison still writes nothing.The signature is unchanged, so the generated forwarders in
assert/assertion_format.go,assert/assertion_forward.go, andrequireneed no regeneration. Callers that pass no message keep exactly their current output.Related issues
This supersedes #1899, which made the same forwarding change and was closed by its author without answering the one review question it received: whether the added test could assert the full error rather than a fragment. The test here does assert the full output, matching the convention the existing message tests in this file already use.
Closes #763