diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go index 1a5993e96e..b0c37b0f4c 100644 --- a/src/path/filepath/path_test.go +++ b/src/path/filepath/path_test.go @@ -752,10 +752,6 @@ var EvalSymlinksTests = []EvalSymlinksTest{ {"test/linkabs", "/"}, } -var EvalSymlinksAbsWindowsTests = []EvalSymlinksTest{ - {`c:\`, `c:\`}, -} - // simpleJoin builds a file name from the directory and path. // It does not use Join because we don't want ".." to be evaluated. func simpleJoin(dir, path string) string { @@ -767,6 +763,9 @@ func TestEvalSymlinks(t *testing.T) { case "android", "nacl", "plan9": t.Skipf("skipping on %s", runtime.GOOS) } + if !supportsSymlinks { + t.Skip("skipping because symlinks are not supported") + } tmpDir, err := ioutil.TempDir("", "evalsymlink") if err != nil { @@ -788,35 +787,15 @@ func TestEvalSymlinks(t *testing.T) { if d.dest == "" { err = os.Mkdir(path, 0755) } else { - if supportsSymlinks { - err = os.Symlink(d.dest, path) - } + err = os.Symlink(d.dest, path) } if err != nil { t.Fatal(err) } } - var tests []EvalSymlinksTest - if supportsSymlinks { - tests = EvalSymlinksTests - } else { - for _, d := range EvalSymlinksTests { - if d.path == d.dest { - // will test only real files and directories - tests = append(tests, d) - // test "canonical" names - d2 := EvalSymlinksTest{ - path: strings.ToUpper(d.path), - dest: d.dest, - } - tests = append(tests, d2) - } - } - } - // Evaluate the symlink farm. - for _, d := range tests { + for _, d := range EvalSymlinksTests { path := simpleJoin(tmpDir, d.path) dest := simpleJoin(tmpDir, d.dest) if filepath.IsAbs(d.dest) || os.IsPathSeparator(d.dest[0]) { diff --git a/src/path/filepath/path_windows_test.go b/src/path/filepath/path_windows_test.go index 100cf30a45..255c894852 100644 --- a/src/path/filepath/path_windows_test.go +++ b/src/path/filepath/path_windows_test.go @@ -10,6 +10,7 @@ import ( "os/exec" "path/filepath" "reflect" + "strings" "syscall" "testing" ) @@ -111,3 +112,65 @@ func testWinSplitListTestIsValid(t *testing.T, ti int, tt SplitListTest, } } } + +// TestEvalSymlinksCanonicalNames verify that EvalSymlinks +// returns "canonical" path names on windows. +func TestEvalSymlinksCanonicalNames(t *testing.T) { + tmp, err := ioutil.TempDir("", "evalsymlinkcanonical") + if err != nil { + t.Fatal("creating temp dir:", err) + } + defer os.RemoveAll(tmp) + + // ioutil.TempDir might return "non-canonical" name. + cTmpName, err := filepath.EvalSymlinks(tmp) + if err != nil { + t.Errorf("EvalSymlinks(%q) error: %v", tmp, err) + } + + dirs := []string{ + "test", + "test/dir", + "testing_long_dir", + "TEST2", + } + + for _, d := range dirs { + dir := filepath.Join(cTmpName, d) + err := os.Mkdir(dir, 0755) + if err != nil { + t.Fatal(err) + } + cname, err := filepath.EvalSymlinks(dir) + if err != nil { + t.Errorf("EvalSymlinks(%q) error: %v", dir, err) + continue + } + if dir != cname { + t.Errorf("EvalSymlinks(%q) returns %q, but should return %q", dir, cname, dir) + continue + } + // test non-canonical names + test := strings.ToUpper(dir) + p, err := filepath.EvalSymlinks(test) + if err != nil { + t.Errorf("EvalSymlinks(%q) error: %v", test, err) + continue + } + if p != cname { + t.Errorf("EvalSymlinks(%q) returns %q, but should return %q", test, p, cname) + continue + } + // another test + test = strings.ToLower(dir) + p, err = filepath.EvalSymlinks(test) + if err != nil { + t.Errorf("EvalSymlinks(%q) error: %v", test, err) + continue + } + if p != cname { + t.Errorf("EvalSymlinks(%q) returns %q, but should return %q", test, p, cname) + continue + } + } +}