Repository navigation
fix(assert): preserve InEpsilonSlice context without eager formatting - #2002
Open
jipeng6036-del wants to merge 2 commits into
Open
jipeng6036-del wants to merge 2 commits into
jipeng6036-del wants to merge 2 commits into
Conversation
…lon call Fixes stretchr#763 (cherry picked from commit 3e4f019)
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>
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
Preserve caller-supplied messages for
InEpsilonSlicetype, 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 lazyStringermessages.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
go test -race -count=1 ./...suite pass; generated files remain unchanged.testing.Tfailures 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.