Skip to content

Commit b4ccdc7

Browse files
dmullisdmullis
authored andcommitted
Regression testing: Clarify source code and CLI text
Bump required Go version to 1.21 for access to functions min() and max().
1 parent 1c87c18 commit b4ccdc7

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
build:
1111
strategy:
1212
matrix:
13-
go-version: [1.20.x]
13+
go-version: [1.21.x]
1414
os: [ubuntu-latest]
1515
runs-on: ${{ matrix.os }}
1616
steps:

examples_test.go

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

1616
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")
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

120132
const 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
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/blampe/goat
22

3-
go 1.17
3+
go 1.21
44

55
require (
66
github.com/frankban/quicktest v1.14.2

pre-push.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,5 @@ go run ./cmd/goat <examples/trees.txt \
8787
# X `tac` is a slightly sleazy way to get the .txt/.svg pairs listed in the
8888
# source/dest order as required by tmpl_expand.
8989
tmpl_expand <README.md.tmpl >README.md $(git-ls-files examples | tac)
90+
91+
printf "\nTo install in local GOPATH:\n\t%s\n" "go install ./cmd/goat"

0 commit comments

Comments
 (0)