1
0
mirror of https://github.com/golang/go synced 2024-11-18 13:44:48 -07:00

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
This commit is contained in:
Alex Brainman 2014-10-23 09:45:47 +11:00
parent d183041bb0
commit 181e280a22
2 changed files with 10 additions and 1 deletions

View File

@ -659,7 +659,7 @@ func f(z interface{}) {
if err := format.Node(&out, fset, f); err != nil { if err := format.Node(&out, fset, f); err != nil {
return err return err
} }
got[orig] = out.String() got[filepath.ToSlash(orig)] = out.String()
return nil return nil
} }
@ -707,6 +707,7 @@ func fakeContext(pkgs map[string][]string) *build.Context {
ctxt.GOROOT = "/go" ctxt.GOROOT = "/go"
ctxt.GOPATH = "" ctxt.GOPATH = ""
ctxt.IsDir = func(path string) bool { ctxt.IsDir = func(path string) bool {
path = filepath.ToSlash(path)
if path == "/go/src" { if path == "/go/src" {
return true // needed by (*build.Context).SrcDirs return true // needed by (*build.Context).SrcDirs
} }
@ -719,6 +720,7 @@ func fakeContext(pkgs map[string][]string) *build.Context {
return ok return ok
} }
ctxt.ReadDir = func(dir string) ([]os.FileInfo, error) { ctxt.ReadDir = func(dir string) ([]os.FileInfo, error) {
dir = filepath.ToSlash(dir)
dir = dir[len("/go/src/"):] dir = dir[len("/go/src/"):]
var fis []os.FileInfo var fis []os.FileInfo
if dir == "" { if dir == "" {
@ -734,6 +736,7 @@ func fakeContext(pkgs map[string][]string) *build.Context {
return fis, nil return fis, nil
} }
ctxt.OpenFile = func(path string) (io.ReadCloser, error) { ctxt.OpenFile = func(path string) (io.ReadCloser, error) {
path = filepath.ToSlash(path)
path = path[len("/go/src/"):] path = path[len("/go/src/"):]
dir, base := filepath.Split(path) dir, base := filepath.Split(path)
dir = filepath.Clean(dir) 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 return ioutil.NopCloser(bytes.NewBufferString(pkgs[dir][index])), nil
} }
ctxt.IsAbsPath = func(path string) bool { ctxt.IsAbsPath = func(path string) bool {
path = filepath.ToSlash(path)
// Don't rely on the default (filepath.Path) since on // Don't rely on the default (filepath.Path) since on
// Windows, it reports our virtual paths as non-absolute. // Windows, it reports our virtual paths as non-absolute.
return strings.HasPrefix(path, "/") return strings.HasPrefix(path, "/")

View File

@ -8,6 +8,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"runtime"
"strings" "strings"
"unicode" "unicode"
@ -81,6 +82,10 @@ func isDigit(ch rune) bool {
// the same file. // the same file.
// //
func sameFile(x, y string) bool { func sameFile(x, y string) bool {
if runtime.GOOS == "windows" {
x = filepath.ToSlash(x)
y = filepath.ToSlash(y)
}
if x == y { if x == y {
return true return true
} }