Skip to content

Commit

Permalink
testing: restore os.Exit(0) after every call to (*M).Run
Browse files Browse the repository at this point in the history
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 <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
Bryan C. Mills committed Aug 28, 2020
1 parent 26ad27b commit 18ea6f5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 18ea6f5

Please sign in to comment.