3 # Test interaction of threads and directory handles.
12 skip_all_without_config('useithreads');
13 skip_all_if_miniperl("no dynamic loading on miniperl, no threads");
23 use File::Spec::Functions qw 'updir catdir';
26 # Basic sanity check: make sure this does not crash
27 fresh_perl_is <<'# this is no comment', 'ok', {}, 'crash when duping dirh';
30 async{}->join for 1..2;
36 skip "telldir or seekdir not defined on this platform", 5
37 if !$Config::Config{d_telldir} || !$Config::Config{d_seekdir};
44 if(!$Config::Config{d_fchdir} && $^O ne "MSWin32") {
45 $::TODO = 'dir handle cloning currently requires fchdir on non-Windows platforms';
48 my @w :shared; # warnings accumulator
49 local $SIG{__WARN__} = sub { push @w, $_[0] };
51 $dir = catdir getcwd(), "thrext$$" . int rand() * 100000;
56 # Create a dir structure like this:
70 {open my $fh, ">thrit" or &$skip("Cannot create file thrit")}
71 {open my $fh, ">rile" or &$skip("Cannot create file rile")}
72 {open my $fh, ">zor" or &$skip("Cannot create file zor")}
75 # Then test that dir iterators are cloned correctly.
77 opendir my $toberead, 'toberead';
78 my $start_pos = telldir $toberead;
79 my @first_2 = (scalar readdir $toberead, scalar readdir $toberead);
80 my @from_thread = @{; async { [readdir $toberead ] } ->join };
81 my @from_main = readdir $toberead;
82 is join('-', sort @from_thread), join('-', sort @from_main),
83 'dir iterator is copied from one thread to another';
85 join('-', "", sort(@first_2, @from_thread), ""),
86 qr/(?<!-rile)-rile-thrit-zor-(?!zor-)/i,
87 'cloned iterator iterates exactly once over everything not already seen';
89 seekdir $toberead, $start_pos;
90 readdir $toberead for 1 .. @first_2+@from_thread;
92 local $::TODO; # This always passes when dir handles are not cloned.
94 async { readdir $toberead // 'undef' } ->join, 'undef',
95 'cloned dir iterator that points to the end of the directory'
99 # Make sure the cloning code can handle file names longer than 255 chars
103 ">floccipaucinihilopilification-"
104 . "pneumonoultramicroscopicsilicovolcanoconiosis-"
105 . "lopadotemachoselachogaleokranioleipsanodrimypotrimmatosilphiokarabo"
106 . "melitokatakechymenokichlepikossyphophattoperisteralektryonoptokephal"
107 . "liokinklopeleiolagoiosiraiobaphetraganopterygon"
110 skip("OS does not support long file names (and I mean *long*)", 1);
112 opendir my $dirh, "toberead";
114 = "dir iterators can be cloned when the next fn > 255 chars";
116 my $pos = telldir $dirh;
117 my $fn = readdir($dirh);
118 if(!defined $fn) { fail($test_name); last SKIP; }
119 if($fn =~ 'lagoio') {
124 is length async { scalar readdir $dirh } ->join, 258, $test_name;
127 is scalar @w, 0, 'no warnings during all that' or diag @w;