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

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: golang/mock
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.4.2
Choose a base ref
...
head repository: golang/mock
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.4.3
Choose a head ref
  • 1 commit
  • 4 files changed
  • 1 contributor

Commits on Mar 16, 2020

  1. Copy the full SHA
    3a35fb6 View commit details
Showing with 3 additions and 1,109 deletions.
  1. +2 −32 gomock/call.go
  2. +0 −875 gomock/call_test.go
  3. +1 −3 gomock/controller_test.go
  4. +0 −199 gomock/internal/validate/validate.go
34 changes: 2 additions & 32 deletions gomock/call.go
Original file line number Diff line number Diff line change
@@ -19,8 +19,6 @@ import (
"reflect"
"strconv"
"strings"

"github.com/golang/mock/gomock/internal/validate"
)

// Call represents an expected call to a mock.
@@ -107,24 +105,10 @@ 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.
// If the method signature of f is not compatible with the mocked function a
// panic will be triggered. Both the arguments and return values of f are
// validated.
func (c *Call) DoAndReturn(f interface{}) *Call {
// TODO: Check arity and types here, rather than dying badly elsewhere.
v := reflect.ValueOf(f)

switch v.Kind() {
case reflect.Func:
mt := c.methodType

ft := v.Type()
if err := validate.InputAndOutputSig(ft, mt); err != nil {
panic(fmt.Sprintf("DoAndReturn: %s", err))
}
default:
panic("DoAndReturn: argument must be a function")
}

c.addAction(func(args []interface{}) []interface{} {
vargs := make([]reflect.Value, len(args))
ft := v.Type()
@@ -150,24 +134,10 @@ 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.
// If the method signature of f is not compatible with the mocked function a
// panic will be triggered. Only the arguments of f are validated; not the return
// values.
func (c *Call) Do(f interface{}) *Call {
// TODO: Check arity and types here, rather than dying badly elsewhere.
v := reflect.ValueOf(f)

switch v.Kind() {
case reflect.Func:
mt := c.methodType

ft := v.Type()
if err := validate.InputSig(ft, mt); err != nil {
panic(fmt.Sprintf("Do: %s", err))
}
default:
panic("Do: argument must be a function")
}

c.addAction(func(args []interface{}) []interface{} {
vargs := make([]reflect.Value, len(args))
ft := v.Type()
Loading