diff --git a/gomock/call.go b/gomock/call.go index 8ed74a62..a3fa1ae4 100644 --- a/gomock/call.go +++ b/gomock/call.go @@ -339,14 +339,14 @@ func (c *Call) matches(args []interface{}) error { // The last arg has a possibility of a variadic argument, so let it branch // sample: Foo(a int, b int, c ...int) - if len(c.args) == len(args) { + if i < len(c.args) && i < len(args) { if m.Matches(args[i]) { // Got Foo(a, b, c) want Foo(matcherA, matcherB, gomock.Any()) // Got Foo(a, b, c) want Foo(matcherA, matcherB, someSliceMatcher) // Got Foo(a, b, c) want Foo(matcherA, matcherB, matcherC) // Got Foo(a, b) want Foo(matcherA, matcherB) // Got Foo(a, b, c, d) want Foo(matcherA, matcherB, matcherC, matcherD) - break + continue } } diff --git a/sample/user_test.go b/sample/user_test.go index 875e81f5..d1de99cd 100644 --- a/sample/user_test.go +++ b/sample/user_test.go @@ -68,12 +68,12 @@ func TestVariadicFunction(t *testing.T) { defer ctrl.Finish() mockIndex := mock_user.NewMockIndex(ctrl) - mockIndex.EXPECT().Ellip("%d", 0, 1, 1, 2, 3).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 != 7 { + if sum != 26 { t.Errorf("Expected 7, got %d", sum) } }) @@ -82,7 +82,7 @@ func TestVariadicFunction(t *testing.T) { for _, value := range nums { sum += value } - if sum != 7 { + if sum != 10 { t.Errorf("Expected 7, got %d", sum) } }) @@ -114,8 +114,8 @@ func TestVariadicFunction(t *testing.T) { } }) - mockIndex.Ellip("%d", 0, 1, 1, 2, 3) - mockIndex.Ellip("%d", 0, 1, 1, 2, 3) + mockIndex.Ellip("%d", 1, 2, 3, 4) // Match second matcher. + mockIndex.Ellip("%d", 5, 6, 7, 8) // Match first matcher. mockIndex.Ellip("%d", 0) mockIndex.Ellip("%d") mockIndex.Ellip("%d")