Skip to content

mock: treat Anything as a matcher only in expectations - #1944

Open
justadityaraj wants to merge 1 commit into
stretchr:masterfrom
justadityaraj:fix/anything-actual-argument
Open

mock: treat Anything as a matcher only in expectations#1944
justadityaraj wants to merge 1 commit into
stretchr:masterfrom
justadityaraj:fix/anything-actual-argument

Conversation

@justadityaraj

Copy link
Copy Markdown

Summary

Treat mock.Anything as a matcher only when it appears in an expected argument list.

Problem / Motivation

Arguments.Diff also treated an actual argument equal to the mock.Anything sentinel as a wildcard. As a result, a runtime call such as MethodCalled("Do", mock.Anything) could satisfy an expectation for a different literal value.

Changes

  • Remove wildcard handling for mock.Anything on the actual-argument side.
  • Keep the existing expectation-side matcher behavior.
  • Add unit and MethodCalled regression coverage for both directions.

User impact

Mocks now reject runtime mock.Anything values that do not equal the configured expectation, preventing unexpected calls from passing silently.

Verification

  • go test ./mock -count=1 — passed
  • go vet ./mock — passed
  • gofmt -l mock/mock.go mock/mock_test.go — clean
  • go generate ./... — no generated changes
  • git diff --check — passed

The full Windows run also passed the changed mock package and the unaffected root/internal/require packages. It could not complete repository-wide because existing tests require Windows symlink privileges and a race-enabled subprocess toolchain.

Related issues

Closes #1943

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.

mock: mock.Anything still works backwards

1 participant