1 # For issue 41355
2 [short] skip
3
4 # This test could fail if the testing package does not wait until
5 # a panicking test does the panic. Turn off multithreading and GC
6 # to increase the probability of such a failure.
7 env GOMAXPROCS=1
8 env GOGC=off
9
10 # If the test exits with 'no tests to run', it means the testing package
11 # implementation is incorrect and does not wait until a test panic.
12 # If the test exits with '(?s)panic: die.*panic: die', it means
13 # the testing package did an extra panic for a panicking test.
14
15 ! go test -v cleanup_failnow/panic_nocleanup_test.go
16 ! stdout 'no tests to run'
17 stdout '(?s)panic: die \[recovered\].*panic: die'
18 ! stdout '(?s)panic: die \[recovered\].*panic: die.*panic: die'
19
20 ! go test -v cleanup_failnow/panic_withcleanup_test.go
21 ! stdout 'no tests to run'
22 stdout '(?s)panic: die \[recovered\].*panic: die'
23 ! stdout '(?s)panic: die \[recovered\].*panic: die.*panic: die'
24
25 -- cleanup_failnow/panic_nocleanup_test.go --
26 package panic_nocleanup_test
27 import "testing"
28 func TestX(t *testing.T) {
29 t.Run("x", func(t *testing.T) {
30 panic("die")
31 })
32 }
33
34 -- cleanup_failnow/panic_withcleanup_test.go --
35 package panic_withcleanup_test
36 import "testing"
37 func TestCleanupWithFailNow(t *testing.T) {
38 t.Cleanup(func() {
39 t.FailNow()
40 })
41 t.Run("x", func(t *testing.T) {
42 t.Run("y", func(t *testing.T) {
43 panic("die")
44 })
45 })
46 }
View as plain text