1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:04:43 -07:00

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 <bradfitz@golang.org>
This commit is contained in:
Alex Brainman 2015-07-29 14:57:13 +10:00
parent 7ba2a8c9a9
commit 0cac9d87b7

View File

@ -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)
}