From 0cac9d87b785bec832be427dfe78a3a4cf529485 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Wed, 29 Jul 2015 14:57:13 +1000 Subject: [PATCH] cmd/fiximports: make tests pass on windows Update golang/go#11811 Change-Id: I1f8977cf8eed84936c7c2b568f87abe88f5723f9 Reviewed-on: https://go-review.googlesource.com/12788 Reviewed-by: Brad Fitzpatrick --- cmd/fiximports/main_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/fiximports/main_test.go b/cmd/fiximports/main_test.go index 80adbc437f8..7320e22f4a5 100644 --- a/cmd/fiximports/main_test.go +++ b/cmd/fiximports/main_test.go @@ -7,6 +7,8 @@ package main import ( "bytes" "os" + "path/filepath" + "runtime" "strings" "testing" ) @@ -27,7 +29,7 @@ import ( // titanic.biz/foo -- domain is sinking but package has no import comment yet func TestFixImports(t *testing.T) { - gopath := cwd + "/testdata" + gopath := filepath.Join(cwd, "testdata") if err := os.Setenv("GOPATH", gopath); err != nil { t.Fatalf("os.Setenv: %v", err) } @@ -107,10 +109,16 @@ import ( gotRewrite := make(map[string]string) writeFile = func(filename string, content []byte, mode os.FileMode) error { filename = strings.Replace(filename, gopath, "$GOPATH", 1) + filename = filepath.ToSlash(filename) gotRewrite[filename] = string(bytes.TrimSpace(content)) return nil } + if runtime.GOOS == "windows" { + test.wantStderr = strings.Replace(test.wantStderr, `testdata/src/old.com/bad/bad.go`, `testdata\src\old.com\bad\bad.go`, -1) + test.wantStderr = strings.Replace(test.wantStderr, `testdata/src/fruit.io/banana/banana.go`, `testdata\src\fruit.io\banana\banana.go`, -1) + } + // Check status code. if fiximports(test.packages...) != test.wantOK { t.Errorf("#%d. fiximports() = %t", i, !test.wantOK) @@ -138,7 +146,7 @@ import ( // TestDryRun tests that the -n flag suppresses calls to writeFile. func TestDryRun(t *testing.T) { - gopath := cwd + "/testdata" + gopath := filepath.Join(cwd, "testdata") if err := os.Setenv("GOPATH", gopath); err != nil { t.Fatalf("os.Setenv: %v", err) }