Skip to content

Commit f1df803

Browse files
Taigeorgelesica-wf
Tai
authored andcommitted
Preserve stack frame for mock parent method call
Go tip contains following commmit, that inlines function with single call bodies. golang/go@13baf4b `(*Call).On()` is the exact target for the improvement in Go repo. Due to the inlining, assert.CallerInfo() can't not detect the file and line number of the call to `(*Mock).On()` from `(*Call).On()`. Thus, the test fails. Adding the compiler directive `go:noinline` prevent this effect and make mock package works with go tip as before.
1 parent 26d4a37 commit f1df803

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

mock/mock.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ func (c *Call) Maybe() *Call {
176176
// Mock.
177177
// On("MyMethod", 1).Return(nil).
178178
// On("MyOtherMethod", 'a', 'b', 'c').Return(errors.New("Some Error"))
179+
//go:noinline
179180
func (c *Call) On(methodName string, arguments ...interface{}) *Call {
180181
return c.Parent.On(methodName, arguments...)
181182
}

mock/mock_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func (i *TestExampleImplementation) TheExampleMethod(a, b, c int) (int, error) {
3232
return args.Int(0), errors.New("Whoops")
3333
}
3434

35+
//go:noinline
3536
func (i *TestExampleImplementation) TheExampleMethod2(yesorno bool) {
3637
i.Called(yesorno)
3738
}
@@ -1492,6 +1493,7 @@ func unexpectedCallRegex(method, calledArg, expectedArg, diff string) string {
14921493
rMethod, calledArg, rMethod, expectedArg, diff)
14931494
}
14941495

1496+
//go:noinline
14951497
func ConcurrencyTestMethod(m *Mock) {
14961498
m.Called()
14971499
}

0 commit comments

Comments
 (0)