aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/path/filepath/path_test.go
diff options
context:
space:
mode:
authorYasuhiro Matsumoto <mattn.jp@gmail.com>2011-03-17 10:41:23 +1100
committerAlex Brainman <alex.brainman@gmail.com>2011-03-17 10:41:23 +1100
commit3d1afb76807fa11e56c16cb5008bc64ae5bb84c7 (patch)
tree44d35e5051f844cb9532f41272eaec3d9c2de68b /src/pkg/path/filepath/path_test.go
parent4bd0a544350568e28a49843e7311a8b04517a60f (diff)
downloadgo-3d1afb76807fa11e56c16cb5008bc64ae5bb84c7.tar.xz
path: work for windows.
R=brainman, rsc, rsc1 CC=golang-dev https://golang.org/cl/4249064
Diffstat (limited to 'src/pkg/path/filepath/path_test.go')
-rw-r--r--src/pkg/path/filepath/path_test.go36
1 files changed, 30 insertions, 6 deletions
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)
}