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

Commit 8247798

Browse files
committed
Fix #71 Do signature change error msg
Update the error handling for Call.Do in the case where the argument passed to Call.Do does not match expectations. * panic if the argument is not a function * panic if the number of input arguments do not match those expected by Call * panic if the types of the input arguments do not match those expected by Call * panic if the number of return arguments do not match those expected by Call * panic if the types of return arguments do not match those expected by Call
1 parent 5c85495 commit 8247798

File tree

4 files changed

+601
-2
lines changed

4 files changed

+601
-2
lines changed

gomock/call.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"reflect"
2020
"strconv"
2121
"strings"
22+
23+
"github.com/golang/mock/gomock/internal/calldo"
2224
)
2325

2426
// Call represents an expected call to a mock.
@@ -135,9 +137,20 @@ func (c *Call) DoAndReturn(f interface{}) *Call {
135137
// return values call DoAndReturn.
136138
// It takes an interface{} argument to support n-arity functions.
137139
func (c *Call) Do(f interface{}) *Call {
138-
// TODO: Check arity and types here, rather than dying badly elsewhere.
139140
v := reflect.ValueOf(f)
140141

142+
switch v.Kind() {
143+
case reflect.Func:
144+
mt := c.methodType
145+
146+
ft := v.Type()
147+
if err := calldo.ValidateInputAndOutputSig(ft, mt); err != nil {
148+
panic(err)
149+
}
150+
default:
151+
panic("Do: argument must be a function")
152+
}
153+
141154
c.addAction(func(args []interface{}) []interface{} {
142155
vargs := make([]reflect.Value, len(args))
143156
ft := v.Type()

0 commit comments

Comments
 (0)