This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
POSIX math: s = "0" is not happy with -Wwrite-strings.
[perl5.git] / lib / DirHandle.t
... / ...
CommitLineData
1#!./perl
2
3BEGIN {
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
13use DirHandle;
14use 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.
19my $chdir;
20if ($ENV{PERL_CORE} && -d 'uni') {
21 chdir 'uni';
22 push @INC, '../../lib';
23 $chdir++;
24};
25
26$dot = DirHandle->new('.');
27
28is(defined $dot, 1);
29
30@a = sort <*>;
31do { $first = $dot->read } while defined($first) && $first =~ /^\./;
32ok(+(grep { $_ eq $first } @a));
33
34@b = sort($first, (grep {/^[^.]/} $dot->read));
35ok(+(join("\0", @a) eq join("\0", @b)));
36
37$dot->rewind;
38@c = sort grep {/^[^.]/} $dot->read;
39cmp_ok(join("\0", @b), 'eq', join("\0", @c));
40
41$dot->close;
42$dot->rewind;
43is(defined $dot->read, '');
44
45if ($chdir) {
46 chdir "..";
47}