Skip to content

fix(assert): preserve InEpsilonSlice context without eager formatting - #2002

Open
jipeng6036-del wants to merge 2 commits into
stretchr:masterfrom
jipeng6036-del:fix/inepsilon-slice-message-context
Open

jipeng6036-del wants to merge 2 commits into
stretchr:masterfrom
jipeng6036-del:fix/inepsilon-slice-message-context

Conversation

@jipeng6036-del

Copy link
Copy Markdown

Summary

Preserve caller-supplied messages for InEpsilonSlice type, length and element failures, while retaining the failing element index. Successful comparisons do not format caller-supplied messages.

Changes

Based on #1931 by Matt Van Horn (3e4f0198a57da20dfdafb95b786735fa205dea23); his commit, authorship and source reference are retained. This version additionally forwards context through the type/length checks and defers element-message formatting until failure. Regression tests cover function/method wrappers, require/formatted calls, indexed printf arguments, literal percent signs and lazy Stringer messages.

Motivation

A failing slice comparison can otherwise lose the context needed to identify the assertion. Eagerly rendering that context for every matching element also invokes user code even when the assertion succeeds.

Related issues

Fixes #763. Related to #1324 and #1931.

Validation

  • Linux Go 1.27.3: code generation, formatting, vet and the complete go test -race -count=1 ./... suite pass; generated files remain unchanged.
  • The unchanged upstream workflow passes all 12 fork CI jobs: stable/oldstable, Go 1.17–1.25 and Actions hashes. CI run.
  • A downstream module installed from local canonical module ZIPs exercises real testing.T failures through six public entry points. Caller context appears in 0/18 baseline cases, 6/18 cases with fix(assert): forward msgAndArgs through InEpsilonSlice #1931 alone, and 18/18 with this change; the successful-assertion formatting control also passes. Those failing-assertion probes intentionally exit 1.

Reproduction source and verification records are bound to commit 593ed2fdda1a2ca9730be402c1b906b6c90ce4ab.

Prepared and validated with Codex; no human review is claimed.

mvanhorn and others added 2 commits October 31, 2026 07:56
Preserve caller context in type and length failures, and defer per-element message formatting until an assertion fails. Cover function and method wrappers, printf arguments and lazy Stringer messages.

Co-authored-by: Matt Van Horn <mvanhorn@gmail.com>
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

2 participants