aboutsummaryrefslogtreecommitdiff
path: root/src/path
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2023-04-13 14:48:35 +0000
committerGopher Robot <gobot@golang.org>2023-04-13 17:46:03 +0000
commit74c296b69ffe07322b4bb42d7d2afe5f76ccf6ad (patch)
tree847fc98e3318b5e029b09c725187aca1286fa80b /src/path
parentb5a7f2eef7cb17255cb396cd4ff7df04957dd21e (diff)
downloadgo-74c296b69ffe07322b4bb42d7d2afe5f76ccf6ad.tar.gz
go-74c296b69ffe07322b4bb42d7d2afe5f76ccf6ad.zip
path/filepath: add test cases for walking a symlink-to-symlink-to-dir
The "double link with slash" test is skipped on darwin due to an apparent kernel / libc bug. If the bug is present on other platforms too, I'd like to know about it. For #59586. Change-Id: I4bdd6a80a3ed7b0960ea6da30f91a655f317d512 Reviewed-on: https://go-review.googlesource.com/c/go/+/484395 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/path')
-rw-r--r--src/path/filepath/path_test.go46
1 files changed, 42 insertions, 4 deletions
diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go
index cfc5cad863..aed8cc8383 100644
--- a/src/path/filepath/path_test.go
+++ b/src/path/filepath/path_test.go
@@ -13,6 +13,7 @@ import (
"path/filepath"
"reflect"
"runtime"
+ "slices"
"sort"
"strings"
"syscall"
@@ -842,6 +843,16 @@ func TestWalkSymlinkRoot(t *testing.T) {
t.Fatal(err)
}
+ abslink := filepath.Join(td, "abslink")
+ if err := os.Symlink(dir, abslink); err != nil {
+ t.Fatal(err)
+ }
+
+ linklink := filepath.Join(td, "linklink")
+ if err := os.Symlink("link", linklink); err != nil {
+ t.Fatal(err)
+ }
+
// Per https://pubs.opengroup.org/onlinepubs/9699919799.2013edition/basedefs/V1_chap04.html#tag_04_12:
// “A pathname that contains at least one non- <slash> character and that ends
// with one or more trailing <slash> characters shall not be resolved
@@ -854,9 +865,10 @@ func TestWalkSymlinkRoot(t *testing.T) {
// but if it does end in a slash, Walk should walk the directory to which the symlink
// refers (since it must be fully resolved before walking).
for _, tt := range []struct {
- desc string
- root string
- want []string
+ desc string
+ root string
+ want []string
+ buggyGOOS []string
}{
{
desc: "no slash",
@@ -868,6 +880,27 @@ func TestWalkSymlinkRoot(t *testing.T) {
root: link + string(filepath.Separator),
want: []string{link, filepath.Join(link, "foo")},
},
+ {
+ desc: "abs no slash",
+ root: abslink,
+ want: []string{abslink},
+ },
+ {
+ desc: "abs with slash",
+ root: abslink + string(filepath.Separator),
+ want: []string{abslink, filepath.Join(abslink, "foo")},
+ },
+ {
+ desc: "double link no slash",
+ root: linklink,
+ want: []string{linklink},
+ },
+ {
+ desc: "double link with slash",
+ root: linklink + string(filepath.Separator),
+ want: []string{linklink, filepath.Join(linklink, "foo")},
+ buggyGOOS: []string{"darwin"}, // https://go.dev/issue/59586
+ },
} {
tt := tt
t.Run(tt.desc, func(t *testing.T) {
@@ -885,7 +918,12 @@ func TestWalkSymlinkRoot(t *testing.T) {
}
if !reflect.DeepEqual(walked, tt.want) {
- t.Errorf("Walk(%#q) visited %#q; want %#q", tt.root, walked, tt.want)
+ t.Logf("Walk(%#q) visited %#q; want %#q", tt.root, walked, tt.want)
+ if slices.Contains(tt.buggyGOOS, runtime.GOOS) {
+ t.Logf("(ignoring known bug on %v)", runtime.GOOS)
+ } else {
+ t.Fail()
+ }
}
})
}