diff --git a/gomock/callset.go b/gomock/callset.go index b046b525..e4e85d60 100644 --- a/gomock/callset.go +++ b/gomock/callset.go @@ -84,7 +84,11 @@ func (cs callSet) FindMatch(receiver interface{}, method string, args []interfac for _, call := range exhausted { if err := call.matches(args); err != nil { _, _ = fmt.Fprintf(&callsErrors, "\n%v", err) + continue } + _, _ = fmt.Fprintf( + &callsErrors, "all expected calls for method %q have been exhausted", method, + ) } if len(expected)+len(exhausted) == 0 { diff --git a/gomock/callset_test.go b/gomock/callset_test.go index 7fc711a4..a2835f34 100644 --- a/gomock/callset_test.go +++ b/gomock/callset_test.go @@ -74,3 +74,26 @@ func TestCallSetRemove(t *testing.T) { cs.Remove(c) } } + +func TestCallSetFindMatch(t *testing.T) { + t.Run("call is exhausted", func(t *testing.T) { + cs := callSet{} + var receiver interface{} = "TestReceiver" + method := "TestMethod" + args := []interface{}{} + + c1 := newCall(t, receiver, method, reflect.TypeOf(receiverType{}.Func)) + cs.exhausted = map[callSetKey][]*Call{ + callSetKey{receiver: receiver, fname: method}: []*Call{c1}, + } + + _, err := cs.FindMatch(receiver, method, args) + if err == nil { + t.Fatal("expected error, but was nil") + } + + if err.Error() == "" { + t.Fatal("expected error to have message, but was empty") + } + }) +}