mirror of
https://github.com/gonum/gonum.git
synced 2025-10-06 23:52:47 +08:00
graph/encoding/dot: ensure that generated DOT is syntactically valid (#795)
This commit is contained in:

committed by
Robin Eklind

parent
bb6edb12aa
commit
03f4920c3e
@@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user