diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-08-26 17:26:05 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-08-27 23:19:15 +0000 |
commit | 4f76fe86756841befb6574ce4bf04113d14389d4 (patch) | |
tree | 7c99448c043961b189d1c05a7b63d4b411b8acf3 /src/testing/testing.go | |
parent | cdc635547fc436dc49c91ddb172b0e101febd3d7 (diff) | |
download | go-4f76fe86756841befb6574ce4bf04113d14389d4.tar.gz go-4f76fe86756841befb6574ce4bf04113d14389d4.zip |
cmd/go, testing, os: fail test that calls os.Exit(0)
This catches cases where a test calls code that calls os.Exit(0),
thereby skipping all subsequent tests.
Fixes #29062
Change-Id: If9478972f40189e27623557e7141469ca4234d89
Reviewed-on: https://go-review.googlesource.com/c/go/+/250977
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/testing/testing.go')
-rw-r--r-- | src/testing/testing.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go index bf83df8863..d0334243f4 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -294,6 +294,7 @@ func Init() { blockProfileRate = flag.Int("test.blockprofilerate", 1, "set blocking profile `rate` (see runtime.SetBlockProfileRate)") mutexProfile = flag.String("test.mutexprofile", "", "write a mutex contention profile to the named file after execution") mutexProfileFraction = flag.Int("test.mutexprofilefraction", 1, "if >= 0, calls runtime.SetMutexProfileFraction()") + panicOnExit0 = flag.Bool("test.paniconexit0", false, "panic on call to os.Exit(0)") traceFile = flag.String("test.trace", "", "write an execution trace to `file`") timeout = flag.Duration("test.timeout", 0, "panic test binary after duration `d` (default 0, timeout disabled)") cpuListStr = flag.String("test.cpu", "", "comma-separated `list` of cpu counts to run each test with") @@ -320,6 +321,7 @@ var ( blockProfileRate *int mutexProfile *string mutexProfileFraction *int + panicOnExit0 *bool traceFile *string timeout *time.Duration cpuListStr *string @@ -1261,6 +1263,7 @@ func (f matchStringOnly) WriteProfileTo(string, io.Writer, int) error { return e func (f matchStringOnly) ImportPath() string { return "" } func (f matchStringOnly) StartTestLog(io.Writer) {} func (f matchStringOnly) StopTestLog() error { return errMain } +func (f matchStringOnly) SetPanicOnExit0(bool) {} // Main is an internal function, part of the implementation of the "go test" command. // It was exported because it is cross-package and predates "internal" packages. @@ -1296,6 +1299,7 @@ type M struct { type testDeps interface { ImportPath() string MatchString(pat, str string) (bool, error) + SetPanicOnExit0(bool) StartCPUProfile(io.Writer) error StopCPUProfile() StartTestLog(io.Writer) @@ -1521,11 +1525,17 @@ func (m *M) before() { m.deps.StartTestLog(f) testlogFile = f } + if *panicOnExit0 { + m.deps.SetPanicOnExit0(true) + } } // after runs after all testing. func (m *M) after() { m.afterOnce.Do(func() { + if *panicOnExit0 { + m.deps.SetPanicOnExit0(false) + } m.writeProfiles() }) } |