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

     1  # Verifies golang.org/issue/37555.
     2  
     3  [short] skip
     4  
     5  # 'go test -json' should say a test passes if it says it passes.
     6  go test -json ./pass
     7  stdout '"Action":"pass","Package":"[^"]*","Elapsed":[^"]*}\n\z'
     8  ! stdout '"Test":.*\n\z'
     9  
    10  # 'go test -json' should say a test passes if it exits 0 and prints nothing.
    11  # TODO(golang.org/issue/29062): this should fail in the future.
    12  go test -json ./exit0main
    13  stdout '"Action":"pass".*\n\z'
    14  ! stdout '"Test":.*\n\z'
    15  
    16  # 'go test -json' should say a test fails if it exits 1 and prints nothing.
    17  ! go test -json ./exit1main
    18  stdout '"Action":"fail".*\n\z'
    19  ! stdout '"Test":.*\n\z'
    20  
    21  # 'go test -json' should say a test fails if it panics.
    22  ! go test -json ./panic
    23  stdout '"Action":"fail".*\n\z'
    24  ! stdout '"Test":.*\n\z'
    25  
    26  -- go.mod --
    27  module example.com/test
    28  
    29  go 1.14
    30  
    31  -- pass/pass_test.go --
    32  package pass_test
    33  
    34  import "testing"
    35  
    36  func TestPass(t *testing.T) {}
    37  
    38  -- exit0main/exit0main_test.go --
    39  package exit0_test
    40  
    41  import (
    42  	"os"
    43  	"testing"
    44  )
    45  
    46  func TestMain(m *testing.M) {
    47  	os.Exit(0)
    48  }
    49  
    50  -- exit1main/exit1main_test.go --
    51  package exit1_test
    52  
    53  import (
    54  	"os"
    55  	"testing"
    56  )
    57  
    58  func TestMain(m *testing.M) {
    59  	os.Exit(1)
    60  }
    61  
    62  -- panic/panic_test.go --
    63  package panic_test
    64  
    65  import "testing"
    66  
    67  func TestPanic(t *testing.T) {
    68  	panic("oh no")
    69  }
    70  

View as plain text