graph/formats/dot/internal: add tests for a fuzz data corpus

This commit is contained in:
Dan Kortschak
2019-03-06 15:07:41 +10:30
parent 6df7f4be3a
commit 75c68f713c
2 changed files with 68 additions and 0 deletions

View File

@@ -11,8 +11,10 @@
package parser_test
import (
"archive/zip"
"bytes"
"io/ioutil"
"os"
"testing"
"gonum.org/v1/gonum/graph/formats/dot"
@@ -86,6 +88,38 @@ func TestParseFile(t *testing.T) {
}
}
func TestParseFuzz(t *testing.T) {
r, err := zip.OpenReader("../../fuzz/corpus.zip")
if err != nil {
if os.IsNotExist(err) {
t.Skip("no corpus")
}
t.Fatalf("failed to open corpus: %v", err)
}
defer r.Close()
for _, f := range r.File {
rc, err := f.Open()
if err != nil {
t.Fatalf("failed to open %q: %v", f.Name, err)
}
func() {
defer func() {
p := recover()
if p != nil {
t.Errorf("unexpected panic parsing %q: %v", f.Name, p)
}
}()
_, err = dot.Parse(rc)
if err != nil {
t.Errorf("unexpected error parsing %q: %v", f.Name, err)
}
}()
rc.Close()
}
}
func TestParseError(t *testing.T) {
golden := []struct {
path string