Skip to content

Commit d0199de

Browse files
dmullisdmullis
authored andcommitted
Clean up regression test
1 parent 9f10b08 commit d0199de

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

examples_test.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
var (
17-
write = flag.Bool("write", false, "write examples to disk")
17+
write = flag.Bool("write", false, "write examples to disk") // XX rename: more descriptive
1818
svgColorLightScheme = flag.String("svg-color-light-scheme", "#000000",
1919
`See help for cmd/goat`)
2020
svgColorDarkScheme = flag.String("svg-color-dark-scheme", "#FFFFFF",
@@ -49,12 +49,12 @@ func TestExamples(t *testing.T) {
4949
}
5050

5151
var buff *bytes.Buffer
52-
52+
if write == nil {
53+
t.Logf("Verifying output of current build against earlier .svg files in examples/.\n")
54+
}
55+
var failures int
5356
for _, name := range filenames {
5457
in := getIn(name)
55-
if testing.Verbose() {
56-
t.Logf("\tprocessing %s\n", name)
57-
}
5858
var out io.WriteCloser
5959
if *write {
6060
out = getOut(name)
@@ -88,17 +88,25 @@ func TestExamples(t *testing.T) {
8888
// source is fresher than the .svg?
8989
t.Log(buff.Len(), len(golden))
9090
t.Logf("Content mismatch for %s", toSVGFilename(name))
91-
t.Logf("%s %s:\n\t%s\nConsider:\n\t%s",
92-
"Option -write not set, and Error reading",
93-
name,
94-
err.Error(),
95-
"$ go test -run TestExamples -v -args -write")
96-
t.FailNow()
91+
failures++
92+
} else {
93+
if testing.Verbose() {
94+
t.Logf("Verified contents of SVG file %s\n",
95+
toSVGFilename(name))
96+
}
9797
}
9898
in.Close()
9999
out.Close()
100100
}
101101
}
102+
if failures > 0 {
103+
t.Logf(`Failed to verify contents of %d .svg files
104+
Consider:
105+
%s`,
106+
failures,
107+
"$ go test -run TestExamples -v -args -write")
108+
t.FailNow()
109+
}
102110
}
103111

104112
func BenchmarkComplicated(b *testing.B) {
@@ -132,6 +140,7 @@ func getOutString(filename string) (string, error) {
132140
if err != nil {
133141
return "", err
134142
}
143+
// XX Why are there RETURN characters in contents of the .SVG files?
135144
b = bytes.ReplaceAll(b, []byte("\r\n"), []byte("\n"))
136145
return string(b), nil
137146
}

0 commit comments

Comments
 (0)