diff --git a/gomock/callset.go b/gomock/callset.go index c44a8a58..7b5cf553 100644 --- a/gomock/callset.go +++ b/gomock/callset.go @@ -69,12 +69,12 @@ func (cs callSet) FindMatch(receiver interface{}, method string, args []interfac // Search through the expected calls. expected := cs.expected[key] var callsErrors bytes.Buffer - for _, call := range expected { - err := call.matches(args) + for i := len(expected) - 1; i >= 0; i-- { + err := expected[i].matches(args) if err != nil { fmt.Fprintf(&callsErrors, "\n%v", err) } else { - return call, nil + return expected[i], nil } } diff --git a/sample/user_test.go b/sample/user_test.go index d1de99cd..1ef50ffa 100644 --- a/sample/user_test.go +++ b/sample/user_test.go @@ -35,12 +35,12 @@ func TestRemember(t *testing.T) { user.Remember(mockIndex, []string{"a", "b"}, []interface{}{1, 2}) // Check the ConcreteRet calls. - if c := mockIndex.ConcreteRet(); c != boolc { - t.Errorf("ConcreteRet: got %v, want %v", c, boolc) - } if c := mockIndex.ConcreteRet(); c != nil { t.Errorf("ConcreteRet: got %v, want nil", c) } + if c := mockIndex.ConcreteRet(); c != boolc { + t.Errorf("ConcreteRet: got %v, want %v", c, boolc) + } // Try one with an action. calledString := "" @@ -68,13 +68,13 @@ func TestVariadicFunction(t *testing.T) { defer ctrl.Finish() mockIndex := mock_user.NewMockIndex(ctrl) - mockIndex.EXPECT().Ellip("%d", 5, 6, 7, 8).Do(func(format string, nums ...int) { + mockIndex.EXPECT().Ellip("%d").Do(func(format string, nums ...int) { sum := 0 for _, value := range nums { sum += value } - if sum != 26 { - t.Errorf("Expected 7, got %d", sum) + if sum != 0 { + t.Errorf("Expected 0, got %d", sum) } }) mockIndex.EXPECT().Ellip("%d", gomock.Any()).Do(func(format string, nums ...int) { @@ -82,8 +82,8 @@ func TestVariadicFunction(t *testing.T) { for _, value := range nums { sum += value } - if sum != 10 { - t.Errorf("Expected 7, got %d", sum) + if sum != 0 { + t.Errorf("Expected 0, got %d", sum) } }) mockIndex.EXPECT().Ellip("%d", gomock.Any()).Do(func(format string, nums ...int) { @@ -100,22 +100,22 @@ func TestVariadicFunction(t *testing.T) { for _, value := range nums { sum += value } - if sum != 0 { - t.Errorf("Expected 0, got %d", sum) + if sum != 10 { + t.Errorf("Expected 7, got %d", sum) } }) - mockIndex.EXPECT().Ellip("%d").Do(func(format string, nums ...int) { + mockIndex.EXPECT().Ellip("%d", 5, 6, 7, 8).Do(func(format string, nums ...int) { sum := 0 for _, value := range nums { sum += value } - if sum != 0 { - t.Errorf("Expected 0, got %d", sum) + if sum != 26 { + t.Errorf("Expected 7, got %d", sum) } }) - mockIndex.Ellip("%d", 1, 2, 3, 4) // Match second matcher. - mockIndex.Ellip("%d", 5, 6, 7, 8) // Match first matcher. + mockIndex.Ellip("%d", 1, 2, 3, 4) // Match second to last matcher. + mockIndex.Ellip("%d", 5, 6, 7, 8) // Match last matcher. mockIndex.Ellip("%d", 0) mockIndex.Ellip("%d") mockIndex.Ellip("%d")