@@ -159,14 +159,17 @@ func (c *Call) Do(f interface{}) *Call {
159
159
160
160
// Return declares the values to be returned by the mocked function call.
161
161
func (c * Call ) Return (rets ... interface {}) * Call {
162
+ skipFrames := 1
163
+
162
164
if h , ok := c .t .(testHelper ); ok {
163
165
h .Helper ()
164
166
}
165
167
166
168
mt := c .methodType
167
169
if len (rets ) != mt .NumOut () {
168
- c .t .Fatalf ("wrong number of arguments to Return for %T.%v: got %d, want %d [%s]" ,
169
- c .receiver , c .method , len (rets ), mt .NumOut (), c .origin )
170
+ stackTraceStr := "\n \n " + currentStackTrace (skipFrames )
171
+ c .t .Fatalf ("wrong number of arguments to Return for %T.%v: got %d, want %d [%s]%+v" ,
172
+ c .receiver , c .method , len (rets ), mt .NumOut (), c .origin , stackTraceStr )
170
173
}
171
174
for i , ret := range rets {
172
175
if got , want := reflect .TypeOf (ret ), mt .Out (i ); got == want {
@@ -177,8 +180,9 @@ func (c *Call) Return(rets ...interface{}) *Call {
177
180
case reflect .Chan , reflect .Func , reflect .Interface , reflect .Map , reflect .Ptr , reflect .Slice :
178
181
// ok
179
182
default :
180
- c .t .Fatalf ("argument %d to Return for %T.%v is nil, but %v is not nillable [%s]" ,
181
- i , c .receiver , c .method , want , c .origin )
183
+ stackTraceStr := "\n \n " + currentStackTrace (skipFrames )
184
+ c .t .Fatalf ("argument %d to Return for %T.%v is nil, but %v is not nillable [%s]%+v" ,
185
+ i , c .receiver , c .method , want , c .origin , stackTraceStr )
182
186
}
183
187
} else if got .AssignableTo (want ) {
184
188
// Assignable type relation. Make the assignment now so that the generated code
@@ -187,8 +191,10 @@ func (c *Call) Return(rets ...interface{}) *Call {
187
191
v .Set (reflect .ValueOf (ret ))
188
192
rets [i ] = v .Interface ()
189
193
} else {
190
- c .t .Fatalf ("wrong type of argument %d to Return for %T.%v: %v is not assignable to %v [%s]" ,
191
- i , c .receiver , c .method , got , want , c .origin )
194
+ skipFrames := 1
195
+ stackTraceStr := "\n \n " + currentStackTrace (skipFrames )
196
+ c .t .Fatalf ("wrong type of argument %d to Return for %T.%v: %v is not assignable to %v [%s]%+v" ,
197
+ i , c .receiver , c .method , got , want , c .origin , stackTraceStr )
192
198
}
193
199
}
194
200
@@ -209,6 +215,8 @@ func (c *Call) Times(n int) *Call {
209
215
// indirected through a pointer. Or, in the case of a slice, SetArg
210
216
// will copy value's elements into the nth argument.
211
217
func (c * Call ) SetArg (n int , value interface {}) * Call {
218
+ skipFrames := 1
219
+
212
220
if h , ok := c .t .(testHelper ); ok {
213
221
h .Helper ()
214
222
}
@@ -217,8 +225,9 @@ func (c *Call) SetArg(n int, value interface{}) *Call {
217
225
// TODO: This will break on variadic methods.
218
226
// We will need to check those at invocation time.
219
227
if n < 0 || n >= mt .NumIn () {
220
- c .t .Fatalf ("SetArg(%d, ...) called for a method with %d args [%s]" ,
221
- n , mt .NumIn (), c .origin )
228
+ stackTraceStr := "\n \n " + currentStackTrace (skipFrames )
229
+ c .t .Fatalf ("SetArg(%d, ...) called for a method with %d args [%s]%+v" ,
230
+ n , mt .NumIn (), c .origin , stackTraceStr )
222
231
}
223
232
// Permit setting argument through an interface.
224
233
// In the interface case, we don't (nay, can't) check the type here.
@@ -227,16 +236,18 @@ func (c *Call) SetArg(n int, value interface{}) *Call {
227
236
case reflect .Ptr :
228
237
dt := at .Elem ()
229
238
if vt := reflect .TypeOf (value ); ! vt .AssignableTo (dt ) {
230
- c .t .Fatalf ("SetArg(%d, ...) argument is a %v, not assignable to %v [%s]" ,
231
- n , vt , dt , c .origin )
239
+ stackTraceStr := "\n \n " + currentStackTrace (skipFrames )
240
+ c .t .Fatalf ("SetArg(%d, ...) argument is a %v, not assignable to %v [%s]%+v" ,
241
+ n , vt , dt , c .origin , stackTraceStr )
232
242
}
233
243
case reflect .Interface :
234
244
// nothing to do
235
245
case reflect .Slice :
236
246
// nothing to do
237
247
default :
238
- c .t .Fatalf ("SetArg(%d, ...) referring to argument of non-pointer non-interface non-slice type %v [%s]" ,
239
- n , at , c .origin )
248
+ stackTraceStr := "\n \n " + currentStackTrace (skipFrames )
249
+ c .t .Fatalf ("SetArg(%d, ...) referring to argument of non-pointer non-interface non-slice type %v [%s]%+v" ,
250
+ n , at , c .origin , stackTraceStr )
240
251
}
241
252
242
253
c .addAction (func (args []interface {}) []interface {} {
0 commit comments