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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
use strict;
use warnings;
use Test::More tests => 4;
use File::Temp qw( tempdir );
use File::Spec;
use Archive::Ar;
my $dir = tempdir( CLEANUP => 1 );
my $fn = File::Spec->catfile($dir, 'foo.ar');
note "fn = $fn";
my $content = do {local $/ = undef; <DATA>};
open my $fh, '>', $fn or die "$fn: $!\n";
binmode $fh;
print $fh $content;
close $fh;
my $filenames = [ qw(foo.txt bar.txt baz.txt) ];
subtest 'filename' => sub {
plan tests => 3;
my $ar = Archive::Ar->new($fn);
isa_ok $ar, 'Archive::Ar';
is_deeply scalar $ar->list_files, $filenames, "scalar context";
is_deeply [$ar->list_files], $filenames, "list context";
};
subtest 'glob' => sub {
plan tests => 3;
open my $fh, '<', $fn;
my $ar = Archive::Ar->new($fh);
isa_ok $ar, 'Archive::Ar';
is_deeply scalar $ar->list_files, $filenames, "scalar context";
is_deeply [$ar->list_files], $filenames, "list context";
};
subtest 'memory' => sub {
plan tests => 4;
open my $fh, '<', $fn;
my $data = do { local $/ = undef; <$fh> };
close $fh;
my $ar = Archive::Ar->new;
isa_ok $ar, 'Archive::Ar';
is $ar->read_memory($data), 242, "size matches";
is_deeply scalar $ar->list_files, $filenames, "scalar context";
is_deeply [$ar->list_files], $filenames, "list context";
};
subtest 'rename' => sub {
plan tests => 6;
open my $fh, '<', $fn;
my $data = do { local $/ = undef; <$fh> };
close $fh;
my $ar = Archive::Ar->new;
isa_ok $ar, 'Archive::Ar';
is $ar->read_memory($data), 242, "size matches";
my $renames = $filenames;
$renames->[1] = 'goo.txt';
$ar->rename('bar.txt', 'goo.txt');
is_deeply scalar $ar->list_files, $filenames, "scalar context";
is_deeply [$ar->list_files], $filenames, "list context";
$renames->[2] = 'zoo.txt';
$ar->rename('baz.txt', 'zoo.txt');
is_deeply scalar $ar->list_files, $filenames, "scalar context";
is_deeply [$ar->list_files], $filenames, "list context";
};
__DATA__
!<arch>
foo.txt 1384344423 1000 1000 100644 9 `
hi there
bar.txt 1384344423 1000 1000 100644 31 `
this is the content of bar.txt
baz.txt 1384344423 1000 1000 100644 11 `
and again.
|