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

     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, GC, and
     6  # async preemption to increase the probability of such a failure.
     7  env GOMAXPROCS=1
     8  env GOGC=off
     9  env GODEBUG=asyncpreempt=off
    10  
    11  # If the test exits with 'no tests to run', it means the testing package
    12  # implementation is incorrect and does not wait until a test panic.
    13  # If the test exits with '(?s)panic: die.*panic: die', it means
    14  # the testing package did an extra panic for a panicking test.
    15  
    16  ! go test -v cleanup_failnow/panic_nocleanup_test.go
    17  ! stdout 'no tests to run'
    18  stdout '(?s)panic: die \[recovered\].*panic: die'
    19  ! stdout '(?s)panic: die \[recovered\].*panic: die.*panic: die'
    20  
    21  ! go test -v cleanup_failnow/panic_withcleanup_test.go
    22  ! stdout 'no tests to run'
    23  stdout '(?s)panic: die \[recovered\].*panic: die'
    24  ! stdout '(?s)panic: die \[recovered\].*panic: die.*panic: die'
    25  
    26  -- cleanup_failnow/panic_nocleanup_test.go --
    27  package panic_nocleanup_test
    28  import "testing"
    29  func TestX(t *testing.T) {
    30  	t.Run("x", func(t *testing.T) {
    31  		panic("die")
    32  	})
    33  }
    34  
    35  -- cleanup_failnow/panic_withcleanup_test.go --
    36  package panic_withcleanup_test
    37  import "testing"
    38  func TestCleanupWithFailNow(t *testing.T) {
    39  	t.Cleanup(func() {
    40  		t.FailNow()
    41  	})
    42  	t.Run("x", func(t *testing.T) {
    43  		t.Run("y", func(t *testing.T) {
    44  			panic("die")
    45  		})
    46  	})
    47  }

View as plain text