~percona-toolkit-dev/percona-toolkit/fix-log-parser-writer-bug-963225

« back to all changes in this revision

Viewing changes to t/lib/FileIterator.t

  • Committer: Daniel Nichter
  • Date: 2011-06-24 17:22:06 UTC
  • Revision ID: daniel@percona.com-20110624172206-c7q4s4ad6r260zz6
Add lib/, t/lib/, and sandbox/.  All modules are updated and passing on MySQL 5.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
BEGIN {
 
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";
 
7
};
 
8
 
 
9
use strict;
 
10
use warnings FATAL => 'all';
 
11
use English qw(-no_match_vars);
 
12
use Test::More tests => 12;
 
13
 
 
14
use FileIterator;
 
15
use MaatkitTest;
 
16
 
 
17
use constant MKDEBUG => $ENV{MKDEBUG} || 0;
 
18
 
 
19
use Data::Dumper;
 
20
$Data::Dumper::Indent    = 1;
 
21
$Data::Dumper::Sortkeys  = 1;
 
22
$Data::Dumper::Quotekeys = 0;
 
23
 
 
24
my $sample = "$trunk/t/lib/samples/";
 
25
 
 
26
my ($next_fh, $fh, $name, $size);
 
27
my $fi = new FileIterator();
 
28
isa_ok($fi, 'FileIterator');
 
29
 
 
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' );
 
39
 
 
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 "-"' );
 
46
 
 
47
# #############################################################################
 
48
# Real filenames.
 
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' );
 
60
 
 
61
# #############################################################################
 
62
# Done.
 
63
# #############################################################################
 
64
exit;