@@ -198,11 +198,37 @@ func (c *Call) String() string {
198
198
// Tests if the given call matches the expected call.
199
199
// If yes, returns nil. If no, returns error with message explaining why it does not match.
200
200
func (c * Call ) matches (args []interface {}) error {
201
- if len (args ) != len (c .args ) {
202
- return fmt .Errorf ("Expected call at %s has the wrong number of arguments. Got: %s, want: %s" ,
203
- c .origin , strconv .Itoa (len (args )), strconv .Itoa (len (c .args )))
201
+ if c .methodType .IsVariadic () {
202
+ if len (c .args ) < c .methodType .NumIn ()- 1 {
203
+ return fmt .Errorf ("matcher count is not enough at %s. Got: %d, want: greater than or equal to %d" ,
204
+ c .origin , len (c .args ), c .methodType .NumIn ()- 1 )
205
+ }
206
+ if len (c .args ) != c .methodType .NumIn () && len (args ) != len (c .args ) {
207
+ return fmt .Errorf ("Expected call at %s has the wrong number of arguments. Got: %d, want: %d" ,
208
+ c .origin , len (args ), len (c .args ))
209
+ }
210
+ if len (args ) < len (c .args )- 1 {
211
+ return fmt .Errorf ("Expected call at %s has the wrong number of arguments. Got: %d, want: greater than or equal to %d" ,
212
+ c .origin , len (args ), len (c .args )- 1 )
213
+ }
214
+ } else {
215
+ if len (args ) != len (c .args ) {
216
+ return fmt .Errorf ("Expected call at %s has the wrong number of arguments. Got: %d, want %d" ,
217
+ c .origin , len (args ), len (c .args ))
218
+ }
219
+ }
220
+
221
+ if len (args ) < len (c .args ) {
222
+ args = append (args , nil )
204
223
}
205
224
for i , m := range c .args {
225
+ if i == len (c .args ) && c .methodType .IsVariadic () {
226
+ if ! c .args [i ].Matches (args [i :]) && ! (len (c .args ) == len (args ) && c .args [i ].Matches (args [i ])) {
227
+ return fmt .Errorf ("Expected call at %s doesn't match the argument at index %s.\n Got: %v\n Want: %v\n " ,
228
+ c .origin , strconv .Itoa (i ), args [i :], c .args [i ])
229
+ }
230
+ break
231
+ }
206
232
if ! m .Matches (args [i ]) {
207
233
return fmt .Errorf ("Expected call at %s doesn't match the argument at index %s.\n Got: %v\n Want: %v\n " ,
208
234
c .origin , strconv .Itoa (i ), args [i ], m )
0 commit comments