4
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
5
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
6
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
10
use warnings FATAL => 'all';
11
use English qw(-no_match_vars);
12
use Test::More tests => 12;
17
use constant MKDEBUG => $ENV{MKDEBUG} || 0;
20
$Data::Dumper::Indent = 1;
21
$Data::Dumper::Sortkeys = 1;
22
$Data::Dumper::Quotekeys = 0;
24
my $sample = "$trunk/t/lib/samples/";
26
my ($next_fh, $fh, $name, $size);
27
my $fi = new FileIterator();
28
isa_ok($fi, 'FileIterator');
30
# #############################################################################
31
# Empty list of filenames.
32
# #############################################################################
33
$next_fh = $fi->get_file_itr(qw());
34
is( ref $next_fh, 'CODE', 'get_file_itr() returns a subref' );
35
( $fh, $name, $size ) = $next_fh->();
36
is( "$fh", '*main::STDIN', 'Got STDIN for empty list' );
37
is( $name, undef, 'STDIN has no name' );
38
is( $size, undef, 'STDIN has no size' );
40
# #############################################################################
41
# Magical '-' filename.
42
# #############################################################################
43
$next_fh = $fi->get_file_itr(qw(-));
44
( $fh, $name, $size ) = $next_fh->();
45
is( "$fh", '*main::STDIN', 'Got STDIN for "-"' );
47
# #############################################################################
49
# #############################################################################
50
$next_fh = $fi->get_file_itr("$sample/memcached/memc_tcpdump009.txt", "$sample/empty");
51
( $fh, $name, $size ) = $next_fh->();
52
is( ref $fh, 'GLOB', 'Open filehandle' );
53
is( $name, "$sample/memcached/memc_tcpdump009.txt", "Got filename for $name");
54
is( $size, 587, "Got size for $name");
55
( $fh, $name, $size ) = $next_fh->();
56
is( $name, "$sample/empty", "Got filename for $name");
57
is( $size, 0, "Got size for $name");
58
( $fh, $name, $size ) = $next_fh->();
59
is( $fh, undef, 'Ran off the end of the list' );
61
# #############################################################################
63
# #############################################################################