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;
42 if(!$Config::Config{d_fchdir} && $^O ne "MSWin32") {
43 $::TODO = 'dir handle cloning currently requires fchdir on non-Windows platforms';
46 my @w :shared; # warnings accumulator
47 local $SIG{__WARN__} = sub { push @w, $_[0] };
49 $dir = catdir getcwd(), "thrext$$" . int rand() * 100000;
54 # Create a dir structure like this:
68 {open my $fh, ">thrit" or &$skip("Cannot create file thrit")}
69 {open my $fh, ">rile" or &$skip("Cannot create file rile")}
70 {open my $fh, ">zor" or &$skip("Cannot create file zor")}
73 # Then test that dir iterators are cloned correctly.
75 opendir my $toberead, 'toberead';
76 my $start_pos = telldir $toberead;
77 my @first_2 = (scalar readdir $toberead, scalar readdir $toberead);
78 my @from_thread = @{; async { [readdir $toberead ] } ->join };
79 my @from_main = readdir $toberead;
80 is join('-', sort @from_thread), join('-', sort @from_main),
81 'dir iterator is copied from one thread to another';
83 join('-', "", sort(@first_2, @from_thread), ""),
84 qr/(?<!-rile)-rile-thrit-zor-(?!zor-)/i,
85 'cloned iterator iterates exactly once over everything not already seen';
87 seekdir $toberead, $start_pos;
88 readdir $toberead for 1 .. @first_2+@from_thread;
90 local $::TODO; # This always passes when dir handles are not cloned.
92 async { readdir $toberead // 'undef' } ->join, 'undef',
93 'cloned dir iterator that points to the end of the directory'
97 # Make sure the cloning code can handle file names longer than 255 chars
101 ">floccipaucinihilopilification-"
102 . "pneumonoultramicroscopicsilicovolcanoconiosis-"
103 . "lopadotemachoselachogaleokranioleipsanodrimypotrimmatosilphiokarabo"
104 . "melitokatakechymenokichlepikossyphophattoperisteralektryonoptokephal"
105 . "liokinklopeleiolagoiosiraiobaphetraganopterygon"
108 skip("OS does not support long file names (and I mean *long*)", 1);
110 opendir my $dirh, "toberead";
112 = "dir iterators can be cloned when the next fn > 255 chars";
114 my $pos = telldir $dirh;
115 my $fn = readdir($dirh);
116 if(!defined $fn) { fail($test_name); last SKIP; }
117 if($fn =~ 'lagoio') {
122 is length async { scalar readdir $dirh } ->join, 258, $test_name;
125 is scalar @w, 0, 'no warnings during all that' or diag @w;