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

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

@spastukhov

Description

@spastukhov

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions