File-Path
view release on metacpan or search on metacpan
"If provided with an empty string for a path, remove_tree() will return a count of 0 things deleted");
$count = make_path();
is($count, 0,
"If not provided with any paths, make_path() will return a count of 0 things created");
$count = mkpath();
is($count, 0,
"If not provided with any paths, make_path() will return a count of 0 things created");
}
SKIP: {
my $skip_count = 3;
skip "Windows will not set this error condition", $skip_count
if $^O eq 'MSWin32';
# mkpath() with hashref: case of phony user
my ($least_deep, $next_deepest, $deepest) =
create_3_level_subdirs( qw| Hhu1KpF4EVAV vUj5k37bih8v Vkdw02POXJxj | );
my (@created, $error);
my $user = join('_' => 'foobar', $$);
@created = mkpath($deepest, { mode => 0711, user => $user, error => \$error });
# TODO: {
# local $TODO = "Notwithstanding the phony 'user', mkpath will actually create subdirectories; should it?";
# is(scalar(@created), 0, "No subdirectories created");
# }
is(scalar(@$error), 1, "caught error condition" );
my ($file, $message) = each %{$error->[0]};
like($message,
qr/unable to map $user to a uid, ownership not changed/s,
"Got expected error message for phony user",
);
cleanup_3_level_subdirs($least_deep);
}
{
# mkpath() with hashref: case of valid uid
my ($least_deep, $next_deepest, $deepest) =
create_3_level_subdirs( qw| b5wj8CJcc7gl XTJe2C3WGLg5 VZ_y2T0XfKu3 | );
my (@created, $error);
my $warn;
local $SIG{__WARN__} = sub { $warn = shift };
@created = mkpath($deepest, { mode => 0711, uid => $>, error => \$error });
SKIP: {
my $skip_count = 1;
skip "Warning should only appear on Windows", $skip_count
unless $^O eq 'MSWin32';
like($warn,
qr/Option\(s\) implausible on Win32 passed to mkpath\(\) or make_path\(\)/,
'make_path with final hashref warned due to options implausible on Win32'
);
}
is(scalar(@created), 3, "Provide valid 'uid' argument: 3 subdirectories created");
cleanup_3_level_subdirs($least_deep);
}
SKIP: {
my $skip_count = 3;
skip "getpwuid() and getgrgid() not implemented on Windows", $skip_count
if $^O eq 'MSWin32';
# mkpath() with hashref: case of valid owner
my ($least_deep, $next_deepest, $deepest) =
create_3_level_subdirs( qw| aiJEDKaAEH25 nqhXsBM_7_bv qfRj4cur4Jrs | );
my (@created, $error);
my $name = getpwuid($>);
@created = mkpath($deepest, { mode => 0711, owner => $name, error => \$error });
is(scalar(@created), 3, "Provide valid 'owner' argument: 3 subdirectories created");
cleanup_3_level_subdirs($least_deep);
}
SKIP: {
my $skip_count = 5;
skip "Windows will not set this error condition", $skip_count
if $^O eq 'MSWin32';
# mkpath() with hashref: case of phony group
my ($least_deep, $next_deepest, $deepest) =
create_3_level_subdirs( qw| nOR4lGRMdLvz NnwkEHEVL5li _3f1Kv6q77yA | );
my (@created, $error);
my $bad_group = join('_' => 'foobarbaz', $$);
@created = mkpath($deepest, { mode => 0711, group => $bad_group, error => \$error });
# TODO: {
# local $TODO = "Notwithstanding the phony 'group', mkpath will actually create subdirectories; should it?";
# is(scalar(@created), 0, "No subdirectories created");
# }
is(scalar(@$error), 1, "caught error condition" );
my ($file, $message) = each %{$error->[0]};
like($message,
qr/unable to map $bad_group to a gid, group ownership not changed/s,
"Got expected error message for phony user",
);
cleanup_3_level_subdirs($least_deep);
}
{
# mkpath() with hashref: case of valid group
my ($least_deep, $next_deepest, $deepest) =
create_3_level_subdirs( qw| BEcigvaBNisY rd4lJ1iZRyeS OyQnDPIBxP2K | );
my (@created, $error);
my $warn;
local $SIG{__WARN__} = sub { $warn = shift };
@created = mkpath($deepest, { mode => 0711, group => $(, error => \$error });
SKIP: {
my $skip_count = 1;
skip "Warning should only appear on Windows", $skip_count
unless $^O eq 'MSWin32';
like($warn,
qr/Option\(s\) implausible on Win32 passed to mkpath\(\) or make_path\(\)/,
'make_path with final hashref warned due to options implausible on Win32'
);
}
is(scalar(@created), 3, "Provide valid 'group' argument: 3 subdirectories created");
cleanup_3_level_subdirs($least_deep);
}
SKIP: {
my $skip_count = 3;
skip "getpwuid() and getgrgid() not implemented on Windows", $skip_count
if $^O eq 'MSWin32';
# mkpath() with hashref: case of valid group
my ($least_deep, $next_deepest, $deepest) =
create_3_level_subdirs( qw| IayhWFDvys8X gTd6gaeuFzmV VVI6UWLJCOEC | );
my (@created, $error);
my $group_name = (getgrgid($())[0];
@created = mkpath($deepest, { mode => 0711, group => $group_name, error => \$error });
is(scalar(@created), 3, "Provide valid 'group' argument: 3 subdirectories created");
cleanup_3_level_subdirs($least_deep);
}
SKIP: {
my $skip_count = 3;
skip "getpwuid() and getgrgid() not implemented on Windows", $skip_count
if $^O eq 'MSWin32';
# mkpath() with hashref: case of valid owner and group
my ($least_deep, $next_deepest, $deepest) =
create_3_level_subdirs( qw| xsmOvlnxOqJc olsGlBSoVUpp tDuRilkD35rd | );
my (@created, $error);
my $name = getpwuid($>);
my $group_name = (getgrgid($())[0];
@created = mkpath($deepest, { mode => 0711, owner => $name, group => $group_name, error => \$error });
is(scalar(@created), 3, "Provide valid 'owner' and 'group' 'group' arguments: 3 subdirectories created");
cleanup_3_level_subdirs($least_deep);
}
( run in 1.134 second using v1.01-cache-2.11-cpan-39bf76dae61 )