Skip to content

Commit

Permalink
Clean up regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
dmullis authored and dmullis committed Jul 17, 2024
1 parent 9f10b08 commit d0199de
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

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

var buff *bytes.Buffer

if write == nil {
t.Logf("Verifying output of current build against earlier .svg files in examples/.\n")
}
var failures int
for _, name := range filenames {
in := getIn(name)
if testing.Verbose() {
t.Logf("\tprocessing %s\n", name)
}
var out io.WriteCloser
if *write {
out = getOut(name)
Expand Down Expand Up @@ -88,17 +88,25 @@ func TestExamples(t *testing.T) {
// source is fresher than the .svg?
t.Log(buff.Len(), len(golden))
t.Logf("Content mismatch for %s", toSVGFilename(name))
t.Logf("%s %s:\n\t%s\nConsider:\n\t%s",
"Option -write not set, and Error reading",
name,
err.Error(),
"$ go test -run TestExamples -v -args -write")
t.FailNow()
failures++
} else {
if testing.Verbose() {
t.Logf("Verified contents of SVG file %s\n",
toSVGFilename(name))
}
}
in.Close()
out.Close()
}
}
if failures > 0 {
t.Logf(`Failed to verify contents of %d .svg files
Consider:
%s`,
failures,
"$ go test -run TestExamples -v -args -write")
t.FailNow()
}
}

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

0 comments on commit d0199de

Please sign in to comment.