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

Commit ab03293

Browse files
authored
fix ill-formatted message with fmt-verbs like %s (#564)
If fmt-verb strings such as %s is included in the error message, the output becomes %!s(MISSING) unintendedly.
1 parent 0cdccf5 commit ab03293

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

gomock/callset.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package gomock
1616

1717
import (
1818
"bytes"
19+
"errors"
1920
"fmt"
2021
)
2122

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

98-
return nil, fmt.Errorf(callsErrors.String())
99+
return nil, errors.New(callsErrors.String())
99100
}
100101

101102
// Failures returns the calls that are not satisfied.

gomock/controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,20 +281,20 @@ func TestUnexpectedArgValue_FirstArg(t *testing.T) {
281281
defer reporter.recoverUnexpectedFatal()
282282
subject := new(Subject)
283283

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

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

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

299299
reporter.assertFatal(func() {
300300
// The expected call wasn't made.

0 commit comments

Comments
 (0)