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