1 [!fuzz] skip
2
3 # Check that if a worker does not call F.Fuzz or calls F.Fail first,
4 # 'go test' exits non-zero and no crasher is recorded.
5
6 [short] skip
7 env GOCACHE=$WORK/cache
8
9 ! go test -fuzz=FuzzReturn
10 ! exists testdata
11
12 ! go test -fuzz=FuzzSkip
13 ! exists testdata
14
15 ! go test -fuzz=FuzzFail
16 ! exists testdata
17
18 ! go test -fuzz=FuzzPanic
19 ! exists testdata
20
21 ! go test -fuzz=FuzzNilPanic
22 ! exists testdata
23
24 ! go test -fuzz=FuzzGoexit
25 ! exists testdata
26
27 ! go test -fuzz=FuzzExit
28 ! exists testdata
29
30 -- go.mod --
31 module m
32
33 go 1.17
34 -- fuzz_fail_test.go --
35 package fuzz_fail
36
37 import (
38 "flag"
39 "os"
40 "runtime"
41 "testing"
42 )
43
44 func isWorker() bool {
45 f := flag.Lookup("test.fuzzworker")
46 if f == nil {
47 return false
48 }
49 get, ok := f.Value.(flag.Getter)
50 if !ok {
51 return false
52 }
53 return get.Get() == interface{}(true)
54 }
55
56 func FuzzReturn(f *testing.F) {
57 if isWorker() {
58 return
59 }
60 f.Fuzz(func(*testing.T, []byte) {})
61 }
62
63 func FuzzSkip(f *testing.F) {
64 if isWorker() {
65 f.Skip()
66 }
67 f.Fuzz(func(*testing.T, []byte) {})
68 }
69
70 func FuzzFail(f *testing.F) {
71 if isWorker() {
72 f.Fail()
73 }
74 f.Fuzz(func(*testing.T, []byte) {})
75 }
76
77 func FuzzPanic(f *testing.F) {
78 if isWorker() {
79 panic("nope")
80 }
81 f.Fuzz(func(*testing.T, []byte) {})
82 }
83
84 func FuzzNilPanic(f *testing.F) {
85 if isWorker() {
86 panic(nil)
87 }
88 f.Fuzz(func(*testing.T, []byte) {})
89 }
90
91 func FuzzGoexit(f *testing.F) {
92 if isWorker() {
93 runtime.Goexit()
94 }
95 f.Fuzz(func(*testing.T, []byte) {})
96 }
97
98 func FuzzExit(f *testing.F) {
99 if isWorker() {
100 os.Exit(99)
101 }
102 f.Fuzz(func(*testing.T, []byte) {})
103 }
104
View as plain text