Skip to content

Commit

Permalink
cmd/fiximports: make tests pass on windows
Browse files Browse the repository at this point in the history
Update golang/go#11811

Change-Id: I1f8977cf8eed84936c7c2b568f87abe88f5723f9
Reviewed-on: https://go-review.googlesource.com/12788
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
alexbrainman committed Jul 29, 2015
1 parent 7ba2a8c commit 0cac9d8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cmd/fiximports/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package main
import (
"bytes"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
)
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 0cac9d8

Please sign in to comment.