Skip to content

fix: mark testify mock constructors and cleanup as helpers - #1183

Open
eliotee wants to merge 1 commit into
vektra:v3from
eliotee:fix/testify-constructor-helpers
Open

fix: mark testify mock constructors and cleanup as helpers#1183
eliotee wants to merge 1 commit into
vektra:v3from
eliotee:fix/testify-constructor-helpers

Conversation

@eliotee

@eliotee eliotee commented Sep 6, 2026

Copy link
Copy Markdown

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 existing TestingT implementations that do not.

Keep the helper assertions in nested scopes so generic type parameters named helper or ok remain valid. Add regression coverage for the actual reported caller line, testing objects without Helper, and generic constructors. The bulk of the diff updates checked-in generated fixtures.

Fixes #1143.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

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.
  • Repeated mocks.generate produced an identical patch; hand-written changes pass gofumpt and git diff --check.
  • The caller-location regression failed against the original generated mocks and passes after regeneration.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes

No documentation changes are needed for this correction to test failure locations.

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.

Mark constructor and Cleanup function as Helpers

1 participant