@@ -14,7 +14,8 @@ import (
14
14
)
15
15
16
16
var (
17
- write = flag .Bool ("write" , false , "write examples to disk" ) // XX rename: more descriptive
17
+ write = flag .Bool ("write" ,
18
+ false , "write reference SVG output files" )
18
19
svgColorLightScheme = flag .String ("svg-color-light-scheme" , "#000000" ,
19
20
`See help for cmd/goat` )
20
21
svgColorDarkScheme = flag .String ("svg-color-dark-scheme" , "#FFFFFF" ,
@@ -50,7 +51,7 @@ func TestExamples(t *testing.T) {
50
51
51
52
var buff * bytes.Buffer
52
53
if write == nil {
53
- t .Logf ("Verifying output of current build against earlier .svg files in examples/.\n " )
54
+ t .Logf ("Verifying equality of current SVG with examples/ references .\n " )
54
55
}
55
56
var failures int
56
57
for _ , name := range filenames {
@@ -83,15 +84,26 @@ func TestExamples(t *testing.T) {
83
84
if err != nil {
84
85
t .Log (err )
85
86
}
86
- if buff .String () != golden {
87
- // XX Skip this if the modification timestamp of the .txt file
88
- // source is fresher than the .svg?
89
- t .Log (buff .Len (), len (golden ))
90
- t .Logf ("Content mismatch for %s" , toSVGFilename (name ))
87
+ if newStr := buff .String (); newStr != golden {
88
+ // Skip complaint if the modification timestamp of the .txt file
89
+ // source is fresher than that of the .svg?
90
+ // => NO, Any .txt difference might be an editing mistake.
91
+
92
+ t .Logf ("Content mismatch for %s. Length was %d, expected %d" ,
93
+ toSVGFilename (name ), buff .Len (), len (golden ))
94
+ for i := 0 ; i < min (len (golden ), len (newStr )); i ++ {
95
+ if newStr [i ] != golden [i ] {
96
+ t .Logf ("Differing runes at offset %d: new='%#v' reference='%#v'\n " ,
97
+ i , newStr [i ], golden [i ])
98
+ break
99
+ }
100
+ }
101
+ t .Logf ("Generated contents do not match existing %s" ,
102
+ toSVGFilename (name ))
91
103
failures ++
92
104
} else {
93
105
if testing .Verbose () {
94
- t .Logf ("Verified contents of SVG file %s\n " ,
106
+ t .Logf ("Existing and generated contents match %s\n " ,
95
107
toSVGFilename (name ))
96
108
}
97
109
}
@@ -119,24 +131,24 @@ func BenchmarkComplicated(b *testing.B) {
119
131
120
132
const basePath string = "examples"
121
133
122
- func getIn (filename string ) io.ReadCloser {
123
- in , err := os .Open (filename )
134
+ func getIn (txtFilename string ) io.ReadCloser {
135
+ in , err := os .Open (txtFilename )
124
136
if err != nil {
125
137
panic (err )
126
138
}
127
139
return in
128
140
}
129
141
130
- func getOut (filename string ) io.WriteCloser {
131
- out , err := os .Create (toSVGFilename (filename ))
142
+ func getOut (txtFilename string ) io.WriteCloser {
143
+ out , err := os .Create (toSVGFilename (txtFilename ))
132
144
if err != nil {
133
145
panic (err )
134
146
}
135
147
return out
136
148
}
137
149
138
- func getOutString (filename string ) (string , error ) {
139
- b , err := ioutil .ReadFile (toSVGFilename (filename ))
150
+ func getOutString (txtFilename string ) (string , error ) {
151
+ b , err := ioutil .ReadFile (toSVGFilename (txtFilename ))
140
152
if err != nil {
141
153
return "" , err
142
154
}
@@ -145,6 +157,6 @@ func getOutString(filename string) (string, error) {
145
157
return string (b ), nil
146
158
}
147
159
148
- func toSVGFilename (filename string ) string {
149
- return strings .TrimSuffix (filename , filepath .Ext (filename )) + ".svg"
160
+ func toSVGFilename (txtFilename string ) string {
161
+ return strings .TrimSuffix (txtFilename , filepath .Ext (txtFilename )) + ".svg"
150
162
}
0 commit comments