From 181e280a22ef5ed4ed8e35d51a73fe6f3b897dc6 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Thu, 23 Oct 2014 09:45:47 +1100 Subject: [PATCH] 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 --- refactor/rename/rename_test.go | 6 +++++- refactor/rename/util.go | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/refactor/rename/rename_test.go b/refactor/rename/rename_test.go index fb568f0d81..2e46569f5a 100644 --- a/refactor/rename/rename_test.go +++ b/refactor/rename/rename_test.go @@ -659,7 +659,7 @@ func f(z interface{}) { 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 @@ func fakeContext(pkgs map[string][]string) *build.Context { 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 @@ func fakeContext(pkgs map[string][]string) *build.Context { 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 @@ func fakeContext(pkgs map[string][]string) *build.Context { 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 @@ func fakeContext(pkgs map[string][]string) *build.Context { 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 aa13908da1..f9354d869d 100644 --- a/refactor/rename/util.go +++ b/refactor/rename/util.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" "reflect" + "runtime" "strings" "unicode" @@ -81,6 +82,10 @@ func isDigit(ch rune) bool { // 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 }