...

Text file src/cmd/go/testdata/script/test_cleanup_failnow.txt

Documentation: cmd/go/testdata/script

     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.
     7env GOMAXPROCS=1
     8env 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'
    17stdout '(?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'
    22stdout '(?s)panic: die \[recovered\].*panic: die'
    23! stdout '(?s)panic: die \[recovered\].*panic: die.*panic: die'
    24
    25-- cleanup_failnow/panic_nocleanup_test.go --
    26package panic_nocleanup_test
    27import "testing"
    28func 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 --
    35package panic_withcleanup_test
    36import "testing"
    37func 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