aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/test_cleanup_failnow.txt
blob: 0737a93db21443b10ea1ba7bd29bba27b11fa3a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# For issue 41355
[short] skip

# This test could fail if the testing package does not wait until
# a panicking test does the panic. Turn off multithreading, GC, and
# async preemption to increase the probability of such a failure.
env GOMAXPROCS=1
env GOGC=off
env GODEBUG=asyncpreempt=off

# If the test exits with 'no tests to run', it means the testing package
# implementation is incorrect and does not wait until a test panic.
# If the test exits with '(?s)panic: die.*panic: die', it means
# the testing package did an extra panic for a panicking test.

! go test -v cleanup_failnow/panic_nocleanup_test.go
! stdout 'no tests to run'
stdout '(?s)panic: die \[recovered\].*panic: die'
! stdout '(?s)panic: die \[recovered\].*panic: die.*panic: die'

! go test -v cleanup_failnow/panic_withcleanup_test.go
! stdout 'no tests to run'
stdout '(?s)panic: die \[recovered\].*panic: die'
! stdout '(?s)panic: die \[recovered\].*panic: die.*panic: die'

-- cleanup_failnow/panic_nocleanup_test.go --
package panic_nocleanup_test
import "testing"
func TestX(t *testing.T) {
	t.Run("x", func(t *testing.T) {
		panic("die")
	})
}

-- cleanup_failnow/panic_withcleanup_test.go --
package panic_withcleanup_test
import "testing"
func TestCleanupWithFailNow(t *testing.T) {
	t.Cleanup(func() {
		t.FailNow()
	})
	t.Run("x", func(t *testing.T) {
		t.Run("y", func(t *testing.T) {
			panic("die")
		})
	})
}