Archive-Tar
view release on metacpan or search on metacpan
t/03_file.t view on Meta::CPAN
my ($dir, $file) = dir_and_file( $unix_path );
my $obj = Archive::Tar::File->new( data => $unix_path, $contents, $attr );
isa_ok( $obj, 'Archive::Tar::File', "Object created" );
is( $obj->name, $file, " name '$file' ok" );
is( $obj->prefix, $dir, " prefix '$dir' ok" );
is( $obj->size, length($contents), " size ok" );
is( $obj->mode, exists($attr->{mode}) ? $attr->{mode} : MODE,
" mode ok" );
is( $obj->uid, exists($attr->{uid}) ? $attr->{uid} : UID,
" uid ok" );
is( $obj->gid, exists($attr->{gid}) ? $attr->{gid} : GID,
" gid ok" );
is( $obj->uname, exists($attr->{uname}) ? $attr->{uname} : UNAME->(UID ),
" uname ok" );
is( $obj->gname, exists($attr->{gname}) ? $attr->{gname} : GNAME->( GID ),
" gname ok" );
is( $obj->type, exists($attr->{type}) ? $attr->{type} : FILE,
" type ok" );
if (exists($attr->{mtime})) {
is( $obj->mtime, $attr->{mtime}, " mtime matches" );
} else {
cmp_ok( $obj->mtime, '>', $start_time, " mtime after start time" );
}
ok( $obj->chksum, " chksum ok" );
ok( $obj->version, " version ok" );
ok( ! $obj->linkname, " linkname ok" );
ok( ! $obj->devmajor, " devmajor ok" );
ok( ! $obj->devminor, " devminor ok" );
ok( ! $obj->raw, " raw ok" );
### test type checkers
SKIP: {
skip "Attributes defined, may not be plainfile", 11 if keys %$attr;
ok( $obj->is_file, " Object is a file" );
for my $name (qw[dir hardlink symlink chardev blockdev fifo
socket unknown longlink label ]
) {
my $method = 'is_' . $name;
ok(!$obj->$method(), " Object is not a '$name'");
}
}
### Use "ok" not "is" to avoid binary data screwing up the screen ###
ok( $obj->get_content eq $contents, " get_content ok" );
ok( ${$obj->get_content_by_ref} eq $contents,
" get_content_by_ref ok" );
is( $obj->has_content, length($contents) ? 1 : 0,
" has_content ok" );
ok( $obj->replace_content( $replace_contents ),
" replace_content ok" );
ok( $obj->get_content eq $replace_contents, " get_content ok" );
ok( $obj->replace_content( $contents ), " replace_content ok" );
ok( $obj->get_content eq $contents, " get_content ok" );
ok( $obj->rename( $rename_path ), " rename ok" );
ok( $obj->chown( 'root' ), " chown 1 arg ok" );
is( $obj->uname, 'root', " chown to root ok" );
ok( $obj->chown( 'rocky', 'perl'), " chown 2 args ok" );
is( $obj->uname, 'rocky', " chown to rocky ok" );
is( $obj->gname, 'perl', " chown to rocky:perl ok" );
is( $obj->name, $rename_file, " name '$file' ok" );
is( $obj->prefix, $rename_dir, " prefix '$dir' ok" );
ok( $obj->rename( $unix_path ), " rename ok" );
is( $obj->name, $file, " name '$file' ok" );
is( $obj->prefix, $dir, " prefix '$dir' ok" );
### clone tests ###
my $clone = $obj->clone;
isnt( $obj, $clone, "Clone is different object" );
is_deeply( $obj, $clone, " Clone holds same data" );
}
### _downgrade_to_plainfile
{ my $aref = $test_files[-1];
my $unix_path = $aref->[0];
my $contents = $aref->[1];
my $attr = $aref->[2];
my $obj = Archive::Tar::File->new( data => $unix_path, $contents, $attr );
### check if the object is as expected
isa_ok( $obj, 'Archive::Tar::File' );
ok( $obj->is_dir, " Is a directory" );
### do the downgrade
ok( $obj->_downgrade_to_plainfile, " Downgraded to plain file" );
### now check if it's downgraded
ok( $obj->is_file, " Is now a file" );
is( $obj->linkname, '', " No link entered" );
is( $obj->mode, MODE, " Mode as expected" );
}
### helper subs ###
sub dir_and_file {
my $unix_path = shift;
my ($vol, $dirs, $file) = File::Spec::Unix->splitpath( $unix_path );
my $dir = File::Spec::Unix->catdir( grep { length } $vol,
File::Spec::Unix->splitdir( $dirs ) );
return ( $dir, $file );
}
( run in 0.358 second using v1.01-cache-2.11-cpan-5511b514fd6 )