fix: mark testify mock constructors and cleanup as helpers - #1183
Open
eliotee 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.
Description
When generated testify mocks have unmet expectations, cleanup failures point into the generated mock instead of the test that constructed it. Mark the constructor and its cleanup callback as helpers when the supplied testing object supports
Helper(), preserving compatibility with existingTestingTimplementations that do not.Keep the helper assertions in nested scopes so generic type parameters named
helperorokremain valid. Add regression coverage for the actual reported caller line, testing objects withoutHelper, and generic constructors. The bulk of the diff updates checked-in generated fixtures.Fixes #1143.
Type of change
Version of Go used when building/testing
Go 1.26.0 on macOS arm64.
How Has This Been Tested?
go run github.com/go-task/task/v3/cmd/task test test.e2e: 175 unit tests, all shell e2e scenarios, and 5 Go e2e tests passed.go run github.com/go-task/task/v3/cmd/task lint: 0 issues.mocks.generateproduced an identical patch; hand-written changes passgofumptandgit diff --check.Checklist
No documentation changes are needed for this correction to test failure locations.