-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate_test.go
66 lines (56 loc) · 1.05 KB
/
generate_test.go
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
package cautiouspancake
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestGenerateFuzz(t *testing.T) {
cg := NewCallGraph(loadFixture(t))
if err := cg.Analyze(); err != nil {
t.Fatalf("Analyze() returned error: %v", err)
}
tests := []struct {
in string
want string
}{
{
in: "YesMaybePanic",
want: `package fixtures
import (
"testing"
)
func FuzzYesMaybePanic(f *testing.F) {
f.Fuzz(func(t *testing.T, p0 byte) {
YesMaybePanic(p0)
})
}
`,
},
{
in: "YesArgs",
want: `package fixtures
import (
"testing"
)
func FuzzYesArgs(f *testing.F) {
f.Fuzz(func(t *testing.T, p0 string, p1 []byte, p2 int, p3 bool, p4 float64) {
YesArgs(p0, p1, p2, p3, p4)
})
}
`,
},
}
for _, tc := range tests {
t.Run(tc.in, func(t *testing.T) {
f, _ := cg.Lookup(tc.in)
if f == nil {
t.Errorf("could not find function %q", tc.in)
return
}
got := GenerateFuzz(f)
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Log(got)
t.Errorf("GenerateFuzz() returned diff (-want +got):\n%s", diff)
}
})
}
}