Skip to content

mock: compare options after matching zero-argument functions - #1983

Open
sergioperezcheco wants to merge 1 commit into
stretchr:masterfrom
sergioperezcheco:fix/mock-zero-argument-options-20261005
Open

sergioperezcheco wants to merge 1 commit into
stretchr:masterfrom
sergioperezcheco:fix/mock-zero-argument-options-20261005

Conversation

@sergioperezcheco

Copy link
Copy Markdown

Summary

Fix functional-option matching stopping after the first matching zero-argument function.

Changes

  • Continue comparing the remaining option functions instead of returning success when a matching function has no parameters.
  • Add public mock.Arguments.Diff and Assert regressions for mismatches in the second and third positions, with equal, first-mismatch, length and empty controls.

Motivation

assertOpts explicitly handles zero-argument functions without invoking them. However, returning after the first matching function bypasses the source-identity checks for all later functions. For example, an expectation containing FunctionalOptions(optionA, optionA) incorrectly matches []func(){optionA, optionB} when optionA and optionB are distinct zero-argument functions defined on different lines.

This is a bug fix within that existing zero-argument branch, not a change to the ordinary func(*Config) option pattern. It preserves the source-file/line identity rule and does not invoke zero-argument functions or expand the API.

On the unchanged base commit, the second- and third-position regressions fail through both Diff and Assert; the four controls pass. With this change, the full mock package race tests, mock vet and targeted incremental govet/staticcheck lint pass locally. Those results were obtained on the identical base and exact same production/test bytes and reused for this commit. Formatting and git diff --check also pass. The full repository, generation step, other Go versions, other operating systems and remote CI have not been run.

Related issues

No existing issue was found for this early-return case. #1023 introduced the zero-argument handling; #1626 established the current per-function source-identity comparison. This does not reopen their original functional-option or indirect-call requests, nor implement the #1578 matcher API refactor.

Implemented by Hermes Agent (Nous Research), using model gpt-6.1-sol. No human-review claim is made.

Signed-off-by: sergioperezcheco <checo520@outlook.com>

@otrumb otrumb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified at c41bc9ec0f23fce21d29360c252a243ce3e1044c. The one-line return to continue change fixes later-position identity matching for zero-argument functional options while preserving non-invocation and ordinary functional-option semantics. Base reproduction failed for second/third-position mismatches; exact head passed independent public-surface tests, the added regression 20 times, focused and full tests, vet, and CGO-disabled build. No blocking or warning findings.

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.

2 participants