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

fix ill-formatted message with fmt-verbs like %s #564

Merged
merged 1 commit into from Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion gomock/callset.go
Expand Up @@ -16,6 +16,7 @@ package gomock

import (
"bytes"
"errors"
"fmt"
)

Expand Down Expand Up @@ -95,7 +96,7 @@ func (cs callSet) FindMatch(receiver interface{}, method string, args []interfac
_, _ = fmt.Fprintf(&callsErrors, "there are no expected calls of the method %q for that receiver", method)
}

return nil, fmt.Errorf(callsErrors.String())
return nil, errors.New(callsErrors.String())
}

// Failures returns the calls that are not satisfied.
Expand Down
6 changes: 3 additions & 3 deletions gomock/controller_test.go
Expand Up @@ -281,20 +281,20 @@ func TestUnexpectedArgValue_FirstArg(t *testing.T) {
defer reporter.recoverUnexpectedFatal()
subject := new(Subject)

expectedArg0 := TestStruct{Number: 123, Message: "hello"}
expectedArg0 := TestStruct{Number: 123, Message: "hello %s"}
ctrl.RecordCall(subject, "ActOnTestStructMethod", expectedArg0, 15)

reporter.assertFatal(func() {
// the method argument (of TestStruct type) has 1 unexpected value (for the Message field)
ctrl.Call(subject, "ActOnTestStructMethod", TestStruct{Number: 123, Message: "no message"}, 15)
}, "Unexpected call to", "doesn't match the argument at index 0",
"Got: {123 no message} (gomock_test.TestStruct)\nWant: is equal to {123 hello} (gomock_test.TestStruct)")
"Got: {123 no message} (gomock_test.TestStruct)\nWant: is equal to {123 hello %s} (gomock_test.TestStruct)")

reporter.assertFatal(func() {
// the method argument (of TestStruct type) has 2 unexpected values (for both fields)
ctrl.Call(subject, "ActOnTestStructMethod", TestStruct{Number: 11, Message: "no message"}, 15)
}, "Unexpected call to", "doesn't match the argument at index 0",
"Got: {11 no message} (gomock_test.TestStruct)\nWant: is equal to {123 hello} (gomock_test.TestStruct)")
"Got: {11 no message} (gomock_test.TestStruct)\nWant: is equal to {123 hello %s} (gomock_test.TestStruct)")

reporter.assertFatal(func() {
// The expected call wasn't made.
Expand Down