This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl5db] Refactoring.
[perl5.git] / lib / DirHandle.t
CommitLineData
c07a80fd 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
c07a80fd 6 require Config; import Config;
1b4456a8 7 if (not $Config{'d_readdir'}) {
c07a80fd 8 print "1..0\n";
9 exit 0;
10 }
11}
12
13use DirHandle;
5b88804b 14use Test::More tests => 5;
c07a80fd 15
ffe4764e
B
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.
19my $chdir;
20if ($ENV{PERL_CORE} && -d 'uni') {
21 chdir 'uni';
5b88804b 22 push @INC, '../../lib';
ffe4764e
B
23 $chdir++;
24};
25
5b88804b 26$dot = DirHandle->new('.');
95e8664e 27
5b88804b 28is(defined $dot, 1);
c07a80fd 29
1b4456a8 30@a = sort <*>;
c07a80fd 31do { $first = $dot->read } while defined($first) && $first =~ /^\./;
a3163838 32ok(+(grep { $_ eq $first } @a));
c07a80fd 33
34@b = sort($first, (grep {/^[^.]/} $dot->read));
a3163838 35ok(+(join("\0", @a) eq join("\0", @b)));
c07a80fd 36
37$dot->rewind;
38@c = sort grep {/^[^.]/} $dot->read;
5b88804b 39cmp_ok(join("\0", @b), 'eq', join("\0", @c));
c07a80fd 40
41$dot->close;
42$dot->rewind;
5b88804b 43is(defined $dot->read, '');
ffe4764e
B
44
45if ($chdir) {
46 chdir "..";
47}