File: io_dir.t

package info (click to toggle)
perl 5.10.1-17squeeze6
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 74,280 kB
  • ctags: 49,087
  • sloc: perl: 319,380; ansic: 193,238; sh: 37,981; pascal: 8,830; lisp: 7,515; cpp: 3,893; makefile: 2,375; xml: 1,972; yacc: 1,555
file content (75 lines) | stat: -rwxr-xr-x 1,508 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!./perl

BEGIN {
    unless(grep /blib/, @INC) {
        chdir 't' if -d 't';
        @INC = '../lib';
    }
    require Config; import Config;
    if ($] < 5.00326 || not $Config{'d_readdir'}) {
	print "1..0 # Skip: readdir() not available\n";
	exit 0;
    }

    require($ENV{PERL_CORE} ? "./test.pl" : "./t/test.pl");
    plan(16);

    use_ok('IO::Dir');
    IO::Dir->import(DIR_UNLINK);
}

use strict;

my $DIR = $^O eq 'MacOS' ? ":" : ".";

my $CLASS = "IO::Dir";
my $dot = $CLASS->new($DIR);
ok(defined($dot));

my @a = sort <*>;
my $first;
do { $first = $dot->read } while defined($first) && $first =~ /^\./;
ok(+(grep { $_ eq $first } @a));

my @b = sort($first, (grep {/^[^.]/} $dot->read));
ok(+(join("\0", @a) eq join("\0", @b)));

ok($dot->rewind,'rewind');
my @c = sort grep {/^[^.]/} $dot->read;
ok(+(join("\0", @b) eq join("\0", @c)));

ok($dot->close,'close');
{ local $^W; # avoid warnings on invalid dirhandle
ok(!$dot->rewind, "rewind on closed");
ok(!defined($dot->read));
}

open(FH,'>X') || die "Can't create x";
print FH "X";
close(FH) or die "Can't close: $!";

my %dir;
tie %dir, $CLASS, $DIR;
my @files = keys %dir;

# I hope we do not have an empty dir :-)
ok(scalar @files);

my $stat = $dir{'X'};
isa_ok($stat,'File::stat');
ok(defined($stat) && $stat->size == 1);

delete $dir{'X'};

ok(-f 'X');

my %dirx;
tie %dirx, $CLASS, $DIR, DIR_UNLINK;

my $statx = $dirx{'X'};
isa_ok($statx,'File::stat');
ok(defined($statx) && $statx->size == 1);

delete $dirx{'X'};

ok(!(-f 'X'));