aboutsummaryrefslogtreecommitdiff
path: root/src/testing/panic_test.go
diff options
context:
space:
mode:
authorChangkun Ou <hi@changkun.de>2021-09-27 12:06:43 +0200
committerGopher Robot <gobot@golang.org>2022-11-14 17:37:45 +0000
commita650e399dfc2435eb18efc430a70cba9d87cec73 (patch)
tree1f55e0e95ab9251e69897f891fec6f3ed9162835 /src/testing/panic_test.go
parentea4631cc0cf301c824bd665a7980c13289ab5c9d (diff)
downloadgo-a650e399dfc2435eb18efc430a70cba9d87cec73.tar.xz
testing: fix error message when a parallel Cleanup calls runtime.Goexit
Fixes #48502 Change-Id: I6054b043ebd2237e19897fdf1234b311d19facc7 Reviewed-on: https://go-review.googlesource.com/c/go/+/352350 Reviewed-by: Joedian Reid <joedian@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Changkun Ou <mail@changkun.de> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/testing/panic_test.go')
-rw-r--r--src/testing/panic_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/testing/panic_test.go b/src/testing/panic_test.go
index 6b8b95391d..fafcff790e 100644
--- a/src/testing/panic_test.go
+++ b/src/testing/panic_test.go
@@ -11,6 +11,7 @@ import (
"os"
"os/exec"
"regexp"
+ "runtime"
"strings"
"testing"
)
@@ -208,3 +209,42 @@ func TestPanicHelper(t *testing.T) {
})
}
}
+
+func TestMorePanic(t *testing.T) {
+ testenv.MustHaveExec(t)
+
+ testCases := []struct {
+ desc string
+ flags []string
+ want string
+ }{
+ {
+ desc: "Issue 48502: call runtime.Goexit in t.Cleanup after panic",
+ flags: []string{"-test.run=TestGoexitInCleanupAfterPanicHelper"},
+ want: `panic: die
+ panic: test executed panic(nil) or runtime.Goexit`,
+ },
+ }
+
+ for _, tc := range testCases {
+ cmd := exec.Command(os.Args[0], tc.flags...)
+ cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
+ b, _ := cmd.CombinedOutput()
+ got := string(b)
+ want := tc.want
+ re := makeRegexp(want)
+ if ok, err := regexp.MatchString(re, got); !ok || err != nil {
+ t.Errorf("output:\ngot:\n%s\nwant:\n%s", got, want)
+ }
+ }
+}
+
+func TestGoexitInCleanupAfterPanicHelper(t *testing.T) {
+ if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
+ return
+ }
+
+ t.Cleanup(func() { runtime.Goexit() })
+ t.Parallel()
+ panic("die")
+}