@@ -14,7 +14,8 @@ import (
1414)
1515
1616var (
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" )
1819 svgColorLightScheme = flag .String ("svg-color-light-scheme" , "#000000" ,
1920 `See help for cmd/goat` )
2021 svgColorDarkScheme = flag .String ("svg-color-dark-scheme" , "#FFFFFF" ,
@@ -50,7 +51,7 @@ func TestExamples(t *testing.T) {
5051
5152 var buff * bytes.Buffer
5253 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 " )
5455 }
5556 var failures int
5657 for _ , name := range filenames {
@@ -83,15 +84,26 @@ func TestExamples(t *testing.T) {
8384 if err != nil {
8485 t .Log (err )
8586 }
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 ))
91103 failures ++
92104 } else {
93105 if testing .Verbose () {
94- t .Logf ("Verified contents of SVG file %s\n " ,
106+ t .Logf ("Existing and generated contents match %s\n " ,
95107 toSVGFilename (name ))
96108 }
97109 }
@@ -119,24 +131,24 @@ func BenchmarkComplicated(b *testing.B) {
119131
120132const basePath string = "examples"
121133
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 )
124136 if err != nil {
125137 panic (err )
126138 }
127139 return in
128140}
129141
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 ))
132144 if err != nil {
133145 panic (err )
134146 }
135147 return out
136148}
137149
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 ))
140152 if err != nil {
141153 return "" , err
142154 }
@@ -145,6 +157,6 @@ func getOutString(filename string) (string, error) {
145157 return string (b ), nil
146158}
147159
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"
150162}
0 commit comments