@@ -13,6 +13,7 @@ import (
13
13
"path/filepath"
14
14
"reflect"
15
15
"runtime"
16
+ "slices"
16
17
"sort"
17
18
"strings"
18
19
"syscall"
@@ -842,6 +843,16 @@ func TestWalkSymlinkRoot(t *testing.T) {
842
843
t .Fatal (err )
843
844
}
844
845
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
+
845
856
// Per https://pubs.opengroup.org/onlinepubs/9699919799.2013edition/basedefs/V1_chap04.html#tag_04_12:
846
857
// “A pathname that contains at least one non- <slash> character and that ends
847
858
// with one or more trailing <slash> characters shall not be resolved
@@ -854,9 +865,10 @@ func TestWalkSymlinkRoot(t *testing.T) {
854
865
// but if it does end in a slash, Walk should walk the directory to which the symlink
855
866
// refers (since it must be fully resolved before walking).
856
867
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
860
872
}{
861
873
{
862
874
desc : "no slash" ,
@@ -868,6 +880,27 @@ func TestWalkSymlinkRoot(t *testing.T) {
868
880
root : link + string (filepath .Separator ),
869
881
want : []string {link , filepath .Join (link , "foo" )},
870
882
},
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
+ },
871
904
} {
872
905
tt := tt
873
906
t .Run (tt .desc , func (t * testing.T ) {
@@ -885,7 +918,12 @@ func TestWalkSymlinkRoot(t *testing.T) {
885
918
}
886
919
887
920
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
+ }
889
927
}
890
928
})
891
929
}
0 commit comments