Files
Billy Keyes 688483e179 Add experimental fuzz test
This uses the beta version of native fuzzing support, currently expected
to ship in an initial form in go 1.18. For now, the test must be run
with a development version of Go and is ignored otherwise.
2021-09-12 21:37:53 -07:00

39 lines
715 B
Go

// +build gofuzzbeta
package gitdiff
import (
"bytes"
"io/fs"
"os"
"path/filepath"
"strings"
"testing"
)
func FuzzParse(f *testing.F) {
// Use existing test files as the seed corpus
// TODO(bkeyes): once supported, should this use static files instead?
if err := filepath.WalkDir("testdata", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() || !strings.HasSuffix(path, ".patch") {
return nil
}
b, err := os.ReadFile(path)
if err != nil {
return err
}
f.Add(b)
return nil
}); err != nil {
f.Fatalf("error creating seed corpus: %v", err)
}
f.Fuzz(func(t *testing.T, b []byte) {
t.Parallel()
Parse(bytes.NewReader(b))
})
}