| 1 | #!./perl |
| 2 | |
| 3 | BEGIN { |
| 4 | chdir 't' if -d 't'; |
| 5 | @INC = '../lib'; |
| 6 | require './test.pl'; |
| 7 | } |
| 8 | |
| 9 | use strict; |
| 10 | use warnings; |
| 11 | use vars qw($fh @fh %fh); |
| 12 | |
| 13 | eval 'opendir(NOSUCH, "no/such/directory");'; |
| 14 | skip_all($@) if $@; |
| 15 | |
| 16 | for my $i (1..2000) { |
| 17 | local *OP; |
| 18 | opendir(OP, "op") or die "can't opendir: $!"; |
| 19 | # should auto-closedir() here |
| 20 | } |
| 21 | |
| 22 | is(opendir(OP, "op"), 1); |
| 23 | my @D = grep(/^[^\.].*\.t$/i, readdir(OP)); |
| 24 | closedir(OP); |
| 25 | |
| 26 | my $expect; |
| 27 | { |
| 28 | open my $man, '<', '../MANIFEST' or die "Can't open ../MANIFEST: $!"; |
| 29 | while (<$man>) { |
| 30 | ++$expect if m!^t/op/[^/]+\t!; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | my ($min, $max) = ($expect - 10, $expect + 10); |
| 35 | within(scalar @D, $expect, 10, 'counting op/*.t'); |
| 36 | |
| 37 | my @R = sort @D; |
| 38 | my @G = sort <op/*.t>; |
| 39 | if ($G[0] =~ m#.*\](\w+\.t)#i) { |
| 40 | # grep is to convert filespecs returned from glob under VMS to format |
| 41 | # identical to that returned by readdir |
| 42 | @G = grep(s#.*\](\w+\.t).*#op/$1#i,<op/*.t>); |
| 43 | } |
| 44 | while (@R && @G && $G[0] eq 'op/'.$R[0]) { |
| 45 | shift(@R); |
| 46 | shift(@G); |
| 47 | } |
| 48 | is(scalar @R, 0, 'readdir results all accounted for'); |
| 49 | is(scalar @G, 0, 'glob results all accounted for'); |
| 50 | |
| 51 | is(opendir($fh, "op"), 1); |
| 52 | is(ref $fh, 'GLOB'); |
| 53 | is(opendir($fh[0], "op"), 1); |
| 54 | is(ref $fh[0], 'GLOB'); |
| 55 | is(opendir($fh{abc}, "op"), 1); |
| 56 | is(ref $fh{abc}, 'GLOB'); |
| 57 | isnt("$fh", "$fh[0]"); |
| 58 | isnt("$fh", "$fh{abc}"); |
| 59 | |
| 60 | # See that perl does not segfault upon readdir($x="."); |
| 61 | # http://rt.perl.org/rt3/Ticket/Display.html?id=68182 |
| 62 | fresh_perl_like(<<'EOP', qr/^no crash/, {}, 'RT #68182'); |
| 63 | eval { |
| 64 | my $x = "."; |
| 65 | my @files = readdir($x); |
| 66 | }; |
| 67 | print "no crash"; |
| 68 | EOP |
| 69 | |
| 70 | done_testing(); |