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

Move argument requirements for Do and DoAndReturn out of example code and into function commentary #572

Merged
merged 1 commit into from
Jun 12, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gomock/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (c *Call) MaxTimes(n int) *Call {
// DoAndReturn declares the action to run when the call is matched.
// The return values from this function are returned by the mocked function.
// It takes an interface{} argument to support n-arity functions.
// The anonymous function must have the same number of input and output arguments as the mocked method.
func (c *Call) DoAndReturn(f interface{}) *Call {
// TODO: Check arity and types here, rather than dying badly elsewhere.
v := reflect.ValueOf(f)
Expand Down Expand Up @@ -143,6 +144,7 @@ func (c *Call) DoAndReturn(f interface{}) *Call {
// return values are ignored to retain backward compatibility. To use the
// return values call DoAndReturn.
// It takes an interface{} argument to support n-arity functions.
// The anonymous function must have the same number of input arguments as the mocked method.
func (c *Call) Do(f interface{}) *Call {
// TODO: Check arity and types here, rather than dying badly elsewhere.
v := reflect.ValueOf(f)
Expand Down
2 changes: 0 additions & 2 deletions gomock/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func ExampleCall_DoAndReturn_latency() {
mockIndex := NewMockFoo(ctrl)

mockIndex.EXPECT().Bar(gomock.Any()).DoAndReturn(
// signature of anonymous function must have the same number of input and output arguments as the mocked method.
func(arg string) string {
time.Sleep(1 * time.Millisecond)
return "I'm sleepy"
Expand All @@ -39,7 +38,6 @@ func ExampleCall_DoAndReturn_captureArguments() {
var s string

mockIndex.EXPECT().Bar(gomock.AssignableToTypeOf(s)).DoAndReturn(
// signature of anonymous function must have the same number of input and output arguments as the mocked method.
func(arg string) interface{} {
s = arg
return "I'm sleepy"
Expand Down