summaryrefslogtreecommitdiff
path: root/libgo/go/path/filepath/path_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/path/filepath/path_test.go')
-rw-r--r--libgo/go/path/filepath/path_test.go57
1 files changed, 55 insertions, 2 deletions
diff --git a/libgo/go/path/filepath/path_test.go b/libgo/go/path/filepath/path_test.go
index 7389ea29a48..f2e92528a96 100644
--- a/libgo/go/path/filepath/path_test.go
+++ b/libgo/go/path/filepath/path_test.go
@@ -6,12 +6,14 @@ package filepath_test
import (
"errors"
+ "fmt"
"internal/testenv"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"runtime"
+ "sort"
"strings"
"testing"
)
@@ -389,7 +391,7 @@ func checkMarks(t *testing.T, report bool) {
// Assumes that each node name is unique. Good enough for a test.
// If clear is true, any incoming error is cleared before return. The errors
// are always accumulated, though.
-func mark(path string, info os.FileInfo, err error, errors *[]error, clear bool) error {
+func mark(info os.FileInfo, err error, errors *[]error, clear bool) error {
if err != nil {
*errors = append(*errors, err)
if clear {
@@ -438,7 +440,7 @@ func TestWalk(t *testing.T) {
errors := make([]error, 0, 10)
clear := true
markFn := func(path string, info os.FileInfo, err error) error {
- return mark(path, info, err, &errors, clear)
+ return mark(info, err, &errors, clear)
}
// Expect no errors.
err := filepath.Walk(tree.name, markFn)
@@ -668,6 +670,7 @@ var windirtests = []PathTest{
{`c:\a\b`, `c:\a`},
{`c:a\b`, `c:a`},
{`c:a\b\c`, `c:a\b`},
+ {`\\host\share`, `\\host\share`},
{`\\host\share\`, `\\host\share\`},
{`\\host\share\a`, `\\host\share\`},
{`\\host\share\a\b`, `\\host\share\a`},
@@ -1330,3 +1333,53 @@ func TestBug3486(t *testing.T) { // https://golang.org/issue/3486
t.Fatalf("%q not seen", ken)
}
}
+
+func testWalkSymlink(t *testing.T, mklink func(target, link string) error) {
+ tmpdir, err := ioutil.TempDir("", "testWalkSymlink")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer os.RemoveAll(tmpdir)
+
+ wd, err := os.Getwd()
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer os.Chdir(wd)
+
+ err = os.Chdir(tmpdir)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = mklink(tmpdir, "link")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ var visited []string
+ err = filepath.Walk(tmpdir, func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ t.Fatal(err)
+ }
+ rel, err := filepath.Rel(tmpdir, path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ visited = append(visited, rel)
+ return nil
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+ sort.Strings(visited)
+ want := []string{".", "link"}
+ if fmt.Sprintf("%q", visited) != fmt.Sprintf("%q", want) {
+ t.Errorf("unexpected paths visited %q, want %q", visited, want)
+ }
+}
+
+func TestWalkSymlink(t *testing.T) {
+ testenv.MustHaveSymlink(t)
+ testWalkSymlink(t, os.Symlink)
+}