Skip to content

Commit

Permalink
Preserve stack frame for mock parent method call
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Tai authored and georgelesica-wf committed Jan 3, 2019
1 parent 26d4a37 commit f1df803
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions mock/mock.go
Expand Up @@ -176,6 +176,7 @@ func (c *Call) Maybe() *Call {
// Mock.
// On("MyMethod", 1).Return(nil).
// On("MyOtherMethod", 'a', 'b', 'c').Return(errors.New("Some Error"))
//go:noinline
func (c *Call) On(methodName string, arguments ...interface{}) *Call {
return c.Parent.On(methodName, arguments...)
}
Expand Down
2 changes: 2 additions & 0 deletions mock/mock_test.go
Expand Up @@ -32,6 +32,7 @@ func (i *TestExampleImplementation) TheExampleMethod(a, b, c int) (int, error) {
return args.Int(0), errors.New("Whoops")
}

//go:noinline
func (i *TestExampleImplementation) TheExampleMethod2(yesorno bool) {
i.Called(yesorno)
}
Expand Down Expand Up @@ -1492,6 +1493,7 @@ func unexpectedCallRegex(method, calledArg, expectedArg, diff string) string {
rMethod, calledArg, rMethod, expectedArg, diff)
}

//go:noinline
func ConcurrencyTestMethod(m *Mock) {
m.Called()
}

0 comments on commit f1df803

Please sign in to comment.