-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Catch panics in the cleanup #91
Comments
The issue was introduced in v3.3.0 after adding Only workaround I've found for previous versions it's not to call c.Finish in defer and don't use t.Cleanup either, the only option to avoid such "debugging surprises" I know is always explicitly call of Finish method at the end of the test. |
Hi! This happens because when expected call is not called, then FailNow is called https://github.com/gojuno/minimock/blob/master/template.go#L353 which suppresses panic output. @hexdigest do we really need to call FailNow here? |
Hey @genesor It's not the responsibility of minimock to handle panics in your code. In fact it's not even possible because in order for the minimock to output information about the panic the panic needs to be recovered somewhere within minimock code but since it's not the minimock that's panicking it can't be caught there. Here is the example of how panic in your code can be handled within your test: func TestStringer(t *testing.T) {
mc := minimock.NewController(t)
mock := NewStringerMock(mc)
mock.StringMock.Return("Hello, World!")
defer func() {
if err := recover(); err != nil {
t.Error(err)
}
}()
panic("panic is good for you")
} Output:
|
Sorry, but problem is not "minimock doesn't catch panics", but "minimock hides panics" (after 3.3.0). Code that illustrates the problem: gist:
Output after 3.3.0:
Output before 3.3.0:
reasons I always call mc.Finish at the end of my tests with minimock (and don't upgrade to 3.3.0+) are:
You can play with code from above here: #91 (comment) |
Hey @hexdigest Thanks for the reply even if I don't agree with you. As you know people are using I totally agree with you with "It's not the responsibility of minimock to handle panics in your code" no debate in this but minimock should not HIDE panics in my code either. Currently with the I'm not asking for minimock to hide or even catch a panic as I know it's not possible, I just want minimock to avoid hiding panics when they occur and let the I tested locally by changing EDIT: I might understand that my original issue was not correctly worded, sorry about that |
Hey guys, fix is available in v3.3.12 , thanks to everyone |
Hi,
Currently if a panic happens before all expected calls to mocks are made the panic output is not shown in the test output, there is only the missing expected calls.
Do you think it's possible to output both the missing expected calls and the panic ?
The text was updated successfully, but these errors were encountered: