@@ -14,7 +14,7 @@ import (
14
14
)
15
15
16
16
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
18
18
svgColorLightScheme = flag .String ("svg-color-light-scheme" , "#000000" ,
19
19
`See help for cmd/goat` )
20
20
svgColorDarkScheme = flag .String ("svg-color-dark-scheme" , "#FFFFFF" ,
@@ -49,12 +49,12 @@ func TestExamples(t *testing.T) {
49
49
}
50
50
51
51
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
53
56
for _ , name := range filenames {
54
57
in := getIn (name )
55
- if testing .Verbose () {
56
- t .Logf ("\t processing %s\n " , name )
57
- }
58
58
var out io.WriteCloser
59
59
if * write {
60
60
out = getOut (name )
@@ -88,17 +88,25 @@ func TestExamples(t *testing.T) {
88
88
// source is fresher than the .svg?
89
89
t .Log (buff .Len (), len (golden ))
90
90
t .Logf ("Content mismatch for %s" , toSVGFilename (name ))
91
- t . Logf ( "%s %s: \n \t %s \n Consider: \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
+ }
97
97
}
98
98
in .Close ()
99
99
out .Close ()
100
100
}
101
101
}
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
+ }
102
110
}
103
111
104
112
func BenchmarkComplicated (b * testing.B ) {
@@ -132,6 +140,7 @@ func getOutString(filename string) (string, error) {
132
140
if err != nil {
133
141
return "" , err
134
142
}
143
+ // XX Why are there RETURN characters in contents of the .SVG files?
135
144
b = bytes .ReplaceAll (b , []byte ("\r \n " ), []byte ("\n " ))
136
145
return string (b ), nil
137
146
}
0 commit comments