@@ -17,6 +17,7 @@ package gomock
17
17
import (
18
18
"fmt"
19
19
"reflect"
20
+ "runtime/debug"
20
21
"strconv"
21
22
"strings"
22
23
)
@@ -81,8 +82,8 @@ func (c *Call) Do(f interface{}) *Call {
81
82
func (c * Call ) Return (rets ... interface {}) * Call {
82
83
mt := c .methodType
83
84
if len (rets ) != mt .NumOut () {
84
- c .t .Fatalf ("wrong number of arguments to Return for %T.%v: got %d, want %d [%s] " ,
85
- c .receiver , c .method , len (rets ), mt .NumOut (), c . origin )
85
+ c .t .Fatalf ("wrong number of arguments to Return for %T.%v: got %d, want %d\n %s " ,
86
+ c .receiver , c .method , len (rets ), mt .NumOut (), debug . Stack () )
86
87
}
87
88
for i , ret := range rets {
88
89
if got , want := reflect .TypeOf (ret ), mt .Out (i ); got == want {
@@ -93,8 +94,8 @@ func (c *Call) Return(rets ...interface{}) *Call {
93
94
case reflect .Chan , reflect .Func , reflect .Interface , reflect .Map , reflect .Ptr , reflect .Slice :
94
95
// ok
95
96
default :
96
- c .t .Fatalf ("argument %d to Return for %T.%v is nil, but %v is not nillable [%s] " ,
97
- i , c .receiver , c .method , want , c . origin )
97
+ c .t .Fatalf ("argument %d to Return for %T.%v is nil, but %v is not nillable\n %s " ,
98
+ i , c .receiver , c .method , want , debug . Stack () )
98
99
}
99
100
} else if got .AssignableTo (want ) {
100
101
// Assignable type relation. Make the assignment now so that the generated code
@@ -103,8 +104,8 @@ func (c *Call) Return(rets ...interface{}) *Call {
103
104
v .Set (reflect .ValueOf (ret ))
104
105
rets [i ] = v .Interface ()
105
106
} else {
106
- c .t .Fatalf ("wrong type of argument %d to Return for %T.%v: %v is not assignable to %v [%s] " ,
107
- i , c .receiver , c .method , got , want , c . origin )
107
+ c .t .Fatalf ("wrong type of argument %d to Return for %T.%v: %v is not assignable to %v\n %s " ,
108
+ i , c .receiver , c .method , got , want , debug . Stack () )
108
109
}
109
110
}
110
111
@@ -128,8 +129,7 @@ func (c *Call) SetArg(n int, value interface{}) *Call {
128
129
// TODO: This will break on variadic methods.
129
130
// We will need to check those at invocation time.
130
131
if n < 0 || n >= mt .NumIn () {
131
- c .t .Fatalf ("SetArg(%d, ...) called for a method with %d args [%s]" ,
132
- n , mt .NumIn (), c .origin )
132
+ c .t .Fatalf ("SetArg(%d, ...) called for a method with %d args\n %s" , n , mt .NumIn (), debug .Stack ())
133
133
}
134
134
// Permit setting argument through an interface.
135
135
// In the interface case, we don't (nay, can't) check the type here.
@@ -138,16 +138,14 @@ func (c *Call) SetArg(n int, value interface{}) *Call {
138
138
case reflect .Ptr :
139
139
dt := at .Elem ()
140
140
if vt := reflect .TypeOf (value ); ! vt .AssignableTo (dt ) {
141
- c .t .Fatalf ("SetArg(%d, ...) argument is a %v, not assignable to %v [%s]" ,
142
- n , vt , dt , c .origin )
141
+ c .t .Fatalf ("SetArg(%d, ...) argument is a %v, not assignable to %v\n %s" , n , vt , dt , debug .Stack ())
143
142
}
144
143
case reflect .Interface :
145
144
// nothing to do
146
145
case reflect .Slice :
147
146
// nothing to do
148
147
default :
149
- c .t .Fatalf ("SetArg(%d, ...) referring to argument of non-pointer non-interface non-slice type %v" ,
150
- n , at , c .origin )
148
+ c .t .Fatalf ("SetArg(%d, ...) referring to argument of non-pointer non-interface type %v\n %s" , n , at , debug .Stack ())
151
149
}
152
150
c .setArgs [n ] = reflect .ValueOf (value )
153
151
return c
@@ -166,7 +164,7 @@ func (c *Call) isPreReq(other *Call) bool {
166
164
// After declares that the call may only match after preReq has been exhausted.
167
165
func (c * Call ) After (preReq * Call ) * Call {
168
166
if c == preReq {
169
- c .t .Fatalf ("A call isn't allowed to be its own prerequisite" )
167
+ c .t .Fatalf ("A call isn't allowed to be its own prerequisite\n %s" , debug . Stack () )
170
168
}
171
169
if preReq .isPreReq (c ) {
172
170
c .t .Fatalf ("Loop in call order: %v is a prerequisite to %v (possibly indirectly)." , c , preReq )
0 commit comments