This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix deparsing of glob(my $x) and CORE::glob
[perl5.git] / lib / DirHandle.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     require Config; import Config;
7     if (not $Config{'d_readdir'}) {
8         print "1..0\n";
9         exit 0;
10     }
11 }
12
13 use DirHandle;
14 use Test::More tests => 5;
15
16 # Fetching the list of files in two different ways and expecting them 
17 # to be the same is a race condition when tests are running in parallel.
18 # So go somewhere quieter.
19 my $chdir;
20 if ($ENV{PERL_CORE} && -d 'uni') {
21   chdir 'uni';
22   push @INC, '../../lib';
23   $chdir++;
24 };
25
26 $dot = DirHandle->new('.');
27
28 is(defined $dot, 1);
29
30 @a = sort <*>;
31 do { $first = $dot->read } while defined($first) && $first =~ /^\./;
32 ok(+(grep { $_ eq $first } @a));
33
34 @b = sort($first, (grep {/^[^.]/} $dot->read));
35 ok(+(join("\0", @a) eq join("\0", @b)));
36
37 $dot->rewind;
38 @c = sort grep {/^[^.]/} $dot->read;
39 cmp_ok(join("\0", @b), 'eq', join("\0", @c));
40
41 $dot->close;
42 $dot->rewind;
43 is(defined $dot->read, '');
44
45 if ($chdir) {
46   chdir "..";
47 }