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
|
#####################################
# Tests for Sysadm::Install/s untar()
#####################################
use Test::More;
use Sysadm::Install qw(:all);
use File::Spec;
use File::Path;
#use Log::Log4perl qw(:easy);
#Log::Log4perl->easy_init($DEBUG);
BEGIN {
eval {
require Archive::Tar;
};
if ($@) {
plan skip_all => "Skipping Archive::Tar tests (not installed)";
} else {
plan tests => 9;
}
}
my $TEST_DIR = ".";
$TEST_DIR = "t" if -d 't';
#####################################################################
# Test unzipped tar
#####################################################################
my $tarfile = File::Spec->catfile($TEST_DIR, "canned", "test.tar");
untar($tarfile);
ok(-d "test", "Untarred directory 'test' exists");
is(readfile("test/a"), "file-a\n", "Testing file a in tar archive");
is(readfile("test/b"), "file-b\n", "Testing file b in tar archive");
##############
sub readfile {
##############
open FILE, "<$_[0]" or die "Cannot open $_[0]";
my $data = join '', <FILE>;
close FILE;
return $data;
}
rmtree "test";
#####################################################################
# Test zipped tar
#####################################################################
$tarfile = File::Spec->catfile($TEST_DIR, "canned", "test.tar");
untar($tarfile);
ok(-d "test", "Untarred directory 'test' exists");
is(readfile("test/a"), "file-a\n", "Testing file a in tar archive");
is(readfile("test/b"), "file-b\n", "Testing file b in tar archive");
rmtree "test";
#####################################################################
# Test zipped tar with different top dir
#####################################################################
$tarfile = File::Spec->catfile($TEST_DIR, "canned", "testa.tar");
untar($tarfile);
ok(-d "testa", "Untarred directory 'testa' exists");
is(readfile("testa/a"), "file-a\n", "Testing file a in tar archive");
is(readfile("testa/b"), "file-b\n", "Testing file b in tar archive");
rmtree "testa";
|