Skip to content

Print struct field name in Got and Want output by default #228 #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gomock/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ func (c *Call) addAction(action func([]any) []any) {
}

func formatGottenArg(m Matcher, arg any) string {
got := fmt.Sprintf("%v (%T)", arg, arg)
got := fmt.Sprintf("%+v (%T)", arg, arg)
if gs, ok := m.(GotFormatter); ok {
got = gs.Got(arg)
}
Expand Down
4 changes: 2 additions & 2 deletions gomock/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,13 @@ func TestUnexpectedArgValue_FirstArg(t *testing.T) {
// 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 %s} (gomock_test.TestStruct)")
"Got: {Number:123 Message:no message} (gomock_test.TestStruct)\nWant: is equal to {Number:123 Message: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 %s} (gomock_test.TestStruct)")
"Got: {Number:11 Message:no message} (gomock_test.TestStruct)\nWant: is equal to {Number:123 Message:hello %s} (gomock_test.TestStruct)")

reporter.assertFatal(func() {
// The expected call wasn't made.
Expand Down
2 changes: 1 addition & 1 deletion gomock/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func getString(x any) string {
if s, ok := x.(fmt.Stringer); ok {
return s.String()
}
return fmt.Sprintf("%v", x)
return fmt.Sprintf("%+v", x)
}

// isGeneratedMock checks if the given type has a "isgomock" field,
Expand Down