File size: 3,083 Bytes
e36aeda
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
[!fuzz] skip
[short] skip
env GOCACHE=$WORK/cache

# Tests which verify the behavior and command line output when
# running a fuzz target as a unit test.

# Tests without -run.

! go test
stdout FAIL
stdout 'error here'

! go test -v
stdout FAIL
stdout 'error here'
stdout '=== RUN   FuzzFoo/thisfails'
stdout '--- FAIL: FuzzFoo/thisfails'
stdout '=== RUN   FuzzFoo/thispasses'
stdout '--- PASS: FuzzFoo/thispasses'

# Tests where -run matches all seed corpora.

! go test -run FuzzFoo/this
stdout FAIL
stdout 'error here'
! stdout 'no tests to run'

! go test -run /this
stdout FAIL
stdout 'error here'
! stdout 'no tests to run'

! go test -v -run FuzzFoo/this
stdout FAIL
stdout 'error here'
stdout '=== RUN   FuzzFoo/thisfails'
stdout '--- FAIL: FuzzFoo/thisfails'
stdout '=== RUN   FuzzFoo/thispasses'
stdout '--- PASS: FuzzFoo/thispasses'
! stdout 'no tests to run'

! go test -v -run /this
stdout FAIL
stdout 'error here'
stdout '=== RUN   FuzzFoo/thisfails'
stdout '--- FAIL: FuzzFoo/thisfails'
stdout '=== RUN   FuzzFoo/thispasses'
stdout '--- PASS: FuzzFoo/thispasses'
! stdout 'no tests to run'

# Tests where -run only matches one seed corpus which passes.

go test -run FuzzFoo/thispasses
stdout ok
! stdout 'no tests to run'

go test -run /thispasses
stdout ok
! stdout 'no tests to run'

# Same tests in verbose mode
go test -v -run FuzzFoo/thispasses
stdout '=== RUN   FuzzFoo/thispasses'
stdout '--- PASS: FuzzFoo/thispasses'
! stdout '=== RUN   FuzzFoo/thisfails'
! stdout 'no tests to run'

go test -v -run /thispasses
stdout '=== RUN   FuzzFoo/thispasses'
stdout '--- PASS: FuzzFoo/thispasses'
! stdout '=== RUN   FuzzFoo/thisfails'
! stdout 'no tests to run'

# Tests where -run only matches one seed corpus which fails.

! go test -run FuzzFoo/thisfails
stdout FAIL
stdout 'error here'
! stdout 'no tests to run'

! go test -run /thisfails
stdout FAIL
stdout 'error here'
! stdout 'no tests to run'

! go test -v -run FuzzFoo/thisfails
stdout 'error here'
stdout '=== RUN   FuzzFoo/thisfails'
stdout '--- FAIL: FuzzFoo/thisfails'
! stdout '=== RUN   FuzzFoo/thispasses'
! stdout 'no tests to run'

! go test -v -run /thisfails
stdout 'error here'
stdout '=== RUN   FuzzFoo/thisfails'
stdout '--- FAIL: FuzzFoo/thisfails'
! stdout '=== RUN   FuzzFoo/thispasses'
! stdout 'no tests to run'

# Tests where -run doesn't match any seed corpora.

go test -run FuzzFoo/nomatch
stdout ok

go test -run /nomatch
stdout ok

go test -v -run FuzzFoo/nomatch
stdout '=== RUN   FuzzFoo'
stdout '--- PASS: FuzzFoo'
stdout ok
! stdout 'no tests to run'

go test -v -run /nomatch
stdout '=== RUN   FuzzFoo'
stdout '--- PASS: FuzzFoo'
stdout ok
! stdout 'no tests to run'

-- go.mod --
module example.com/x

go 1.16
-- x_test.go --
package x

import "testing"

func FuzzFoo(f *testing.F) {
    f.Add("this is fine")
    f.Fuzz(func(t *testing.T, s string) {
        if s == "fails" {
            t.Error("error here")
        }
    })
}
-- testdata/fuzz/FuzzFoo/thisfails --
go test fuzz v1
string("fails")
-- testdata/fuzz/FuzzFoo/thispasses --
go test fuzz v1
string("passes")