Skip to content

fix(assert): forward msgAndArgs through InEpsilonSlice - #1931

Open
mvanhorn wants to merge 1 commit into
stretchr:masterfrom
mvanhorn:fix/763-testify-inepsilonslice-message
Open

fix(assert): forward msgAndArgs through InEpsilonSlice#1931
mvanhorn wants to merge 1 commit into
stretchr:masterfrom
mvanhorn:fix/763-testify-inepsilonslice-message

Conversation

@mvanhorn

Copy link
Copy Markdown

Motivation

InEpsilonSlice calls InEpsilon once per element with the literal hint "at index %d", so the caller's msgAndArgs never 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 sibling InDeltaSlice already forwards msgAndArgs..., so the two slice helpers behave differently for identical caller code.

Summary

Forward the caller's message to each per-element InEpsilon call 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 as at index N plus the caller's rendered msgAndArgs (via the existing messageFromMsgAndArgs) when any were supplied, and pass that to InEpsilon.
  • assert/assertions_test.go: add TestInEpsilonSliceMessage, 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, and require need 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

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.

assert.InEpsilonSlice doesn't print the message

1 participant