refactor/rename: use filepath.ToSlash everywhere to fix windows tests
Fixes golang/go#8823.
LGTM=adonovan
R=golang-codereviews, gobot, adonovan
CC=golang-codereviews
https://golang.org/cl/142660043
diff --git a/refactor/rename/rename_test.go b/refactor/rename/rename_test.go
index fb568f0..2e46569 100644
--- a/refactor/rename/rename_test.go
+++ b/refactor/rename/rename_test.go
@@ -659,7 +659,7 @@
if err := format.Node(&out, fset, f); err != nil {
return err
}
- got[orig] = out.String()
+ got[filepath.ToSlash(orig)] = out.String()
return nil
}
@@ -707,6 +707,7 @@
ctxt.GOROOT = "/go"
ctxt.GOPATH = ""
ctxt.IsDir = func(path string) bool {
+ path = filepath.ToSlash(path)
if path == "/go/src" {
return true // needed by (*build.Context).SrcDirs
}
@@ -719,6 +720,7 @@
return ok
}
ctxt.ReadDir = func(dir string) ([]os.FileInfo, error) {
+ dir = filepath.ToSlash(dir)
dir = dir[len("/go/src/"):]
var fis []os.FileInfo
if dir == "" {
@@ -734,6 +736,7 @@
return fis, nil
}
ctxt.OpenFile = func(path string) (io.ReadCloser, error) {
+ path = filepath.ToSlash(path)
path = path[len("/go/src/"):]
dir, base := filepath.Split(path)
dir = filepath.Clean(dir)
@@ -741,6 +744,7 @@
return ioutil.NopCloser(bytes.NewBufferString(pkgs[dir][index])), nil
}
ctxt.IsAbsPath = func(path string) bool {
+ path = filepath.ToSlash(path)
// Don't rely on the default (filepath.Path) since on
// Windows, it reports our virtual paths as non-absolute.
return strings.HasPrefix(path, "/")
diff --git a/refactor/rename/util.go b/refactor/rename/util.go
index aa13908..f9354d8 100644
--- a/refactor/rename/util.go
+++ b/refactor/rename/util.go
@@ -8,6 +8,7 @@
"os"
"path/filepath"
"reflect"
+ "runtime"
"strings"
"unicode"
@@ -81,6 +82,10 @@
// the same file.
//
func sameFile(x, y string) bool {
+ if runtime.GOOS == "windows" {
+ x = filepath.ToSlash(x)
+ y = filepath.ToSlash(y)
+ }
if x == y {
return true
}