Model testify, gotest.tools, and goconvey assertions as trusted functions#420
Open
TvdW wants to merge 3 commits into
Open
Model testify, gotest.tools, and goconvey assertions as trusted functions#420TvdW wants to merge 3 commits into
TvdW wants to merge 3 commits into
Conversation
Trusted function matching previously required the call to be a selector expression (`assert.Error(...)`), so functions of dot-imported packages (`Error(...)` with `import . "..."`) were never matched. Resolve the called identifier for both call forms via `asthelper.FuncIdentFromCallExpr` in both `matchCall` and `generateComparators`. Soundness is unchanged: the identifier must still resolve to a function object whose package path matches the trusted signature, so local functions and function values never match.
…ions Extend the SplitBlockOn hook with more assertion functions whose success implies nilability facts about their arguments: - testify `ErrorContains(f)`/`EqualError(f)` (function and method forms): these can only pass with a non-nil error, same as `Error`. - gotest.tools assert (both /v3 and the legacy v1/v2 import path): `NilError`, `Error`, and `ErrorContains`, plus `Assert` via a new `boolOrErrorExpr` action handling its bool and error argument forms. - goconvey `So(actual, assertion, ...)`: a new `soExpr` action resolves the assertion argument to its package-level object and models the nilability-relevant `Should*` assertions. The idiomatic dot-imported call form relies on the dot-import matching from the previous commit. Also hoist the argIndex bounds check from the individual actions into SplitBlockOn, and document that the failure branch of a split is modeled as terminating execution.
`if assert.NoError(t, err) { <use> }` is a common pattern with testify's
non-fatal `assert` package, but narrowing previously only applied to
statement-position assertion calls (via SplitBlockOn), so NilAway
reported false positives inside such guarded branches.
Model these through the ReplaceConditional mechanism, following the
existing `errors.As` pattern: the conditional is replaced with
`<call> && <implied expr>` (e.g., `assert.NoError(t, err) && err == nil`),
where the implied expression is the same one `_splitBlockOn` derives for
the call in statement position, so the per-assertion semantics are
defined in a single place.
c385155 to
6c573fd
Compare
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.
This PR adds three more test libraries to the hooks, in an attempt to further reduce false positives around test suites.
Claude-assisted, human-reviewed.
No diff on stdlib expected because it doesn't use any of these 😉