summaryrefslogtreecommitdiff
path: root/src/path
diff options
context:
space:
mode:
authorAlex Brainman <alex.brainman@gmail.com>2015-09-09 10:54:25 +1000
committerAlex Brainman <alex.brainman@gmail.com>2015-10-22 04:35:50 +0000
commit72193c98248d26c92ced56e0855eac8722269aad (patch)
treefddbf4aaedc5ff2bd5391da8e189095ff93dd230 /src/path
parent5a68eb9f25a2a6290800278df972e04a4085cee3 (diff)
downloadgo-git-72193c98248d26c92ced56e0855eac8722269aad.tar.gz
path/filepath: test EvalSymlinks returns canonical path on windows
When you create C:\A.TXT file on windows, you can open it as c:\a.txt. EvalSymlinks("c:\a.txt") returns C:\A.TXT. This is all EvalSymlinks did in the past, but recently symlinks functionality been implemented on some Windows version (where symlinks are supported). So now EvalSymlinks handles both: searching for file canonical name and resolving symlinks. Unfortunately TestEvalSymlinks has not been adjusted properly. The test tests either canonical paths or symlinks, but not both. This CL separates canonical paths tests into new TestEvalSymlinksCanonicalNames, so all functionality is covered. Tests are simplified somewhat too. Also remove EvalSymlinksAbsWindowsTests - it seems not used anywhere. Change-Id: Id12e9f1441c1e30f15c523b250469978e4511a84 Reviewed-on: https://go-review.googlesource.com/14412 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/path')
-rw-r--r--src/path/filepath/path_test.go31
-rw-r--r--src/path/filepath/path_windows_test.go63
2 files changed, 68 insertions, 26 deletions
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
+ }
+ }
+}