diff --git a/.travis.yml b/.travis.yml index 364ca9ef..73c8a2e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,6 +34,11 @@ before_install: # Required for dot parser checks. - ./.travis/install-gocc.sh 0e2cfc030005b281b2e5a2de04fa7fe1d5063722 +addons: + apt: + packages: + - graphviz + go_import_path: gonum.org/v1/gonum # Get deps, build, test, and ensure the code is gofmt'ed. diff --git a/graph/encoding/dot/encode_test.go b/graph/encoding/dot/encode_test.go index 19709f3c..4b4f3cd5 100644 --- a/graph/encoding/dot/encode_test.go +++ b/graph/encoding/dot/encode_test.go @@ -5,6 +5,8 @@ package dot import ( + "bytes" + "os/exec" "testing" "gonum.org/v1/gonum/graph" @@ -1474,6 +1476,7 @@ func TestEncode(t *testing.T) { if string(got) != test.want { t.Errorf("unexpected DOT result for test %d:\ngot: %s\nwant:%s", i, got, test.want) } + checkDOT(t, got) } } @@ -1729,5 +1732,24 @@ func TestEncodeMulti(t *testing.T) { if string(got) != test.want { t.Errorf("unexpected DOT result for test %d:\ngot: %s\nwant:%s", i, got, test.want) } + checkDOT(t, got) + } +} + +// checkDOT hands b to the dot executable if it exists and fails t if dot +// returns an error. +func checkDOT(t *testing.T, b []byte) { + dot, err := exec.LookPath("dot") + if err != nil { + t.Logf("skipping DOT syntax check: %v", err) + return + } + cmd := exec.Command(dot) + cmd.Stdin = bytes.NewReader(b) + stderr := &bytes.Buffer{} + cmd.Stderr = stderr + err = cmd.Run() + if err != nil { + t.Errorf("invalid DOT syntax: %v\n%s\ninput:\n%s", err, stderr.String(), b) } } diff --git a/graph/encoding/graphql/decode_test.go b/graph/encoding/graphql/decode_test.go index e4d0c8a5..5db4d5df 100644 --- a/graph/encoding/graphql/decode_test.go +++ b/graph/encoding/graphql/decode_test.go @@ -5,8 +5,10 @@ package graphql import ( + "bytes" "errors" "fmt" + "os/exec" "sort" "strconv" "strings" @@ -147,6 +149,7 @@ func TestDecode(t *testing.T) { if gotDOT != test.wantDOT { t.Errorf("unexpected DOT encoding for %q:\ngot:\n%s\nwant:\n%s", test.name, gotDOT, test.wantDOT) } + checkDOT(t, b) } } @@ -219,3 +222,21 @@ func (a attributes) Attributes() []encoding.Attribute { } return attr } + +// checkDOT hands b to the dot executable if it exists and fails t if dot +// returns an error. +func checkDOT(t *testing.T, b []byte) { + dot, err := exec.LookPath("dot") + if err != nil { + t.Logf("skipping DOT syntax check: %v", err) + return + } + cmd := exec.Command(dot) + cmd.Stdin = bytes.NewReader(b) + stderr := &bytes.Buffer{} + cmd.Stderr = stderr + err = cmd.Run() + if err != nil { + t.Errorf("invalid DOT syntax: %v\n%s\ninput:\n%s", err, stderr.String(), b) + } +}