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

Commit b96f175

Browse files
authored
Move argument requirements for Do and DoAndReturn out of example code 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.
1 parent aba2ff9 commit b96f175

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

gomock/call.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func (c *Call) MaxTimes(n int) *Call {
108108
// DoAndReturn declares the action to run when the call is matched.
109109
// The return values from this function are returned by the mocked function.
110110
// It takes an interface{} argument to support n-arity functions.
111+
// The anonymous function must have the same number of input and output arguments as the mocked method.
111112
func (c *Call) DoAndReturn(f interface{}) *Call {
112113
// TODO: Check arity and types here, rather than dying badly elsewhere.
113114
v := reflect.ValueOf(f)
@@ -143,6 +144,7 @@ func (c *Call) DoAndReturn(f interface{}) *Call {
143144
// return values are ignored to retain backward compatibility. To use the
144145
// return values call DoAndReturn.
145146
// It takes an interface{} argument to support n-arity functions.
147+
// The anonymous function must have the same number of input arguments as the mocked method.
146148
func (c *Call) Do(f interface{}) *Call {
147149
// TODO: Check arity and types here, rather than dying badly elsewhere.
148150
v := reflect.ValueOf(f)

gomock/example_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ func ExampleCall_DoAndReturn_latency() {
2020
mockIndex := NewMockFoo(ctrl)
2121

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

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

0 commit comments

Comments
 (0)