Doit
view release on metacpan or search on metacpan
error "Failing while in scope cleanup";
CORE::exit(0); # never reached --- and exitcode=0 would be considered an error in this test
}
waitpid $pid, 0;
isnt $?, 0, 'scope cleanup after failure, in separate process';
}
######################################################################
# copy_stat
{
my $doit = Doit->init;
my %sudo_info;
my $sudo = TestUtil::get_sudo($doit, info => \%sudo_info); # must run in this directory
my $tempdir = tempdir(TMPDIR => 1, CLEANUP => 1);
in_directory {
$doit->create_file_if_nonexisting('source');
$doit->create_file_if_nonexisting('target');
my @stat = stat('source');
$doit->chmod(0600, 'source');
copy_stat('source', 'target');
is(((stat('target'))[2] & 07777), ($^O eq 'MSWin32' ? 0666 : 0600), 'preserving mode');
$stat[2] = 0400;
copy_stat(\@stat, 'target');
is(((stat('target'))[2] & 07777), ($^O eq 'MSWin32' ? 0444 : 0400), 'preserving mode using stat array');
$stat[2] = 0644;
copy_stat(\@stat, 'target', 'mode' => 1);
is(((stat('target'))[2] & 07777), ($^O eq 'MSWin32' ? 0666 : 0644), 'explicit preserve option');
$stat[2] = 0755;
copy_stat(\@stat, 'target', 'ownership' => 1);
is(((stat('target'))[2] & 07777), ($^O eq 'MSWin32' ? 0666 : 0644), 'unchanged stat, non-matching preserve option');
$doit->utime(86400,86400,'source');
copy_stat('source', 'target');
is((stat('target'))[8], 86400, 'preserving atime') if $enable_atime_tests;
is((stat('target'))[9], 86400, 'preserving mtime');
$stat[8] = $stat[9] = 86400*2;
copy_stat(\@stat, 'target');
is((stat('target'))[8], 86400*2, 'preserving atime using stat array') if $enable_atime_tests;
is((stat('target'))[9], 86400*2, 'preserving mtime using stat array');
$stat[8] = $stat[9] = 86400*3;
copy_stat(\@stat, 'target', 'time' => 1);
is((stat('target'))[8], 86400*3, 'explicit preserve option (atime)') if $enable_atime_tests;
is((stat('target'))[9], 86400*3, 'explicit preserve option (mtime)');
$stat[8] = $stat[9] = 86400*4;
copy_stat(\@stat, 'target', 'mode' => 1);
is((stat('target'))[8], 86400*3, 'unchanged atime, non-matching preserve option') if $enable_atime_tests;
is((stat('target'))[9], 86400*3, 'unchanged mtime, non-matching preserve option');
# Must be last in this block --- source+target are deleted
SKIP: {
skip "Can't sudo: $sudo_info{error}", 2 if !$sudo;
$sudo->chown(0,0,"$tempdir/source");
$sudo->call_with_runner('run_copy_stat', "$tempdir/source", "$tempdir/target"); # NOTE: directory change does not apply to sudo context XXX would be nicer if $sudo->copy_stat could be used
is((stat('target'))[4], 0, 'preserving owner');
is((stat('target'))[5], 0, 'preserving group');
$sudo->unlink(qw(source target));
}
} $tempdir;
}
__END__
( run in 0.461 second using v1.01-cache-2.11-cpan-71847e10f99 )