runtime: don't let the tests leave core files behind

Also add a check that we didn't leave any core files behind.

Change-Id: I30444ef43ad1a8cc1cacd3b75280f2128e104939
Reviewed-on: https://go-review.googlesource.com/c/go/+/525175
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Ian Lance Taylor 2023-09-01 12:52:48 -07:00 committed by Gopher Robot
parent a819178915
commit cffdfe8d2c
3 changed files with 16 additions and 1 deletions

View file

@ -24,10 +24,21 @@ import (
var toRemove []string
func TestMain(m *testing.M) {
_, coreErrBefore := os.Stat("core")
status := m.Run()
for _, file := range toRemove {
os.RemoveAll(file)
}
_, coreErrAfter := os.Stat("core")
if coreErrBefore != nil && coreErrAfter == nil {
fmt.Fprintln(os.Stderr, "runtime.test: some test left a core file behind")
if status == 0 {
status = 1
}
}
os.Exit(status)
}