diff options
| author | Changkun Ou <hi@changkun.de> | 2021-09-27 11:37:56 +0200 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-11-16 14:42:36 +0000 |
| commit | 978ce7e252b0d6ff0a19f66206ed5f3eca281059 (patch) | |
| tree | 6a32a053f319b961fdbcdbe5f91686250b45d798 /src/testing/panic_test.go | |
| parent | 7c8c209b45ebe5c3d7979c44e53216f61e8b5f2a (diff) | |
| download | go-978ce7e252b0d6ff0a19f66206ed5f3eca281059.tar.xz | |
testing: reject calls to Run within Cleanup callbacks
Calling t.Run inside t.Cleanup can mess up the execution order of
registered Cleanup callbacks. Reject calls to Run within Cleanup
callbacks.
Fixes #48515
Change-Id: I61e4cb35253db1a8bbe3351d59055433030aa289
Reviewed-on: https://go-review.googlesource.com/c/go/+/352349
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joedian Reid <joedian@golang.org>
Run-TryBot: Changkun Ou <mail@changkun.de>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/testing/panic_test.go')
| -rw-r--r-- | src/testing/panic_test.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/testing/panic_test.go b/src/testing/panic_test.go index fafcff790e..4648057b77 100644 --- a/src/testing/panic_test.go +++ b/src/testing/panic_test.go @@ -224,6 +224,11 @@ func TestMorePanic(t *testing.T) { want: `panic: die panic: test executed panic(nil) or runtime.Goexit`, }, + { + desc: "Issue 48515: call t.Run in t.Cleanup should trigger panic", + flags: []string{"-test.run=TestCallRunInCleanupHelper"}, + want: `panic: testing: t.Run is called during t.Cleanup`, + }, } for _, tc := range testCases { @@ -239,6 +244,18 @@ func TestMorePanic(t *testing.T) { } } +func TestCallRunInCleanupHelper(t *testing.T) { + if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" { + return + } + + t.Cleanup(func() { + t.Run("in-cleanup", func(t *testing.T) { + t.Log("must not be executed") + }) + }) +} + func TestGoexitInCleanupAfterPanicHelper(t *testing.T) { if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" { return |
