Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

gomock.GotFormatterAdapter doesn't work for variadic function #391

Closed
spastukhov opened this issue Jan 23, 2020 · 2 comments
Closed

gomock.GotFormatterAdapter doesn't work for variadic function #391

spastukhov opened this issue Jan 23, 2020 · 2 comments
Milestone

Comments

@spastukhov
Copy link

Actual behavior A clear and concise description of what the bug is.
When configured for variadic functions GotFormatterAdapter is not invoked.

Expected behavior A clear and concise description of what you expected to
happen.
"Got" values are formatted by provided GotFormatterAdapter

To Reproduce Steps to reproduce the behavior

type IF interface {
	SimpleMethod(i int)
	VariadicMethod(i ...int)
}

func TestGoMockGotFormatter(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mif := NewMockIF(ctrl)

	var iface IF = mif

	wantMatcher := gomock.WantFormatter(
		gomock.StringerFunc(func() string { return "blah" }),
		gomock.Eq((6)),
	)
	gotMatcher := gomock.GotFormatterAdapter(
		gomock.GotFormatterFunc(func(i interface{}) string {
			// Leading 0s
			return fmt.Sprintf("%02d", i)
		}),
		wantMatcher,
	)

	//mif.EXPECT().SimpleMethod(gotMatcher)
	mif.EXPECT().VariadicMethod(gotMatcher)

	//iface.SimpleMethod(5)
	iface.VariadicMethod(4, 2)

}

Output:

xxx.go:xx: Unexpected call to *xxx.MockIF.VariadicMethod([4 2]) at xxx.go:xx because: 
        Expected call at xxx.go:xx doesn't match the argument at index 0.
        Got: [4 2]
        Want: blah
    panic.go:563: missing call(s) to *xx.MockIF.VariadicMethod(blah) xxx.go:xx

Additional Information

  • gomock mode (reflect or source):
    source
  • gomock version or git ref:
    version = "v1.4.0"
  • golang version:
    1.13

Triage Notes for the Maintainers

@codyoss
Copy link
Member

codyoss commented Jan 24, 2020

Thanks for the report we will look into this.

@codyoss codyoss added this to the v1.5.0 milestone Feb 28, 2020
@codyoss
Copy link
Member

codyoss commented Jun 12, 2020

Closing this is favor of #432 . Should be fixed by #434

@codyoss codyoss closed this as completed Jun 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants