You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently TestMain is expected to call os.Exit itself, but that means it's
not possible to use defer to do package-wide test cleanup there,
because the defer will never be called.
I propose that TestMain be optionally allowed to return an integer,
in which case os.Exit will be called with its result.
Then we can write:
func TestMain(m *testing.M) int {
defer testhelper.Cleanup()
return m.Run()
}
which is arguably more natural and harder to get wrong than calling os.Exit.
The text was updated successfully, but these errors were encountered:
I understand that this is more verbose, but I'm wondering if that offsets adding extra code and documentation to the testing package. I would definitely agree with you if the testing package was designed from the ground up, however. Unless there is a specific reason for os.Exit that we are both missing.
@OneOfOne what is your point? The integer that you can use in an os.Exit call is the same integer that @rogpeppe suggests to have as a return parameter. See my silly workaround above as an example.
Currently TestMain is expected to call os.Exit itself, but that means it's
not possible to use defer to do package-wide test cleanup there,
because the defer will never be called.
I propose that TestMain be optionally allowed to return an integer,
in which case os.Exit will be called with its result.
Then we can write:
which is arguably more natural and harder to get wrong than calling os.Exit.
The text was updated successfully, but these errors were encountered: