Skip to content

Commit

Permalink
Detect and execute Fuzz targets with seed inputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
nevkontakte committed Aug 1, 2022
1 parent 4845bda commit b19a3f1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
13 changes: 11 additions & 2 deletions internal/testmain/testmain.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type TestMain struct {
Package *build.PackageData
Tests []TestFunc
Benchmarks []TestFunc
Fuzz []TestFunc
Examples []ExampleFunc
TestMain *TestFunc
}
Expand Down Expand Up @@ -133,6 +134,11 @@ func (tm *TestMain) scanFile(f *ast.File, loc FuncLocation) error {
Location: loc,
Name: name,
})
case isTest(name, "Fuzz"):
tm.Fuzz = append(tm.Fuzz, TestFunc{
Location: loc,
Name: name,
})
}
}

Expand Down Expand Up @@ -275,8 +281,11 @@ var benchmarks = []testing.InternalBenchmark{
{{- end}}
}
// TODO(nevkontakte): Extract fuzz targets from the source.
var fuzzTargets = []testing.InternalFuzzTarget{}
var fuzzTargets = []testing.InternalFuzzTarget{
{{- range .Fuzz}}
{"{{.Name}}", {{.Location}}.{{.Name}}},
{{- end}}
}
var examples = []testing.InternalExample{
{{- range .Examples }}
Expand Down
13 changes: 12 additions & 1 deletion internal/testmain/testmain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func TestScan(t *testing.T) {
{Location: LocInPackage, Name: "BenchmarkXxx"},
{Location: LocExternal, Name: "BenchmarkYyy"},
},
Fuzz: []TestFunc{
{Location: LocInPackage, Name: "FuzzXxx"},
{Location: LocExternal, Name: "FuzzYyy"},
},
Examples: []ExampleFunc{
{Location: LocInPackage, Name: "ExampleXxx"},
{Location: LocExternal, Name: "ExampleYyy", Output: "hello\n"},
Expand Down Expand Up @@ -71,6 +75,10 @@ func TestSynthesize(t *testing.T) {
{Location: LocInPackage, Name: "BenchmarkXxx"},
{Location: LocExternal, Name: "BenchmarkYyy"},
},
Fuzz: []TestFunc{
{Location: LocInPackage, Name: "FuzzXxx"},
{Location: LocExternal, Name: "FuzzYyy"},
},
Examples: []ExampleFunc{
{Location: LocInPackage, Name: "ExampleXxx", EmptyOutput: true},
{Location: LocExternal, Name: "ExampleYyy", EmptyOutput: true},
Expand Down Expand Up @@ -134,7 +142,10 @@ var benchmarks = []testing.InternalBenchmark{
{"BenchmarkYyy", _xtest.BenchmarkYyy},
}
var fuzzTargets = []testing.InternalFuzzTarget{}
var fuzzTargets = []testing.InternalFuzzTarget{
{"FuzzXxx", _test.FuzzXxx},
{"FuzzYyy", _xtest.FuzzYyy},
}
var examples = []testing.InternalExample{
{"ExampleXxx", _test.ExampleXxx, "", false},
Expand Down

0 comments on commit b19a3f1

Please sign in to comment.