Skip to content

Commit e5a5a2d

Browse files
authored
Merge pull request #1055 from LandonTClipp/LandonTClipp/variadic_arg_fix
Fix issue when no value specified for variadic arg
2 parents 0e3b2a9 + 93b3cab commit e5a5a2d

File tree

5 files changed

+59
-12
lines changed

5 files changed

+59
-12
lines changed

internal/fixtures/buildtag/comment/mocks_testify_comment_test.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/fixtures/mocks_testify_test_test.go

Lines changed: 36 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/fixtures/variadic_with_multiple_returns_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,17 @@ func TestNoUnrollVariadicRun(t *testing.T) {
6666
m.Foo("", "")
6767
assert.True(t, ran)
6868
}
69+
70+
func TestNoUnrollVariadicWithNoVariadicArgument(t *testing.T) {
71+
var ran bool
72+
73+
m := NewMockVariadicWithMultipleReturns(t)
74+
m.EXPECT().Foo(mock.Anything, mock.Anything).Run(
75+
func(one string, two ...string) {
76+
ran = true
77+
},
78+
).Return("", nil)
79+
//nolint: errcheck
80+
m.Foo("")
81+
assert.True(t, ran)
82+
}

internal/mock_testify.templ

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ func (_c *{{ $ExpecterCallNameInstantiated }}) Run(run func({{ $method.ArgList }
193193
}
194194
}
195195
{{- else }}
196-
variadicArgs := args[{{ len $nonVariadicParams }}].({{ $variadicParam.TypeString }})
196+
var variadicArgs {{ $variadicParam.TypeString }}
197+
if len(args) > {{ len $nonVariadicParams }} {
198+
variadicArgs = args[{{ len $nonVariadicParams }}].({{ $variadicParam.TypeString }})
199+
}
197200
{{- end }}
198201
arg{{ $i }} = variadicArgs
199202
{{- else }}

mockery-tools.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION=v3.3.0
1+
VERSION=v3.3.1

0 commit comments

Comments
 (0)