diff --git a/leaks.go b/leaks.go index 41754e9..ee122b7 100644 --- a/leaks.go +++ b/leaks.go @@ -84,14 +84,14 @@ type testHelper interface { // defer VerifyNone(t) func VerifyNone(t TestingT, options ...Option) { opts := buildOpts(options...) - cleanup := opts.cleanup + var cleanup func(int) + cleanup, opts.cleanup = opts.cleanup, nil + if h, ok := t.(testHelper); ok { // Mark this function as a test helper, if available. h.Helper() } - // Find does not appreciate cleanups - opts.cleanup = nil if err := Find(opts); err != nil { t.Error(err) } diff --git a/testmain.go b/testmain.go index 8652b39..7b1a50b 100644 --- a/testmain.go +++ b/testmain.go @@ -52,13 +52,12 @@ type TestingM interface { func VerifyTestMain(m TestingM, options ...Option) { exitCode := m.Run() opts := buildOpts(options...) + var cleanup func(int) cleanup, opts.cleanup = opts.cleanup, nil - if cleanup == nil { cleanup = _osExit } - defer func() { cleanup(exitCode) }() if exitCode == 0 {