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