Skip to content

Commit

Permalink
misc. fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhang committed Sep 13, 2023
1 parent 0135608 commit 1b3cb79
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions gomock/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,24 +438,25 @@ func (c *Call) call() []func([]any) []any {
// It panics if the type of any of the arguments isn't *Call or a generated
// mock with an embedded *Call.
func InOrder(args ...any) {
var calls []*Call
calls := make([]*Call, 0, len(args))
for i := 0; i < len(args); i++ {
if call := getCall(args[i]); call != nil {
calls = append(calls, call)
continue
}
errMsg := fmt.Sprintf(
panic(fmt.Sprintf(
"invalid argument at position %d of type %T, InOrder expects *gomock.Call or generated mock types with an embedded *gomock.Call",
i,
args[i],
)
panic(errMsg)
))
}
for i := 1; i < len(calls); i++ {
calls[i].After(calls[i-1])
}
}

// getCall checks if the parameter is a *Call or a generated struct
// that wraps a *Call and returns the *Call pointer - if neither, it returns nil.
func getCall(arg any) *Call {
if call, ok := arg.(*Call); ok {
return call
Expand Down

0 comments on commit 1b3cb79

Please sign in to comment.