@@ -7,6 +7,7 @@ type {{$mock}}{{(params)}} struct {
77
88 {{ range $method := $ .Interface.Methods }}
99 func{{$method .Name }} func{{ $method .Signature }}
10+ func{{$method .Name }}Origin string
1011 inspectFunc{{$method .Name }} func({{ $method .Params }})
1112 after{{$method .Name }}Counter uint64
1213 before{{$method .Name }}Counter uint64
@@ -45,15 +46,17 @@ func New{{$mock}}{{(params)}}(t minimock.Tester) *{{$mock}}{{(paramsRef)}} {
4546 {{ end }}
4647
4748 expectedInvocations uint64
49+ expectedInvocationsOrigin string
4850 }
4951
5052 // {{$mock }}{{$method .Name }}Expectation specifies expectation struct of the {{$ .Interface.Name }}. {{$method .Name }}
5153 type {{$mock }}{{$method .Name }}Expectation{{(params)}} struct {
5254 mock *{{$mock }}{{(paramsRef)}}
5355 {{ if $method .HasParams }} params *{{$mock }}{{$method .Name }}Params{{(paramsRef)}} {{end }}
5456 {{ if $method .HasParams }} paramPtrs *{{$mock }}{{$method .Name }}ParamPtrs{{(paramsRef)}} {{end }}
55- {{ if $method .HasParams }} origins {{$mock }}{{$method .Name }}Origins {{end }}
57+ {{ if $method .HasParams }} expectationOrigins {{$mock }}{{$method .Name }}ExpectationOrigins {{end }}
5658 {{ if $method .HasResults }} results *{{$mock }}{{$method .Name }}Results{{(paramsRef)}} {{end }}
59+ returnOrigin string
5760 Counter uint64
5861 }
5962
@@ -74,7 +77,7 @@ func New{{$mock}}{{(params)}}(t minimock.Tester) *{{$mock}}{{(paramsRef)}} {
7477
7578 {{if $method .HasParams }}
7679 // {{$mock }}{{$method .Name }}Origins contains origins of expectations of the {{$ .Interface.Name }}. {{$method .Name }}
77- type {{$mock }}{{$method .Name }}Origins struct {
80+ type {{$mock }}{{$method .Name }}ExpectationOrigins struct {
7881 origin string
7982 {{- range $param := $method .Params }}
8083 origin{{ $param .Name | title }} string
@@ -108,7 +111,7 @@ func New{{$mock}}{{(params)}}(t minimock.Tester) *{{$mock}}{{(paramsRef)}} {
108111 }
109112
110113 {{$m }}.defaultExpectation.params = &{{$mock }}{{$method .Name }}Params{{(paramsRef)}}{ {{ $method .ParamsNames }} }
111- {{$m }}.defaultExpectation.origins .origin = minimock.CallerInfo (1)
114+ {{$m }}.defaultExpectation.expectationOrigins .origin = minimock.CallerInfo (1)
112115 for _, e := range {{$m }}.expectations {
113116 if minimock.Equal (e.params , {{$m }}.defaultExpectation.params ) {
114117 {{$m }}.mock.t.Fatalf (" Expectation set by When has same params: %#v" , *{{$m }}.defaultExpectation.params )
@@ -137,7 +140,7 @@ func New{{$mock}}{{(params)}}(t minimock.Tester) *{{$mock}}{{(paramsRef)}} {
137140 {{$m }}.defaultExpectation.paramPtrs = &{{$mock }}{{$method .Name }}ParamPtrs{{(paramsRef)}}{}
138141 }
139142 {{$m }}.defaultExpectation.paramPtrs. {{$param .Name }} = &{{$param .Name }}
140- {{$m }}.defaultExpectation.origins .origin {{ $param .Name | title }} = minimock.CallerInfo (1)
143+ {{$m }}.defaultExpectation.expectationOrigins .origin {{ $param .Name | title }} = minimock.CallerInfo (1)
141144
142145 return {{$m }}
143146 }
@@ -163,6 +166,7 @@ func New{{$mock}}{{(params)}}(t minimock.Tester) *{{$mock}}{{(paramsRef)}} {
163166 {{$m }}.defaultExpectation = &{{$mock }}{{$method .Name }}Expectation{{(paramsRef)}}{mock: {{$m }}.mock }
164167 }
165168 {{if $method .HasResults }} {{$m }}.defaultExpectation.results = &{{$mock }}{{$method .Name }}Results{{(paramsRef)}}{ {{ $method .ResultsNames }} } {{end }}
169+ {{$m }}.defaultExpectation.returnOrigin = minimock.CallerInfo (1)
166170 return {{$m }}.mock
167171 }
168172
@@ -176,7 +180,8 @@ func New{{$mock}}{{(params)}}(t minimock.Tester) *{{$mock}}{{(paramsRef)}} {
176180 {{$m }}.mock.t.Fatalf (" Some expectations are already set for the {{$.Interface.Name}}.{{$method.Name}} method" )
177181 }
178182
179- {{$m }}.mock.func {{$method .Name }}= f
183+ {{$m }}.mock.func {{$method .Name }} = f
184+ {{$m }}.mock.func {{$method .Name }}Origin = minimock.CallerInfo (1)
180185 return {{$m }}.mock
181186 }
182187
@@ -191,7 +196,7 @@ func New{{$mock}}{{(params)}}(t minimock.Tester) *{{$mock}}{{(paramsRef)}} {
191196 expectation := &{{$mock }}{{$method .Name }}Expectation{{(paramsRef)}}{
192197 mock: {{$m }}.mock ,
193198 params: &{{$mock }}{{$method .Name }}Params{{(paramsRef)}}{ {{ $method .ParamsNames }} },
194- origins : {{$mock }}{{$method .Name }}Origins {origin: minimock.CallerInfo (1)},
199+ expectationOrigins : {{$mock }}{{$method .Name }}ExpectationOrigins {origin: minimock.CallerInfo (1)},
195200 }
196201 {{$m }}.expectations = append({{$m }}.expectations , expectation)
197202 return expectation
@@ -210,6 +215,7 @@ func New{{$mock}}{{(params)}}(t minimock.Tester) *{{$mock}}{{(paramsRef)}} {
210215 {{$m }}.mock.t.Fatalf (" Times of {{$mock}}.{{$method.Name}} mock can not be zero" )
211216 }
212217 mm_atomic.StoreUint64 (&{{$m }}.expectedInvocations , n)
218+ {{$m }}.expectedInvocationsOrigin = minimock.CallerInfo (1)
213219 return {{$m }}
214220 }
215221
@@ -229,9 +235,7 @@ func New{{$mock}}{{(params)}}(t minimock.Tester) *{{$mock}}{{(paramsRef)}} {
229235 mm_atomic.AddUint64 (&{{$m }}.before {{$method .Name }}Counter, 1)
230236 defer mm_atomic.AddUint64 (&{{$m }}.after {{$method .Name }}Counter, 1)
231237
232- if helper, ok := {{$m }}.t. (interface{ Helper() }); ok {
233- helper.Helper ()
234- }
238+ {{$m }}.t.Helper ()
235239
236240 if {{$m }}.inspectFunc {{$method .Name }} != nil {
237241 {{$m }}.inspectFunc {{$method .Name }}({{$method .Params.Pass }})
@@ -264,13 +268,13 @@ func New{{$mock}}{{(params)}}(t minimock.Tester) *{{$mock}}{{(paramsRef)}} {
264268 if mm_want_ptrs != nil {
265269 {{ range $idx , $param := $method .Params }}
266270 if mm_want_ptrs. {{$param .Name }} != nil && !minimock.Equal (*mm_want_ptrs. {{$param .Name }}, mm_got. {{$param .Name }}) {
267- {{$m }}.t.Errorf (" {{$mock}}.{{$method.Name}} got unexpected parameter {{$param.Name}} expected at\n %s :\n want: %#v\n got: %#v%s \n " ,
268- {{$m }}. {{$method .Name }}Mock.defaultExpectation.origins .origin {{$param .Name | title}}, *mm_want_ptrs. {{$param .Name }}, mm_got. {{$param .Name }}, minimock.Diff (*mm_want_ptrs. {{$param .Name }}, mm_got. {{$param .Name }}))
271+ {{$m }}.t.Errorf (" {{$mock}}.{{$method.Name}} got unexpected parameter {{$param.Name}}, expected at\n %s :\n want: %#v\n got: %#v%s \n " ,
272+ {{$m }}. {{$method .Name }}Mock.defaultExpectation.expectationOrigins .origin {{$param .Name | title}}, *mm_want_ptrs. {{$param .Name }}, mm_got. {{$param .Name }}, minimock.Diff (*mm_want_ptrs. {{$param .Name }}, mm_got. {{$param .Name }}))
269273 }
270274 {{ end }}
271275 } else if mm_want != nil && !minimock.Equal (*mm_want, mm_got) {
272- {{$m }}.t.Errorf (" {{$mock}}.{{$method.Name}} got unexpected parameters expected at\n %s :\n want: %#v\n got: %#v%s \n " ,
273- {{$m }}. {{$method .Name }}Mock.defaultExpectation.origins .origin , *mm_want, mm_got, minimock.Diff (*mm_want, mm_got))
276+ {{$m }}.t.Errorf (" {{$mock}}.{{$method.Name}} got unexpected parameters, expected at\n %s :\n want: %#v\n got: %#v%s \n " ,
277+ {{$m }}. {{$method .Name }}Mock.defaultExpectation.expectationOrigins .origin , *mm_want, mm_got, minimock.Diff (*mm_want, mm_got))
274278 }
275279 {{ end }}
276280 {{if $method .HasResults }}
@@ -337,7 +341,7 @@ func New{{$mock}}{{(params)}}(t minimock.Tester) *{{$mock}}{{(paramsRef)}} {
337341 for _, e := range m. {{$method .Name }}Mock.expectations {
338342 if mm_atomic.LoadUint64 (&e.Counter ) < 1 {
339343 {{- if $method .HasParams }}
340- m.t.Errorf (" Expected call to {{$mock}}.{{$method.Name}} with params: %#v" , *e.params )
344+ m.t.Errorf (" Expected call to {{$mock}}.{{$method.Name}} at \n %s with params: %#v" , e .expectationOrigins.origin , *e.params )
341345 {{else }}
342346 m.t.Error (" Expected call to {{$mock}}.{{$method.Name}}" )
343347 {{end -}}
@@ -349,22 +353,22 @@ func New{{$mock}}{{(params)}}(t minimock.Tester) *{{$mock}}{{(paramsRef)}} {
349353 if m. {{$method .Name }}Mock.defaultExpectation != nil && after{{$method .Name }}Counter < 1 {
350354 {{- if $method .HasParams }}
351355 if m. {{$method .Name }}Mock.defaultExpectation.params == nil {
352- m.t.Error (" Expected call to {{$mock}}.{{$method.Name}}" )
356+ m.t.Errorf (" Expected call to {{$mock}}.{{$method.Name}} at \n %s " , m . {{ $method .Name }}Mock .defaultExpectation.returnOrigin )
353357 } else {
354- m.t.Errorf (" Expected call to {{$mock}}.{{$method.Name}} with params: %#v" , *m. {{$method .Name }}Mock.defaultExpectation.params )
358+ m.t.Errorf (" Expected call to {{$mock}}.{{$method.Name}} at \n %s with params: %#v" , m . {{ $method .Name }}Mock .defaultExpectation.expectationOrigins.origin , *m. {{$method .Name }}Mock.defaultExpectation.params )
355359 }
356360 {{else }}
357- m.t.Error (" Expected call to {{$mock}}.{{$method.Name}}" )
361+ m.t.Errorf (" Expected call to {{$mock}}.{{$method.Name}} at \n %s " , m . {{ $method .Name }}Mock .defaultExpectation.returnOrigin )
358362 {{end -}}
359363 }
360364 // if func was set then invocations count should be greater than zero
361365 if m.func {{$method .Name }} != nil && after{{$method .Name }}Counter < 1 {
362- m.t.Error (" Expected call to {{$mock}}.{{$method.Name}}" )
366+ m.t.Errorf (" Expected call to {{$mock}}.{{$method.Name}} at \n %s " , m .func {{ $method .Name }}Origin )
363367 }
364368
365369 if !m. {{$method .Name }}Mock.invocationsDone () && after{{$method .Name }}Counter > 0 {
366- m.t.Errorf (" Expected %d calls to {{$mock}}.{{$method.Name}} but found %d calls" ,
367- mm_atomic.LoadUint64 (&m. {{$method .Name }}Mock.expectedInvocations ), after{{$method .Name }}Counter)
370+ m.t.Errorf (" Expected %d calls to {{$mock}}.{{$method.Name}} at \n %s but found %d calls" ,
371+ mm_atomic.LoadUint64 (&m. {{$method .Name }}Mock.expectedInvocations ), m . {{ $method .Name }}Mock .expectedInvocationsOrigin , after{{$method .Name }}Counter)
368372 }
369373 }
370374{{end }}
0 commit comments