Skip to content

Commit 28a8f81

Browse files
committed
Fix Windows test (after fixing Windows printing): properly escape \ in paths
This PR adds proper escaping to dot strings, so that the backslash (`\`) in windows paths will now print correctly in dot output. Previously, the tests were incorreclty checking for an unescaped single `\` in the output, which isn't a valid `dot` string, so this commit updates the dot tests to expect the newly correct output. Updates the path testing assertions in various test files
1 parent 060ba73 commit 28a8f81

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

internal/driver/driver_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,15 @@ func TestParse(t *testing.T) {
191191
if err != nil {
192192
t.Fatalf("reading solution file %s: %v", solution, err)
193193
}
194-
if runtime.GOOS == "windows" {
195-
sbuf = bytes.Replace(sbuf, []byte("testdata/"), []byte("testdata\\"), -1)
196-
sbuf = bytes.Replace(sbuf, []byte("/path/to/"), []byte("\\path\\to\\"), -1)
194+
if runtime.GOOS != "windows" {
195+
if flags[0] == "dot" {
196+
// The .dot test has the paths inside strings, so \ must be escaped.
197+
sbuf = bytes.Replace(sbuf, []byte("testdata/"), []byte(`testdata\\`), -1)
198+
sbuf = bytes.Replace(sbuf, []byte("/path/to/"), []byte(`\\path\\to\\`), -1)
199+
} else {
200+
sbuf = bytes.Replace(sbuf, []byte("testdata/"), []byte(`testdata\`), -1)
201+
sbuf = bytes.Replace(sbuf, []byte("/path/to/"), []byte(`\path\to\`), -1)
202+
}
197203
}
198204

199205
if flags[0] == "svg" {

internal/report/report_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ func TestSource(t *testing.T) {
8080
t.Fatalf("%s: %v", tc.want, err)
8181
}
8282
if runtime.GOOS == "windows" {
83-
gold = bytes.Replace(gold, []byte("testdata/"), []byte("testdata\\"), -1)
83+
if tc.rpt.options.OutputFormat == Dot {
84+
// The .dot test has the paths inside strings, so \ must be escaped.
85+
gold = bytes.Replace(gold, []byte("testdata/"), []byte(`testdata\\`), -1)
86+
} else {
87+
gold = bytes.Replace(gold, []byte("testdata/"), []byte(`testdata\`), -1)
88+
}
8489
}
8590
if string(b.String()) != string(gold) {
8691
d, err := proftest.Diff(gold, b.Bytes())

0 commit comments

Comments
 (0)