1b39c5158SmillertBEGIN { chdir 't' if -d 't' } 2b39c5158Smillert 3*256a93a4Safresh1use Test::More; 4b39c5158Smillertuse strict; 5b39c5158Smillertuse lib '../lib'; 6b39c5158Smillert 7*256a93a4Safresh1plan skip_all => "File contains an alien character set" if ord "A" != 65; 8*256a93a4Safresh1 9b39c5158Smillertmy $Class = 'Archive::Tar'; 10b39c5158Smillertmy $FClass = 'Archive::Tar::File'; 11b39c5158Smillertmy $File = 'src/long/bar.tar'; 12b39c5158Smillertmy @Expect = ( 13b39c5158Smillert qr|^c$|, 14b39c5158Smillert qr|^d$|, 15b39c5158Smillert qr|^directory/$|, 16b39c5158Smillert qr|^directory/really.*name/$|, 17b39c5158Smillert qr|^directory/.*/myfile$|, 18b39c5158Smillert); 19b39c5158Smillert 20b39c5158Smillertuse_ok( $Class ); 21b39c5158Smillert 22b39c5158Smillert### crazy ref to special case 'all' 23b39c5158Smillertfor my $index ( \0, 0 .. $#Expect ) { 24b39c5158Smillert 25b39c5158Smillert my %opts = (); 26b39c5158Smillert my @expect = (); 27b39c5158Smillert 28898184e3Ssthen my $dotest = sub { 29898184e3Ssthen my $desc = shift; 30b39c5158Smillert my $next = $Class->iter( $File, 0, \%opts ); 31b39c5158Smillert 32b39c5158Smillert my $pp_opts = join " => ", %opts; 33898184e3Ssthen ok( $next, "Iterator created from $File ($pp_opts $desc)" ); 34898184e3Ssthen isa_ok( $next, "CODE", " Iterator $desc" ); 35b39c5158Smillert 36b39c5158Smillert my @names; 37b39c5158Smillert while( my $f = $next->() ) { 38898184e3Ssthen ok( $f, " File object retrieved $desc" ); 39898184e3Ssthen isa_ok( $f, $FClass, " Object $desc" ); 40b39c5158Smillert 41b39c5158Smillert push @names, $f->name; 42b39c5158Smillert } 43b39c5158Smillert 44b39c5158Smillert is( scalar(@names), scalar(@expect), 45898184e3Ssthen " Found correct number of files $desc" ); 46b39c5158Smillert 47b39c5158Smillert my $i = 0; 48b39c5158Smillert for my $name ( @names ) { 49898184e3Ssthen ok( 1, " Inspecting '$name' $desc" ); 50898184e3Ssthen like($name, $expect[$i]," Matches $Expect[$i] $desc" ); 51b39c5158Smillert $i++; 52b39c5158Smillert } 53898184e3Ssthen }; 54898184e3Ssthen 55898184e3Ssthen ### do a full test vs individual filters 56898184e3Ssthen if( not ref $index ) { 57898184e3Ssthen my $regex = $Expect[$index]; 58898184e3Ssthen @expect = ($regex); 59898184e3Ssthen %opts = ( filter => $regex ); 60898184e3Ssthen $dotest->("filter $regex"); 61898184e3Ssthen %opts = ( filter_cb => sub { my ($entry) = @_; $entry->name() =~ /$regex/ } ); 62898184e3Ssthen $dotest->("filter_cb $regex"); 63898184e3Ssthen } else { 64898184e3Ssthen @expect = @Expect; 65898184e3Ssthen $dotest->("all"); 66898184e3Ssthen } 67b39c5158Smillert} 68*256a93a4Safresh1 69*256a93a4Safresh1done_testing; 70