Skip to content

Commit 74c296b

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
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 <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent b5a7f2e commit 74c296b

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

src/path/filepath/path_test.go

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"path/filepath"
1414
"reflect"
1515
"runtime"
16+
"slices"
1617
"sort"
1718
"strings"
1819
"syscall"
@@ -842,6 +843,16 @@ func TestWalkSymlinkRoot(t *testing.T) {
842843
t.Fatal(err)
843844
}
844845

846+
abslink := filepath.Join(td, "abslink")
847+
if err := os.Symlink(dir, abslink); err != nil {
848+
t.Fatal(err)
849+
}
850+
851+
linklink := filepath.Join(td, "linklink")
852+
if err := os.Symlink("link", linklink); err != nil {
853+
t.Fatal(err)
854+
}
855+
845856
// Per https://pubs.opengroup.org/onlinepubs/9699919799.2013edition/basedefs/V1_chap04.html#tag_04_12:
846857
// “A pathname that contains at least one non- <slash> character and that ends
847858
// with one or more trailing <slash> characters shall not be resolved
@@ -854,9 +865,10 @@ func TestWalkSymlinkRoot(t *testing.T) {
854865
// but if it does end in a slash, Walk should walk the directory to which the symlink
855866
// refers (since it must be fully resolved before walking).
856867
for _, tt := range []struct {
857-
desc string
858-
root string
859-
want []string
868+
desc string
869+
root string
870+
want []string
871+
buggyGOOS []string
860872
}{
861873
{
862874
desc: "no slash",
@@ -868,6 +880,27 @@ func TestWalkSymlinkRoot(t *testing.T) {
868880
root: link + string(filepath.Separator),
869881
want: []string{link, filepath.Join(link, "foo")},
870882
},
883+
{
884+
desc: "abs no slash",
885+
root: abslink,
886+
want: []string{abslink},
887+
},
888+
{
889+
desc: "abs with slash",
890+
root: abslink + string(filepath.Separator),
891+
want: []string{abslink, filepath.Join(abslink, "foo")},
892+
},
893+
{
894+
desc: "double link no slash",
895+
root: linklink,
896+
want: []string{linklink},
897+
},
898+
{
899+
desc: "double link with slash",
900+
root: linklink + string(filepath.Separator),
901+
want: []string{linklink, filepath.Join(linklink, "foo")},
902+
buggyGOOS: []string{"darwin"}, // https://go.dev/issue/59586
903+
},
871904
} {
872905
tt := tt
873906
t.Run(tt.desc, func(t *testing.T) {
@@ -885,7 +918,12 @@ func TestWalkSymlinkRoot(t *testing.T) {
885918
}
886919

887920
if !reflect.DeepEqual(walked, tt.want) {
888-
t.Errorf("Walk(%#q) visited %#q; want %#q", tt.root, walked, tt.want)
921+
t.Logf("Walk(%#q) visited %#q; want %#q", tt.root, walked, tt.want)
922+
if slices.Contains(tt.buggyGOOS, runtime.GOOS) {
923+
t.Logf("(ignoring known bug on %v)", runtime.GOOS)
924+
} else {
925+
t.Fail()
926+
}
889927
}
890928
})
891929
}

0 commit comments

Comments
 (0)