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

Commit

Permalink
fix ill-formatted message with fmt-verbs like %s (#564)
Browse files Browse the repository at this point in the history
If fmt-verb strings such as %s is included in the error message,
the output becomes %!s(MISSING) unintendedly.
  • Loading branch information
motemen authored Jun 4, 2021
1 parent 0cdccf5 commit ab03293
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion gomock/callset.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit ab03293

Please sign in to comment.