From: Bryan C. Mills Date: Thu, 13 Apr 2023 14:48:35 +0000 (+0000) Subject: path/filepath: add test cases for walking a symlink-to-symlink-to-dir X-Git-Tag: go1.21rc1~910 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=74c296b69ffe07322b4bb42d7d2afe5f76ccf6ad;p=gostls13.git 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 Run-TryBot: Bryan Mills Auto-Submit: Bryan Mills Reviewed-by: Ian Lance Taylor --- 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- character and that ends // with one or more trailing 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() + } } }) }