2 # Path.t -- tests for module File::Path
6 use Test::More tests => 167;
13 _cannot_delete_safe_mode
15 create_3_level_subdirs
16 cleanup_3_level_subdirs
23 use_ok('File::Path', qw(rmtree mkpath make_path remove_tree));
24 use_ok('File::Spec::Functions');
27 my $Is_VMS = $^O eq 'VMS';
29 my $fchmod_supported = 0;
30 if (open my $fh, curdir()) {
31 my ($perm) = (stat($fh))[2];
33 eval { $fchmod_supported = chmod( $perm, $fh); };
36 # first check for stupid permissions second for full, so we clean up
38 for my $perm (0111,0777) {
39 my $path = catdir(curdir(), "mhx", "bar");
41 chmod $perm, "mhx", $path;
43 my $oct = sprintf('0%o', $perm);
45 ok(-d "mhx", "mkdir parent dir $oct");
46 ok(-d $path, "mkdir child dir $oct");
50 ok(! -e "mhx", "mhx does not exist $oct");
53 # find a place to work
54 my ($error, $list, $file, $message);
55 my $tmp_base = catdir(
57 sprintf( 'test-%x-%x-%x', time, $$, rand(99999) ),
62 catdir($tmp_base, qw(a b)),
63 catdir($tmp_base, qw(a c)),
64 catdir($tmp_base, qw(z b)),
65 catdir($tmp_base, qw(z c)),
69 my @created = mkpath([@dir]);
71 is(scalar(@created), 7, "created list of directories");
73 # pray for no race conditions blowing them out from under us
74 @created = mkpath([$tmp_base]);
75 is(scalar(@created), 0, "skipped making existing directory")
76 or diag("unexpectedly recreated @created");
79 my $file_name = catfile( $tmp_base, 'a', 'delete.me' );
81 if (open OUT, "> $file_name") {
82 print OUT "this file may be deleted\n";
87 diag( "Failed to create file $file_name: $!" );
91 skip "cannot remove a file we failed to create", 1
92 unless $file_count == 1;
93 my $count = rmtree($file_name);
94 is($count, 1, "rmtree'ed a file");
97 @created = mkpath('');
98 is(scalar(@created), 0, "Can't create a directory named ''");
104 # background info: @_ = 1; !shift # gives '' not 0
105 # Message-Id: <3C820CE6-4400-4E91-AF43-A3D19B356E68@activestate.com>
106 # http://www.nntp.perl.org/group/perl.perl5.porters/2008/05/msg136625.html
107 mkpath(shift, !shift, 0755);
111 opendir D, shift or return -1;
112 my $count = () = readdir D;
113 closedir D or return -1;
120 open my $f, '>', 'foo.dat';
122 my $before = count(curdir());
123 cmp_ok($before, '>', 0, "baseline $before");
126 is(count(curdir()), $before + 1, "first after $before");
128 $before = count(curdir());
131 is(count(curdir()), $before + 1, "second after $before");
140 open my $f, '>', 'foo.dat';
142 my $before = count(curdir());
144 cmp_ok($before, '>', 0, "ARGV $before");
147 mkpath('3rd', !shift, 0755);
150 is(count(curdir()), $before + 1, "third after $before");
152 $before = count(curdir());
155 mkpath('4th', !shift, 0755);
158 is(count(curdir()), $before + 1, "fourth after $before");
165 # tests for rmtree() of ancestor directory
167 my $cwd = getcwd() or skip "failed to getcwd: $!", $nr_tests;
168 my $dir = catdir($cwd, 'remove');
169 my $dir2 = catdir($cwd, 'remove', 'this', 'dir');
171 skip "failed to mkpath '$dir2': $!", $nr_tests
172 unless mkpath($dir2, {verbose => 0});
173 skip "failed to chdir dir '$dir2': $!", $nr_tests
176 rmtree($dir, {error => \$error});
177 my $nr_err = @$error;
179 is($nr_err, 1, "ancestor error");
182 my ($file, $message) = each %{$error->[0]};
184 is($file, $dir, "ancestor named");
185 my $ortho_dir = $^O eq 'MSWin32' ? File::Path::_slash_lc($dir2) : $dir2;
186 $^O eq 'MSWin32' and $message
187 =~ s/\A(cannot remove path when cwd is )(.*)\Z/$1 . File::Path::_slash_lc($2)/e;
189 is($message, "cannot remove path when cwd is $ortho_dir", "ancestor reason");
191 ok(-d $dir2, "child not removed");
193 ok(-d $dir, "ancestor not removed");
204 ok(!(-d $dir), "ancestor now removed");
207 my $count = rmtree({error => \$error});
209 is( $count, 0, 'rmtree of nothing, count of zero' );
211 is( scalar(@$error), 0, 'no diagnostic captured' );
213 @created = mkpath($tmp_base, 0);
215 is(scalar(@created), 0, "skipped making existing directories (old style 1)")
216 or diag("unexpectedly recreated @created");
218 $dir = catdir($tmp_base,'C');
219 # mkpath returns unix syntax filespecs on VMS
220 $dir = VMS::Filespec::unixify($dir) if $Is_VMS;
221 @created = make_path($tmp_base, $dir);
223 is(scalar(@created), 1, "created directory (new style 1)");
225 is($created[0], $dir, "created directory (new style 1) cross-check");
227 @created = mkpath($tmp_base, 0, 0700);
229 is(scalar(@created), 0, "skipped making existing directories (old style 2)")
230 or diag("unexpectedly recreated @created");
232 $dir2 = catdir($tmp_base,'D');
233 # mkpath returns unix syntax filespecs on VMS
234 $dir2 = VMS::Filespec::unixify($dir2) if $Is_VMS;
235 @created = make_path($tmp_base, $dir, $dir2);
237 is(scalar(@created), 1, "created directory (new style 2)");
239 is($created[0], $dir2, "created directory (new style 2) cross-check");
241 $count = rmtree($dir, 0);
243 is($count, 1, "removed directory unsafe mode");
245 my $expected_count = _cannot_delete_safe_mode($dir2) ? 0 : 1;
247 $count = rmtree($dir2, 0, 1);
249 is($count, $expected_count, "removed directory safe mode");
253 # existence of E is neither here nor there
254 $dir = catdir($tmp_base, 'E', updir(), 'Y');
255 @created =mkpath($dir);
257 cmp_ok(scalar(@created), '>=', 1, "made one or more dirs because of ..");
259 cmp_ok(scalar(@created), '<=', 2, "made less than two dirs because of ..");
261 ok( -d catdir($tmp_base, 'Y'), "directory after parent" );
263 @created = make_path(catdir(curdir(), $tmp_base));
265 is(scalar(@created), 0, "nothing created")
268 $dir = catdir($tmp_base, 'a');
269 $dir2 = catdir($tmp_base, 'z');
280 is(scalar(@$error), 0, "no errors unlinking a and z");
282 is(scalar(@$list), 4, "list contains 4 elements")
285 ok(-d $dir, "dir a still exists");
287 ok(-d $dir2, "dir z still exists");
289 $dir = catdir($tmp_base,'F');
290 # mkpath returns unix syntax filespecs on VMS
291 $dir = VMS::Filespec::unixify($dir) if $Is_VMS;
293 @created = mkpath($dir, undef, 0770);
295 is(scalar(@created), 1, "created directory (old style 2 verbose undef)");
297 is($created[0], $dir, "created directory (old style 2 verbose undef) cross-check");
299 is(rmtree($dir, undef, 0), 1, "removed directory 2 verbose undef");
301 @created = mkpath($dir, undef);
303 is(scalar(@created), 1, "created directory (old style 2a verbose undef)");
305 is($created[0], $dir, "created directory (old style 2a verbose undef) cross-check");
307 is(rmtree($dir, undef), 1, "removed directory 2a verbose undef");
309 @created = mkpath($dir, 0, undef);
311 is(scalar(@created), 1, "created directory (old style 3 mode undef)");
313 is($created[0], $dir, "created directory (old style 3 mode undef) cross-check");
315 is(rmtree($dir, 0, undef), 1, "removed directory 3 verbose undef");
318 skip "fchmod of directories not supported on this platform", 3 unless $fchmod_supported;
319 $dir = catdir($tmp_base,'G');
320 $dir = VMS::Filespec::unixify($dir) if $Is_VMS;
322 @created = mkpath($dir, undef, 0400);
324 is(scalar(@created), 1, "created read-only dir");
326 is($created[0], $dir, "created read-only directory cross-check");
328 is(rmtree($dir), 1, "removed read-only dir");
331 # borderline new-style heuristics
332 if (chdir $tmp_base) {
333 pass("chdir to temp dir");
336 fail("chdir to temp dir: $!");
339 $dir = catdir('a', 'd1');
340 $dir2 = catdir('a', 'd2');
342 @created = make_path( $dir, 0, $dir2 );
344 is(scalar @created, 3, 'new-style 3 dirs created');
346 $count = remove_tree( $dir, 0, $dir2, );
348 is($count, 3, 'new-style 3 dirs removed');
350 @created = make_path( $dir, $dir2, 1 );
352 is(scalar @created, 3, 'new-style 3 dirs created (redux)');
354 $count = remove_tree( $dir, $dir2, 1 );
356 is($count, 3, 'new-style 3 dirs removed (redux)');
358 @created = make_path( $dir, $dir2 );
360 is(scalar @created, 2, 'new-style 2 dirs created');
362 $count = remove_tree( $dir, $dir2 );
364 is($count, 2, 'new-style 2 dirs removed');
366 $dir = catdir("a\nb", 'd1');
367 $dir2 = catdir("a\nb", 'd2');
370 # Better to search for *nix derivatives?
371 # Not sure what else doesn't support newline in paths
372 skip "$^O doesn't allow newline in paths", 2
373 if $^O =~ m/^(MSWin32|VMS)$/;
375 @created = make_path( $dir, $dir2 );
377 is(scalar @created, 3, 'new-style 3 dirs created in parent with newline');
379 $count = remove_tree( $dir, $dir2 );
381 is($count, 2, 'new-style 2 dirs removed in parent with newline');
385 pass("chdir parent");
388 fail("chdir parent: $!");
392 # test bug http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=487319
393 skip "Don't need Force_Writeable semantics on $^O", 6
394 if grep {$^O eq $_} qw(amigaos dos epoc MSWin32 MacOS os2);
395 skip "Symlinks not available", 6 unless $Config{d_symlink};
397 $dir2 = 'bug487319-symlink';
398 @created = make_path($dir, {mask => 0700});
400 is( scalar @created, 1, 'bug 487319 setup' );
401 symlink($dir, $dir2);
403 ok(-e $dir2, "debian bug 487319 setup symlink") or diag($dir2);
406 my $mask_initial = (stat $dir)[2];
409 my $mask = (stat $dir)[2];
411 is( $mask, $mask_initial, 'mask of symlink target dir unchanged (debian bug 487319)');
414 #my $file = catfile($dir, 'file');
415 my $file = 'bug487319-file';
416 my $file2 = 'bug487319-file-symlink';
417 open my $out, '>', $file;
420 ok(-e $file, 'file exists');
423 $mask_initial = (stat $file)[2];
425 symlink($file, $file2);
427 ok(-e $file2, 'file2 exists');
430 $mask = (stat $file)[2];
432 is( $mask, $mask_initial, 'mask of symlink target file unchanged (debian bug 487319)');
438 # see what happens if a file exists where we want a directory
440 my $entry = catfile($tmp_base, "file");
441 skip "VMS can have a file and a directory with the same name.", 4
443 skip "Cannot create $entry", 4 unless open OUT, "> $entry";
444 print OUT "test file, safe to delete\n", scalar(localtime), "\n";
446 ok(-e $entry, "file exists in place of directory");
448 mkpath( $entry, {error => \$error} );
449 is( scalar(@$error), 1, "caught error condition" );
450 ($file, $message) = each %{$error->[0]};
451 is( $entry, $file, "and the message is: $message");
453 eval {@created = mkpath($entry, 0, 0700)};
455 chomp $error; # just to remove silly # in TAP output
456 cmp_ok( $error, 'ne', "", "no directory created (old-style) err=$error" )
461 $dir = catdir($tmp_base, 'ZZ');
462 @created = mkpath($dir);
463 is(scalar(@created), 1, "create a ZZ directory");
465 local @ARGV = ($dir);
466 rmtree( [grep -e $_, @ARGV], 0, 0 );
467 ok(!-e $dir, "blow it away via \@ARGV");
472 # this test will fail on Windows, as per:
473 # http://perldoc.perl.org/perlport.html#chmod
475 skip "Windows chmod test skipped", $skip_count
477 skip "fchmod() on directories is not supported on this platform", $skip_count
478 unless $fchmod_supported;
482 0777, 0700, 0470, 0407,
483 0433, 0400, 0430, 0403,
484 0111, 0100, 0110, 0101,
485 0731, 0713, 0317, 0371,
492 $dir = catdir($tmp_base, sprintf("chmod_test%04o", $input));
493 # We can skip from here because 0 is last in the list.
494 skip "Mode of 0 means assume user defaults on VMS", 1
495 if ($input == 0 && $Is_VMS);
496 @created = mkpath($dir, {chmod => $input});
497 $mode = (stat($dir))[2];
498 $octal_mode = S_IMODE($mode);
499 $octal_input = sprintf "%04o", S_IMODE($input);
501 skip "permissions are not fully supported by the filesystem", 1
502 if (($^O eq 'MSWin32' || $^O eq 'cygwin') && ((Win32::FsType())[1] & 8) == 0);
503 is($octal_mode,$input, "create a new directory with chmod $input ($octal_input)");
509 my $dir_base = catdir($tmp_base,'output');
510 my $dir_a = catdir($dir_base, 'A');
511 my $dir_b = catdir($dir_base, 'B');
513 is(_run_for_verbose(sub {@created = mkpath($dir_a, 1)}),
514 _verbose_expected('mkpath', $dir_base, 0, 1)
515 . _verbose_expected('mkpath', $dir_a, 0),
516 'mkpath verbose (old style 1)'
519 is(_run_for_verbose(sub {@created = mkpath([$dir_b], 1)}),
520 _verbose_expected('mkpath', $dir_b, 0),
521 'mkpath verbose (old style 2)'
524 my $verbose_expected;
526 # Must determine expectations while directories still exist.
527 $verbose_expected = _verbose_expected('rmtree', $dir_a, 1)
528 . _verbose_expected('rmtree', $dir_b, 1);
530 is(_run_for_verbose(sub {$count = rmtree([$dir_a, $dir_b], 1, 1)}),
532 'rmtree verbose (old style)'
535 # In case we didn't delete them in safe mode.
536 rmtree($dir_a) if -d $dir_a;
537 rmtree($dir_b) if -d $dir_b;
539 is(_run_for_verbose(sub {@created = mkpath( $dir_a,
540 {verbose => 1, mask => 0750})}),
541 _verbose_expected('mkpath', $dir_a, 0),
542 'mkpath verbose (new style 1)'
545 is(_run_for_verbose(sub {@created = mkpath($dir_b, 1, 0771)}),
546 _verbose_expected('mkpath', $dir_b, 0),
547 'mkpath verbose (new style 2)'
550 $verbose_expected = _verbose_expected('rmtree', $dir_a, 1)
551 . _verbose_expected('rmtree', $dir_b, 1);
553 is(_run_for_verbose(sub {$count = rmtree([$dir_a, $dir_b], 1, 1)}),
555 'again: rmtree verbose (old style)'
558 rmtree($dir_a) if -d $dir_a;
559 rmtree($dir_b) if -d $dir_b;
561 is(_run_for_verbose(sub {@created = make_path( $dir_a, $dir_b,
562 {verbose => 1, mode => 0711});}),
563 _verbose_expected('make_path', $dir_a, 1)
564 . _verbose_expected('make_path', $dir_b, 1),
565 'make_path verbose with final hashref'
568 $verbose_expected = _verbose_expected('remove_tree', $dir_a, 0)
569 . _verbose_expected('remove_tree', $dir_b, 0);
571 is(_run_for_verbose(sub {@created = remove_tree( $dir_a, $dir_b,
574 'remove_tree verbose with final hashref'
577 rmtree($dir_a) if -d $dir_a;
578 rmtree($dir_b) if -d $dir_b;
580 # Have to re-create these 2 directories so that next block is not skipped.
581 @created = make_path(
586 is(@created, 2, "2 directories created");
589 $file = catfile($dir_b, "file");
590 skip "Cannot create $file", 2 unless open OUT, "> $file";
591 print OUT "test file, safe to delete\n", scalar(localtime), "\n";
594 $verbose_expected = _verbose_expected('rmtree', $dir_a, 1)
595 . _verbose_expected('unlink', $file, 0)
596 . _verbose_expected('rmtree', $dir_b, 1);
598 ok(-e $file, "file created in directory");
600 is(_run_for_verbose(sub {$count = rmtree( $dir_a, $dir_b,
601 {verbose => 1, safe => 1})}),
603 'rmtree safe verbose (new style)'
605 rmtree($dir_a) if -d $dir_a;
606 rmtree($dir_b) if -d $dir_b;
610 my $base = catdir( $tmp_base, 'output2');
611 my $dir = catdir( $base, 'A');
612 my $dir2 = catdir( $base, 'B');
615 my $warn = _run_for_warning( sub {
616 my @created = make_path(
619 { mode => 0711, foo => 1, bar => 1 }
623 qr/Unrecognized option\(s\) passed to mkpath\(\) or make_path\(\):.*?bar.*?foo/,
624 'make_path with final hashref warned due to unrecognized options'
629 my $warn = _run_for_warning( sub {
630 my @created = remove_tree(
633 { foo => 1, bar => 1 }
637 qr/Unrecognized option\(s\) passed to remove_tree\(\):.*?bar.*?foo/,
638 'remove_tree with final hashref failed due to unrecognized options'
645 my $cwd = getcwd() or skip "failed to getcwd: $!", $nr_tests;
646 rmtree($tmp_base, {result => \$list} );
647 is(ref($list), 'ARRAY', "received a final list of results");
648 ok( !(-d $tmp_base), "test base directory gone" );
655 ok(mkpath($xx), "make $xx");
656 ok(chdir($xx), "... and chdir $xx");
658 # ok(chdir($p), "... now chdir $p");
659 # ok(rmtree($xx), "... and finally rmtree $xx");
664 # create and delete directory
665 my $px = catdir($p, $x);
666 ok(mkpath($px), 'create and delete directory 2.07');
667 ok(rmtree($px), '.. rmtree fails in File-Path-2.07');
671 my $windows_dir = 'C:\Path\To\Dir';
672 my $expect = 'c:/path/to/dir';
674 File::Path::_slash_lc($windows_dir),
676 "Windows path unixified as expected"
680 my ($x, $message, $object, $expect, $rv, $arg, $error);
681 my ($k, $v, $second_error, $third_error);
685 $message = 'message in a bottle';
686 $object = '/path/to/glory';
687 $expect = "$message for $object: $x";
688 $rv = _run_for_warning( sub {
695 like($rv, qr/^$expect/,
696 "no \$arg->{error}: defined 2nd and 3rd args: got expected error message");
699 $expect = "$message: $x";
700 $rv = _run_for_warning( sub {
707 like($rv, qr/^$expect/,
708 "no \$arg->{error}: defined 2nd arg; undefined 3rd arg: got expected error message");
710 $message = 'message in a bottle';
712 $expect = "$message: $x";
713 $arg = { error => \$error };
719 is(ref($error->[0]), 'HASH',
720 "first element of array inside \$error is hashref");
721 ($k, $v) = %{$error->[0]};
722 is($k, '', 'key of hash is empty string, since 3rd arg was undef');
723 is($v, $expect, "value of hash is 2nd arg: $message");
726 $object = '/path/to/glory';
727 $expect = "$message: $x";
728 $arg = { error => \$second_error };
734 is(ref($second_error->[0]), 'HASH',
735 "first element of array inside \$second_error is hashref");
736 ($k, $v) = %{$second_error->[0]};
737 is($k, $object, "key of hash is '$object', since 3rd arg was defined");
738 is($v, $expect, "value of hash is 2nd arg: $message");
742 $expect = "$message: $x";
743 $arg = { error => \$third_error };
749 is(ref($third_error->[0]), 'HASH',
750 "first element of array inside \$third_error is hashref");
751 ($k, $v) = %{$third_error->[0]};
752 is($k, '', "key of hash is empty string, since 3rd arg was undef");
753 is($v, $expect, "value of hash is 2nd arg: $message");
757 # https://rt.cpan.org/Ticket/Display.html?id=117019
758 # remove_tree(): Permit re-use of options hash without issuing a warning
760 my ($least_deep, $next_deepest, $deepest) =
761 create_3_level_subdirs( qw| ZoYhvc6RmGnl S2CrQ0lju0o7 lvOqVYWpfhcP | );
763 @created = File::Path::make_path($deepest, { mode => 0711 });
764 is(scalar(@created), 3, "Created 3 subdirectories");
767 my $opts = { error => \$x };
768 File::Path::remove_tree($deepest, $opts);
769 ok(! -d $deepest, "directory '$deepest' removed, as expected");
772 $warn = _run_for_warning( sub { File::Path::remove_tree($next_deepest, $opts); } );
773 ok(! $warn, "CPAN 117019: No warning thrown when re-using \$opts");
774 ok(! -d $next_deepest, "directory '$next_deepest' removed, as expected");
776 $warn = _run_for_warning( sub { File::Path::remove_tree($least_deep, $opts); } );
777 ok(! $warn, "CPAN 117019: No warning thrown when re-using \$opts");
778 ok(! -d $least_deep, "directory '$least_deep' removed, as expected");
782 # Corner cases with respect to arguments provided to functions
785 $count = remove_tree();
787 "If not provided with any paths, remove_tree() will return a count of 0 things deleted");
789 $count = remove_tree('');
791 "If not provided with any paths, remove_tree() will return a count of 0 things deleted");
794 $warn = _run_for_warning( sub { $count = rmtree(); } );
795 like($warn, qr/No root path\(s\) specified/s, "Got expected carp");
797 "If not provided with any paths, remove_tree() will return a count of 0 things deleted");
799 $warn = _run_for_warning( sub {$count = rmtree(undef); } );
800 like($warn, qr/No root path\(s\) specified/s, "Got expected carp");
802 "If provided only with an undefined value, remove_tree() will return a count of 0 things deleted");
804 $warn = _run_for_warning( sub {$count = rmtree(''); } );
805 like($warn, qr/No root path\(s\) specified/s, "Got expected carp");
807 "If provided with an empty string for a path, remove_tree() will return a count of 0 things deleted");
809 $count = make_path();
811 "If not provided with any paths, make_path() will return a count of 0 things created");
815 "If not provided with any paths, make_path() will return a count of 0 things created");
820 skip "Windows will not set this error condition", $skip_count
823 # mkpath() with hashref: case of phony user
824 my ($least_deep, $next_deepest, $deepest) =
825 create_3_level_subdirs( qw| Hhu1KpF4EVAV vUj5k37bih8v Vkdw02POXJxj | );
826 my (@created, $error);
827 my $user = join('_' => 'foobar', $$);
828 @created = mkpath($deepest, { mode => 0711, user => $user, error => \$error });
830 local $TODO = "Notwithstanding the phony 'user', mkpath will actually create subdirectories; should it?";
831 is(scalar(@created), 0, "No subdirectories created");
833 is(scalar(@$error), 1, "caught error condition" );
834 my ($file, $message) = each %{$error->[0]};
836 qr/unable to map $user to a uid, ownership not changed/s,
837 "Got expected error message for phony user",
840 cleanup_3_level_subdirs($least_deep);
844 # mkpath() with hashref: case of valid uid
845 my ($least_deep, $next_deepest, $deepest) =
846 create_3_level_subdirs( qw| b5wj8CJcc7gl XTJe2C3WGLg5 VZ_y2T0XfKu3 | );
847 my (@created, $error);
848 @created = mkpath($deepest, { mode => 0711, uid => $>, error => \$error });
849 is(scalar(@created), 3, "Provide valid 'uid' argument: 3 subdirectories created");
851 cleanup_3_level_subdirs($least_deep);
856 skip "getpwuid() and getgrgid() not implemented on Windows", $skip_count
859 # mkpath() with hashref: case of valid owner
860 my ($least_deep, $next_deepest, $deepest) =
861 create_3_level_subdirs( qw| aiJEDKaAEH25 nqhXsBM_7_bv qfRj4cur4Jrs | );
862 my (@created, $error);
863 my $name = getpwuid($>);
864 @created = mkpath($deepest, { mode => 0711, owner => $name, error => \$error });
865 is(scalar(@created), 3, "Provide valid 'owner' argument: 3 subdirectories created");
867 cleanup_3_level_subdirs($least_deep);
872 skip "Windows will not set this error condition", $skip_count
875 # mkpath() with hashref: case of phony group
876 my ($least_deep, $next_deepest, $deepest) =
877 create_3_level_subdirs( qw| nOR4lGRMdLvz NnwkEHEVL5li _3f1Kv6q77yA | );
878 my (@created, $error);
879 my $bad_group = join('_' => 'foobarbaz', $$);
880 @created = mkpath($deepest, { mode => 0711, group => $bad_group, error => \$error });
882 local $TODO = "Notwithstanding the phony 'group', mkpath will actually create subdirectories; should it?";
883 is(scalar(@created), 0, "No subdirectories created");
885 is(scalar(@$error), 1, "caught error condition" );
886 my ($file, $message) = each %{$error->[0]};
888 qr/unable to map $bad_group to a gid, group ownership not changed/s,
889 "Got expected error message for phony user",
892 cleanup_3_level_subdirs($least_deep);
896 # mkpath() with hashref: case of valid group
897 my ($least_deep, $next_deepest, $deepest) =
898 create_3_level_subdirs( qw| BEcigvaBNisY rd4lJ1iZRyeS OyQnDPIBxP2K | );
899 my (@created, $error);
900 @created = mkpath($deepest, { mode => 0711, group => $(, error => \$error });
901 is(scalar(@created), 3, "Provide valid 'group' argument: 3 subdirectories created");
903 cleanup_3_level_subdirs($least_deep);
908 skip "getpwuid() and getgrgid() not implemented on Windows", $skip_count
911 # mkpath() with hashref: case of valid group
912 my ($least_deep, $next_deepest, $deepest) =
913 create_3_level_subdirs( qw| IayhWFDvys8X gTd6gaeuFzmV VVI6UWLJCOEC | );
914 my (@created, $error);
915 my $group_name = (getgrgid($())[0];
916 @created = mkpath($deepest, { mode => 0711, group => $group_name, error => \$error });
917 is(scalar(@created), 3, "Provide valid 'group' argument: 3 subdirectories created");
919 cleanup_3_level_subdirs($least_deep);
924 skip "getpwuid() and getgrgid() not implemented on Windows", $skip_count
927 # mkpath() with hashref: case of valid owner and group
928 my ($least_deep, $next_deepest, $deepest) =
929 create_3_level_subdirs( qw| xsmOvlnxOqJc olsGlBSoVUpp tDuRilkD35rd | );
930 my (@created, $error);
931 my $name = getpwuid($>);
932 my $group_name = (getgrgid($())[0];
933 @created = mkpath($deepest, { mode => 0711, owner => $name, group => $group_name, error => \$error });
934 is(scalar(@created), 3, "Provide valid 'owner' and 'group' 'group' arguments: 3 subdirectories created");
936 cleanup_3_level_subdirs($least_deep);