From: Bryan C. Mills Date: Fri, 28 Aug 2020 01:30:24 +0000 (-0400) Subject: testing: restore os.Exit(0) after every call to (*M).Run X-Git-Tag: go1.16beta1~1172 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=18ea6f597c031d5f3c5160217db72d80cb62f689;p=gostls13.git testing: restore os.Exit(0) after every call to (*M).Run cmd/go.TestScript/test_main_twice demonstrates a program that invokes (*M).Run twice in a row. If we only restore os.Exit(0) in m.afterOnce, we will fail to restore it after the second run and fail the test process despite both runs passing. Updates #29062 Updates #23129 Change-Id: Id22ec68f1708e4583c8dda14a8ba0efae7178b85 Reviewed-on: https://go-review.googlesource.com/c/go/+/251262 Run-TryBot: Bryan C. Mills Reviewed-by: Ian Lance Taylor TryBot-Result: Gobot Gobot --- diff --git a/src/testing/testing.go b/src/testing/testing.go index d0334243f4..01743969ee 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -1533,11 +1533,15 @@ func (m *M) before() { // after runs after all testing. func (m *M) after() { m.afterOnce.Do(func() { - if *panicOnExit0 { - m.deps.SetPanicOnExit0(false) - } m.writeProfiles() }) + + // Restore PanicOnExit0 after every run, because we set it to true before + // every run. Otherwise, if m.Run is called multiple times the behavior of + // os.Exit(0) will not be restored after the second run. + if *panicOnExit0 { + m.deps.SetPanicOnExit0(false) + } } func (m *M) writeProfiles() {