@@ -29,6 +29,7 @@ type Call struct {
29
29
methodType reflect.Type // the type of the method
30
30
args []Matcher // the args
31
31
rets []interface {} // the return values (if any)
32
+ origin string // file and line number of call setup
32
33
33
34
preReqs []* Call // prerequisite calls
34
35
@@ -79,8 +80,8 @@ func (c *Call) Do(f interface{}) *Call {
79
80
func (c * Call ) Return (rets ... interface {}) * Call {
80
81
mt := c .methodType
81
82
if len (rets ) != mt .NumOut () {
82
- c .t .Fatalf ("wrong number of arguments to Return for %T.%v: got %d, want %d" ,
83
- c .receiver , c .method , len (rets ), mt .NumOut ())
83
+ c .t .Fatalf ("wrong number of arguments to Return for %T.%v: got %d, want %d [%s] " ,
84
+ c .receiver , c .method , len (rets ), mt .NumOut (), c . origin )
84
85
}
85
86
for i , ret := range rets {
86
87
if got , want := reflect .TypeOf (ret ), mt .Out (i ); got == want {
@@ -91,8 +92,8 @@ func (c *Call) Return(rets ...interface{}) *Call {
91
92
case reflect .Chan , reflect .Func , reflect .Interface , reflect .Map , reflect .Ptr , reflect .Slice :
92
93
// ok
93
94
default :
94
- c .t .Fatalf ("argument %d to Return for %T.%v is nil, but %v is not nillable" ,
95
- i , c .receiver , c .method , want )
95
+ c .t .Fatalf ("argument %d to Return for %T.%v is nil, but %v is not nillable [%s] " ,
96
+ i , c .receiver , c .method , want , c . origin )
96
97
}
97
98
} else if got .AssignableTo (want ) {
98
99
// Assignable type relation. Make the assignment now so that the generated code
@@ -101,8 +102,8 @@ func (c *Call) Return(rets ...interface{}) *Call {
101
102
v .Set (reflect .ValueOf (ret ))
102
103
rets [i ] = v .Interface ()
103
104
} else {
104
- c .t .Fatalf ("wrong type of argument %d to Return for %T.%v: %v is not assignable to %v" ,
105
- i , c .receiver , c .method , got , want )
105
+ c .t .Fatalf ("wrong type of argument %d to Return for %T.%v: %v is not assignable to %v [%s] " ,
106
+ i , c .receiver , c .method , got , want , c . origin )
106
107
}
107
108
}
108
109
@@ -125,7 +126,8 @@ func (c *Call) SetArg(n int, value interface{}) *Call {
125
126
// TODO: This will break on variadic methods.
126
127
// We will need to check those at invocation time.
127
128
if n < 0 || n >= mt .NumIn () {
128
- c .t .Fatalf ("SetArg(%d, ...) called for a method with %d args" , n , mt .NumIn ())
129
+ c .t .Fatalf ("SetArg(%d, ...) called for a method with %d args [%s]" ,
130
+ n , mt .NumIn (), c .origin )
129
131
}
130
132
// Permit setting argument through an interface.
131
133
// In the interface case, we don't (nay, can't) check the type here.
@@ -134,12 +136,14 @@ func (c *Call) SetArg(n int, value interface{}) *Call {
134
136
case reflect .Ptr :
135
137
dt := at .Elem ()
136
138
if vt := reflect .TypeOf (value ); ! vt .AssignableTo (dt ) {
137
- c .t .Fatalf ("SetArg(%d, ...) argument is a %v, not assignable to %v" , n , vt , dt )
139
+ c .t .Fatalf ("SetArg(%d, ...) argument is a %v, not assignable to %v [%s]" ,
140
+ n , vt , dt , c .origin )
138
141
}
139
142
case reflect .Interface :
140
143
// nothing to do
141
144
default :
142
- c .t .Fatalf ("SetArg(%d, ...) referring to argument of non-pointer non-interface type %v" , n , at )
145
+ c .t .Fatalf ("SetArg(%d, ...) referring to argument of non-pointer non-interface type %v [%s]" ,
146
+ n , at , c .origin )
143
147
}
144
148
c .setArgs [n ] = reflect .ValueOf (value )
145
149
return c
@@ -184,7 +188,7 @@ func (c *Call) String() string {
184
188
args [i ] = arg .String ()
185
189
}
186
190
arguments := strings .Join (args , ", " )
187
- return fmt .Sprintf ("%T.%v(%s)" , c .receiver , c .method , arguments )
191
+ return fmt .Sprintf ("%T.%v(%s) [%s] " , c .receiver , c .method , arguments , c . origin )
188
192
}
189
193
190
194
// Tests if the given call matches the expected call.
0 commit comments