Upgrade to Archive-Tar-1.39_04
[p5sagit/p5-mst-13.2.git] / lib / Archive / Tar / t / 05_iter.t
1 BEGIN {
2     if( $ENV{PERL_CORE} ) {
3         chdir '../lib/Archive/Tar' if -d '../lib/Archive/Tar';
4     }       
5     use lib '../../..';
6 }
7
8 BEGIN { chdir 't' if -d 't' }
9
10 use Test::More 'no_plan';
11 use strict;
12 use lib '../lib';
13
14 my $Class   = 'Archive::Tar';
15 my $FClass  = 'Archive::Tar::File';
16 my $File    = 'src/long/bar.tar';
17 my @Expect = (
18     qr|^c$|,
19     qr|^d$|,
20     qr|^directory/$|,
21     qr|^directory/really.*name/$|,
22     qr|^directory/.*/myfile$|,
23 );
24
25 use_ok( $Class );
26
27 ### crazy ref to special case 'all'
28 for my $index ( \0, 0 .. $#Expect ) {   
29
30     my %opts    = ();
31     my @expect  = ();
32     
33     ### do a full test vs individual filters
34     if( not ref $index ) {
35         my $regex       = $Expect[$index];
36         $opts{'filter'} = $regex;
37         @expect         = ($regex);
38     } else {
39         @expect         = @Expect;
40     }        
41
42     my $next = $Class->iter( $File, 0, \%opts );
43     
44     my $pp_opts = join " => ", %opts;
45     ok( $next,                  "Iterator created from $File ($pp_opts)" );
46     isa_ok( $next, "CODE",      "   Iterator" );
47
48     my @names;
49     while( my $f = $next->() ) {
50         ok( $f,                 "       File object retrieved" );
51         isa_ok( $f, $FClass,    "           Object" );
52
53         push @names, $f->name;
54     }
55     
56     is( scalar(@names), scalar(@expect),
57                                 "   Found correct number of files" );
58     
59     my $i = 0;
60     for my $name ( @names ) {
61         ok( 1,                  "   Inspecting '$name' " );
62         like($name, $expect[$i],"       Matches $Expect[$i]" );
63         $i++;
64     }        
65 }