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

Commit

Permalink
Move argument requirements for Do and DoAndReturn out of example code…
Browse files Browse the repository at this point in the history
… and into function commentary (#572)

Regardless of the result of #558, this is not a new requirement (I believe), and the location of it in the example code was easy to miss.

The `Do` version excludes a reference to the output argument count, as the returns are ignored.
  • Loading branch information
bconway committed Jun 12, 2021
1 parent aba2ff9 commit b96f175
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 2 additions & 0 deletions gomock/call.go
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
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

0 comments on commit b96f175

Please sign in to comment.