From 3d1afb76807fa11e56c16cb5008bc64ae5bb84c7 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Thu, 17 Mar 2011 10:41:23 +1100 Subject: path: work for windows. R=brainman, rsc, rsc1 CC=golang-dev https://golang.org/cl/4249064 --- src/pkg/path/filepath/path_test.go | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'src/pkg/path/filepath/path_test.go') diff --git a/src/pkg/path/filepath/path_test.go b/src/pkg/path/filepath/path_test.go index 8f887f00bb..c23cb6c0ec 100644 --- a/src/pkg/path/filepath/path_test.go +++ b/src/pkg/path/filepath/path_test.go @@ -68,7 +68,7 @@ var cleantests = []PathTest{ func TestClean(t *testing.T) { for _, test := range cleantests { - if s := filepath.Clean(test.path); s != test.result { + if s := filepath.ToSlash(filepath.Clean(test.path)); s != test.result { t.Errorf("Clean(%q) = %q, want %q", test.path, s, test.result) } } @@ -161,6 +161,14 @@ var jointests = []JoinTest{ {[]string{"", ""}, ""}, } +var winjointests = []JoinTest{ + {[]string{`directory`, `file`}, `directory\file`}, + {[]string{`C:\Windows\`, `System32`}, `C:\Windows\System32`}, + {[]string{`C:\Windows\`, ``}, `C:\Windows`}, + {[]string{`C:\`, `Windows`}, `C:\Windows`}, + {[]string{`C:`, `Windows`}, `C:\Windows`}, +} + // join takes a []string and passes it to Join. func join(elem []string, args ...string) string { args = elem @@ -168,8 +176,11 @@ func join(elem []string, args ...string) string { } func TestJoin(t *testing.T) { + if runtime.GOOS == "windows" { + jointests = append(jointests, winjointests...) + } for _, test := range jointests { - if p := join(test.elem); p != test.path { + if p := join(test.elem); p != filepath.FromSlash(test.path) { t.Errorf("join(%q) = %q, want %q", test.elem, p, test.path) } } @@ -261,6 +272,7 @@ func checkMarks(t *testing.T) { // Assumes that each node name is unique. Good enough for a test. func mark(name string) { + name = filepath.ToSlash(name) walkTree(tree, tree.name, func(path string, n *Node) { if n.name == name { n.mark++ @@ -302,7 +314,7 @@ func TestWalk(t *testing.T) { } checkMarks(t) - if os.Getuid() != 0 { + if os.Getuid() > 0 { // introduce 2 errors: chmod top-level directories to 0 os.Chmod(filepath.Join(tree.name, tree.entries[1].name), 0) os.Chmod(filepath.Join(tree.name, tree.entries[3].name), 0) @@ -361,7 +373,7 @@ var basetests = []PathTest{ func TestBase(t *testing.T) { for _, test := range basetests { - if s := filepath.Base(test.path); s != test.result { + if s := filepath.ToSlash(filepath.Base(test.path)); s != test.result { t.Errorf("Base(%q) = %q, want %q", test.path, s, test.result) } } @@ -372,7 +384,7 @@ type IsAbsTest struct { isAbs bool } -var isAbsTests = []IsAbsTest{ +var isabstests = []IsAbsTest{ {"", false}, {"/", true}, {"/usr/bin/gcc", true}, @@ -383,8 +395,20 @@ var isAbsTests = []IsAbsTest{ {"lala", false}, } +var winisabstests = []IsAbsTest{ + {`C:\`, true}, + {`c\`, false}, + {`c::`, false}, + {`/`, true}, + {`\`, true}, + {`\Windows`, true}, +} + func TestIsAbs(t *testing.T) { - for _, test := range isAbsTests { + if runtime.GOOS == "windows" { + isabstests = append(isabstests, winisabstests...) + } + for _, test := range isabstests { if r := filepath.IsAbs(test.path); r != test.isAbs { t.Errorf("IsAbs(%q) = %v, want %v", test.path, r, test.isAbs) } -- cgit v1.3