golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.28k stars 610 forks source link

Bad formatted message when fmt-verbs included #565

Closed motemen closed 3 years ago

motemen commented 3 years ago

Actual behavior A clear and concise description of what the bug is.

With test code with gomock like below:

package eg

import (
    "testing"

    "github.com/golang/mock/gomock"
)

func Test(t *testing.T) {
    ctrl := gomock.NewController(t)
    foo := NewMockFoo(ctrl)
    foo.EXPECT().Foo("%s")
    foo.Foo("x")
}

We get:

--- FAIL: Test (0.00s)
    eg_test.go:14: Unexpected call to *eg.MockFoo.Foo([x]) at /src/eg_test.go:14 because:
        expected call at /src/eg_test.go:12 doesn't match the argument at index 0.
        Got: x
        Want: is equal to %!s(MISSING)
    controller.go:137: missing call(s) to *eg.MockFoo.Foo(is equal to %s) /src/eg_test.go:12
    controller.go:137: aborting test due to missing call(s)

Having %!s(MISSING) unintendedly.

Expected behavior A clear and concise description of what you expected to happen.

We sholud get:

--- FAIL: Test (0.00s)
    eg_test.go:14: Unexpected call to *eg.MockFoo.Foo([x]) at /src/eg_test.go:14 because:
        expected call at /src/eg_test.go:12 doesn't match the argument at index 0.
        Got: x
        Want: is equal to %s
    controller.go:137: missing call(s) to *eg.MockFoo.Foo(is equal to %s) /src/eg_test.go:12
    controller.go:137: aborting test due to missing call(s)

To Reproduce Steps to reproduce the behavior

  1. Clone https://github.com/motemen/example-gomock-ill-formatted-message
  2. Run docker run --rm -v $PWD:/src -w /src golang go test

Additional Information

Triage Notes for the Maintainers

codyoss commented 3 years ago

@motemen Thanks!

codyoss commented 3 years ago

Fixed by #564