1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:04:43 -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 {
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, "/")

View File

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