...

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

Documentation: cmd/go/testdata/script

     1[short] skip
     2
     3go test -c -o mainpanic.exe ./mainpanic &
     4go test -c -o mainexit0.exe ./mainexit0 &
     5go test -c -o testpanic.exe ./testpanic &
     6go test -c -o testbgpanic.exe ./testbgpanic &
     7wait
     8
     9# Test binaries that panic in TestMain should be marked as failing.
    10
    11! go test -json ./mainpanic
    12stdout '"Action":"fail"'
    13! stdout '"Action":"pass"'
    14
    15! go tool test2json ./mainpanic.exe
    16stdout '"Action":"fail"'
    17! stdout '"Action":"pass"'
    18
    19# Test binaries that exit with status 0 should be marked as passing.
    20
    21go test -json ./mainexit0
    22stdout '"Action":"pass"'
    23! stdout '"Action":"fail"'
    24
    25go tool test2json ./mainexit0.exe
    26stdout '"Action":"pass"'
    27! stdout '"Action":"fail"'
    28
    29# Test functions that panic should never be marked as passing
    30# (https://golang.org/issue/40132).
    31
    32! go test -json ./testpanic
    33stdout '"Action":"fail"'
    34! stdout '"Action":"pass"'
    35
    36! go tool test2json ./testpanic.exe -test.v
    37stdout '"Action":"fail"'
    38! stdout '"Action":"pass"'
    39
    40! go tool test2json ./testpanic.exe
    41stdout '"Action":"fail"'
    42! stdout '"Action":"pass"'
    43
    44# Tests that panic in a background goroutine should be marked as failing.
    45
    46! go test -json ./testbgpanic
    47stdout '"Action":"fail"'
    48! stdout '"Action":"pass"'
    49
    50! go tool test2json ./testbgpanic.exe -test.v
    51stdout '"Action":"fail"'
    52! stdout '"Action":"pass"'
    53
    54! go tool test2json ./testbgpanic.exe
    55stdout '"Action":"fail"'
    56! stdout '"Action":"pass"'
    57
    58-- go.mod --
    59module m
    60go 1.14
    61-- mainpanic/mainpanic_test.go --
    62package mainpanic_test
    63
    64import "testing"
    65
    66func TestMain(m *testing.M) {
    67	panic("haha no")
    68}
    69-- mainexit0/mainexit0_test.go --
    70package mainexit0_test
    71
    72import (
    73	"fmt"
    74	"os"
    75	"testing"
    76)
    77
    78func TestMain(m *testing.M) {
    79	fmt.Println("nothing to do")
    80	os.Exit(0)
    81}
    82-- testpanic/testpanic_test.go --
    83package testpanic_test
    84
    85import "testing"
    86
    87func TestPanic(*testing.T) {
    88	panic("haha no")
    89}
    90-- testbgpanic/testbgpanic_test.go --
    91package testbgpanic_test
    92
    93import "testing"
    94
    95func TestPanicInBackground(*testing.T) {
    96	c := make(chan struct{})
    97	go func() {
    98		panic("haha no")
    99		close(c)
   100	}()
   101	<-c
   102}

View as plain text