This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
File::Path: synch with CPAN version 2.18
[perl5.git] / cpan / File-Path / t / Path.t
index ea4d2b5..b265aee 100644 (file)
@@ -3,24 +3,36 @@
 
 use strict;
 
-use Test::More tests => 159;
+use Test::More tests => 167;
 use Config;
 use Fcntl ':mode';
+use lib './t';
+use FilePathTest qw(
+    _run_for_warning
+    _run_for_verbose
+    _cannot_delete_safe_mode
+    _verbose_expected
+    create_3_level_subdirs
+    cleanup_3_level_subdirs
+);
+use Errno qw(:POSIX);
+use Carp;
 
 BEGIN {
-    # 1
     use_ok('Cwd');
-    # 2
     use_ok('File::Path', qw(rmtree mkpath make_path remove_tree));
-    # 3
     use_ok('File::Spec::Functions');
 }
 
-eval "use Test::Output";
-my $has_Test_Output = $@ ? 0 : 1;
-
 my $Is_VMS = $^O eq 'VMS';
 
+my $fchmod_supported = 0;
+if (open my $fh, curdir()) {
+    my ($perm) = (stat($fh))[2];
+    $perm &= 07777;
+    eval { $fchmod_supported = chmod( $perm, $fh); };
+}
+
 # first check for stupid permissions second for full, so we clean up
 # behind ourselves
 for my $perm (0111,0777) {
@@ -29,13 +41,12 @@ for my $perm (0111,0777) {
     chmod $perm, "mhx", $path;
 
     my $oct = sprintf('0%o', $perm);
-    # 4
+
     ok(-d "mhx", "mkdir parent dir $oct");
-    # 5
     ok(-d $path, "mkdir child dir $oct");
 
     rmtree("mhx");
-    # 6
+
     ok(! -e "mhx", "mhx does not exist $oct");
 }
 
@@ -57,7 +68,6 @@ my @dir = (
 # create them
 my @created = mkpath([@dir]);
 
-# 7
 is(scalar(@created), 7, "created list of directories");
 
 # pray for no race conditions blowing them out from under us
@@ -81,12 +91,10 @@ SKIP: {
     skip "cannot remove a file we failed to create", 1
         unless $file_count == 1;
     my $count = rmtree($file_name);
-# 8
     is($count, 1, "rmtree'ed a file");
 }
 
 @created = mkpath('');
-# 9
 is(scalar(@created), 0, "Can't create a directory named ''");
 
 my $dir;
@@ -112,16 +120,14 @@ sub count {
     open my $f, '>', 'foo.dat';
     close $f;
     my $before = count(curdir());
-# 10
     cmp_ok($before, '>', 0, "baseline $before");
 
     gisle('1st', 1);
-# 11
     is(count(curdir()), $before + 1, "first after $before");
 
     $before = count(curdir());
     gisle('2nd', 1);
-# 12
+
     is(count(curdir()), $before + 1, "second after $before");
 
     chdir updir();
@@ -134,13 +140,13 @@ sub count {
     open my $f, '>', 'foo.dat';
     close $f;
     my $before = count(curdir());
-# 13
+
     cmp_ok($before, '>', 0, "ARGV $before");
     {
         local @ARGV = (1);
         mkpath('3rd', !shift, 0755);
     }
-# 14
+
     is(count(curdir()), $before + 1, "third after $before");
 
     $before = count(curdir());
@@ -148,7 +154,7 @@ sub count {
         local @ARGV = (1);
         mkpath('4th', !shift, 0755);
     }
-# 15
+
     is(count(curdir()), $before + 1, "fourth after $before");
 
     chdir updir();
@@ -169,21 +175,21 @@ SKIP: {
 
     rmtree($dir, {error => \$error});
     my $nr_err = @$error;
-# 16
+
     is($nr_err, 1, "ancestor error");
 
     if ($nr_err) {
         my ($file, $message) = each %{$error->[0]};
-# 17
+
         is($file, $dir, "ancestor named");
         my $ortho_dir = $^O eq 'MSWin32' ? File::Path::_slash_lc($dir2) : $dir2;
         $^O eq 'MSWin32' and $message
             =~ s/\A(cannot remove path when cwd is )(.*)\Z/$1 . File::Path::_slash_lc($2)/e;
-# 18
+
         is($message, "cannot remove path when cwd is $ortho_dir", "ancestor reason");
-# 19
+
         ok(-d $dir2, "child not removed");
-# 20
+
         ok(-d $dir, "ancestor not removed");
     }
     else {
@@ -194,18 +200,18 @@ SKIP: {
     }
     chdir $cwd;
     rmtree($dir);
-# 21
+
     ok(!(-d $dir), "ancestor now removed");
 };
 
 my $count = rmtree({error => \$error});
-# 22
+
 is( $count, 0, 'rmtree of nothing, count of zero' );
-# 23
+
 is( scalar(@$error), 0, 'no diagnostic captured' );
 
 @created = mkpath($tmp_base, 0);
-# 24
+
 is(scalar(@created), 0, "skipped making existing directories (old style 1)")
     or diag("unexpectedly recreated @created");
 
@@ -213,13 +219,13 @@ $dir = catdir($tmp_base,'C');
 # mkpath returns unix syntax filespecs on VMS
 $dir = VMS::Filespec::unixify($dir) if $Is_VMS;
 @created = make_path($tmp_base, $dir);
-# 25
+
 is(scalar(@created), 1, "created directory (new style 1)");
-# 26
+
 is($created[0], $dir, "created directory (new style 1) cross-check");
 
 @created = mkpath($tmp_base, 0, 0700);
-# 27
+
 is(scalar(@created), 0, "skipped making existing directories (old style 2)")
     or diag("unexpectedly recreated @created");
 
@@ -227,34 +233,35 @@ $dir2 = catdir($tmp_base,'D');
 # mkpath returns unix syntax filespecs on VMS
 $dir2 = VMS::Filespec::unixify($dir2) if $Is_VMS;
 @created = make_path($tmp_base, $dir, $dir2);
-# 28
+
 is(scalar(@created), 1, "created directory (new style 2)");
-# 29
+
 is($created[0], $dir2, "created directory (new style 2) cross-check");
 
 $count = rmtree($dir, 0);
-# 30
+
 is($count, 1, "removed directory unsafe mode");
 
+my $expected_count = _cannot_delete_safe_mode($dir2) ? 0 : 1;
+
 $count = rmtree($dir2, 0, 1);
-my $removed = $Is_VMS ? 0 : 1;
-# 31
-is($count, $removed, "removed directory safe mode");
+
+is($count, $expected_count, "removed directory safe mode");
 
 # mkdir foo ./E/../Y
 # Y should exist
 # existence of E is neither here nor there
 $dir = catdir($tmp_base, 'E', updir(), 'Y');
 @created =mkpath($dir);
-# 32
+
 cmp_ok(scalar(@created), '>=', 1, "made one or more dirs because of ..");
-# 33
+
 cmp_ok(scalar(@created), '<=', 2, "made less than two dirs because of ..");
-# 34
+
 ok( -d catdir($tmp_base, 'Y'), "directory after parent" );
 
 @created = make_path(catdir(curdir(), $tmp_base));
-# 35
+
 is(scalar(@created), 0, "nothing created")
     or diag(@created);
 
@@ -269,14 +276,14 @@ rmtree( $dir, $dir2,
     }
 );
 
-# 36
+
 is(scalar(@$error), 0, "no errors unlinking a and z");
-# 37
+
 is(scalar(@$list),  4, "list contains 4 elements")
     or diag("@$list");
-# 38
+
 ok(-d $dir,  "dir a still exists");
-# 39
+
 ok(-d $dir2, "dir z still exists");
 
 $dir = catdir($tmp_base,'F');
@@ -284,39 +291,42 @@ $dir = catdir($tmp_base,'F');
 $dir = VMS::Filespec::unixify($dir) if $Is_VMS;
 
 @created = mkpath($dir, undef, 0770);
-# 40
+
 is(scalar(@created), 1, "created directory (old style 2 verbose undef)");
-# 41
+
 is($created[0], $dir, "created directory (old style 2 verbose undef) cross-check");
-# 42
+
 is(rmtree($dir, undef, 0), 1, "removed directory 2 verbose undef");
 
 @created = mkpath($dir, undef);
-# 43
+
 is(scalar(@created), 1, "created directory (old style 2a verbose undef)");
-# 44
+
 is($created[0], $dir, "created directory (old style 2a verbose undef) cross-check");
-# 45
+
 is(rmtree($dir, undef), 1, "removed directory 2a verbose undef");
 
 @created = mkpath($dir, 0, undef);
-# 46
+
 is(scalar(@created), 1, "created directory (old style 3 mode undef)");
-# 47
+
 is($created[0], $dir, "created directory (old style 3 mode undef) cross-check");
-# 48
+
 is(rmtree($dir, 0, undef), 1, "removed directory 3 verbose undef");
 
-$dir = catdir($tmp_base,'G');
-$dir = VMS::Filespec::unixify($dir) if $Is_VMS;
+SKIP: {
+    skip "fchmod of directories not supported on this platform", 3 unless $fchmod_supported;
+    $dir = catdir($tmp_base,'G');
+    $dir = VMS::Filespec::unixify($dir) if $Is_VMS;
 
-@created = mkpath($dir, undef, 0200);
-# 49
-is(scalar(@created), 1, "created write-only dir");
-# 50
-is($created[0], $dir, "created write-only directory cross-check");
-# 51
-is(rmtree($dir), 1, "removed write-only dir");
+    @created = mkpath($dir, undef, 0400);
+
+    is(scalar(@created), 1, "created read-only dir");
+
+    is($created[0], $dir, "created read-only directory cross-check");
+
+    is(rmtree($dir), 1, "removed read-only dir");
+}
 
 # borderline new-style heuristics
 if (chdir $tmp_base) {
@@ -330,46 +340,44 @@ $dir   = catdir('a', 'd1');
 $dir2  = catdir('a', 'd2');
 
 @created = make_path( $dir, 0, $dir2 );
-# 52
+
 is(scalar @created, 3, 'new-style 3 dirs created');
 
 $count = remove_tree( $dir, 0, $dir2, );
-# 53
+
 is($count, 3, 'new-style 3 dirs removed');
 
 @created = make_path( $dir, $dir2, 1 );
-# 54
+
 is(scalar @created, 3, 'new-style 3 dirs created (redux)');
 
 $count = remove_tree( $dir, $dir2, 1 );
-# 55
+
 is($count, 3, 'new-style 3 dirs removed (redux)');
 
 @created = make_path( $dir, $dir2 );
-# 56
+
 is(scalar @created, 2, 'new-style 2 dirs created');
 
 $count = remove_tree( $dir, $dir2 );
-# 57
+
 is($count, 2, 'new-style 2 dirs removed');
 
 $dir = catdir("a\nb", 'd1');
 $dir2 = catdir("a\nb", 'd2');
 
-
-
 SKIP: {
   # Better to search for *nix derivatives?
   # Not sure what else doesn't support newline in paths
-  skip "This is a MSWin32 platform", 2
-    if $^O eq 'MSWin32';
+  skip "$^O doesn't allow newline in paths", 2
+    if $^O =~ m/^(MSWin32|VMS)$/;
 
   @created = make_path( $dir, $dir2 );
-# 58
+
   is(scalar @created, 3, 'new-style 3 dirs created in parent with newline');
 
   $count = remove_tree( $dir, $dir2 );
-# 59
+
   is($count, 2, 'new-style 2 dirs removed in parent with newline');
 }
 
@@ -381,25 +389,6 @@ else {
 }
 
 SKIP: {
-    skip "This is not a MSWin32 platform", 3
-        unless $^O eq 'MSWin32';
-
-    my $UNC_path = catdir(getcwd(), $tmp_base, 'uncdir');
-    #dont compute a SMB path with $ENV{COMPUTERNAME}, since SMB may be turned off
-    #firewalled, disabled, blocked, or no NICs are on and there the PC has no
-    #working TCPIP stack, \\?\ will always work
-    $UNC_path = '\\\\?\\'.$UNC_path;
-# 60
-    is(mkpath($UNC_path), 1, 'mkpath on Win32 UNC path returns made 1 dir');
-# 61
-    ok(-d $UNC_path, 'mkpath on Win32 UNC path made dir');
-
-    my $removed = rmtree($UNC_path);
-# 62
-    cmp_ok($removed, '>', 0, "removed $removed entries from $UNC_path");
-}
-
-SKIP: {
     # test bug http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=487319
     skip "Don't need Force_Writeable semantics on $^O", 6
         if grep {$^O eq $_} qw(amigaos dos epoc MSWin32 MacOS os2);
@@ -407,10 +396,10 @@ SKIP: {
     $dir  = 'bug487319';
     $dir2 = 'bug487319-symlink';
     @created = make_path($dir, {mask => 0700});
-# 63
+
     is( scalar @created, 1, 'bug 487319 setup' );
     symlink($dir, $dir2);
-# 64
+
     ok(-e $dir2, "debian bug 487319 setup symlink") or diag($dir2);
 
     chmod 0500, $dir;
@@ -418,7 +407,7 @@ SKIP: {
     remove_tree($dir2);
 
     my $mask = (stat $dir)[2];
-# 65
+
     is( $mask, $mask_initial, 'mask of symlink target dir unchanged (debian bug 487319)');
 
     # now try a file
@@ -427,19 +416,19 @@ SKIP: {
     my $file2 = 'bug487319-file-symlink';
     open my $out, '>', $file;
     close $out;
-# 66
+
     ok(-e $file, 'file exists');
 
     chmod 0500, $file;
     $mask_initial = (stat $file)[2];
 
     symlink($file, $file2);
-# 67
+
     ok(-e $file2, 'file2 exists');
     remove_tree($file2);
 
     $mask = (stat $file)[2];
-# 68
+
     is( $mask, $mask_initial, 'mask of symlink target file unchanged (debian bug 487319)');
 
     remove_tree($dir);
@@ -468,53 +457,6 @@ SKIP: {
         or diag(@created);
 }
 
-my $extra =  catdir(curdir(), qw(EXTRA 1 a));
-
-SKIP: {
-    skip "extra scenarios not set up, see eg/setup-extra-tests", 14
-        unless -e $extra;
-    skip "Symlinks not available", 14 unless $Config{d_symlink};
-
-    my ($list, $err);
-    $dir = catdir( 'EXTRA', '1' );
-    rmtree( $dir, {result => \$list, error => \$err} );
-    is(scalar(@$list), 2, "extra dir $dir removed");
-    is(scalar(@$err), 1, "one error encountered");
-
-    $dir = catdir( 'EXTRA', '3', 'N' );
-    rmtree( $dir, {result => \$list, error => \$err} );
-    is( @$list, 1, q{remove a symlinked dir} );
-    is( @$err,  0, q{with no errors} );
-
-    $dir = catdir('EXTRA', '3', 'S');
-    rmtree($dir, {error => \$error});
-    is( scalar(@$error), 1, 'one error for an unreadable dir' );
-    eval { ($file, $message) = each %{$error->[0]}};
-    is( $file, $dir, 'unreadable dir reported in error' )
-        or diag($message);
-
-    $dir = catdir('EXTRA', '3', 'T');
-    rmtree($dir, {error => \$error});
-    is( scalar(@$error), 1, 'one error for an unreadable dir T' );
-    eval { ($file, $message) = each %{$error->[0]}};
-    is( $file, $dir, 'unreadable dir reported in error T' );
-
-    $dir = catdir( 'EXTRA', '4' );
-    rmtree($dir,  {result => \$list, error => \$err} );
-    is( scalar(@$list), 0, q{don't follow a symlinked dir} );
-    is( scalar(@$err),  2, q{two errors when removing a symlink in r/o dir} );
-    eval { ($file, $message) = each %{$err->[0]} };
-    is( $file, $dir, 'symlink reported in error' );
-
-    $dir  = catdir('EXTRA', '3', 'U');
-    $dir2 = catdir('EXTRA', '3', 'V');
-    rmtree($dir, $dir2, {verbose => 0, error => \$err, result => \$list});
-    is( scalar(@$list),  1, q{deleted 1 out of 2 directories} );
-    is( scalar(@$error), 1, q{left behind 1 out of 2 directories} );
-    eval { ($file, $message) = each %{$err->[0]} };
-    is( $file, $dir, 'first dir reported in error' );
-}
-
 {
     $dir = catdir($tmp_base, 'ZZ');
     @created = mkpath($dir);
@@ -526,298 +468,179 @@ SKIP: {
 }
 
 SKIP : {
-    my $skip_count = 19;
-    #this test will fail on Windows, as per: http://perldoc.perl.org/perlport.html#chmod
+    my $skip_count = 18;
+    # this test will fail on Windows, as per:
+    #   http://perldoc.perl.org/perlport.html#chmod
+
     skip "Windows chmod test skipped", $skip_count
         if $^O eq 'MSWin32';
+    skip "fchmod() on directories is not supported on this platform", $skip_count
+        unless $fchmod_supported;
     my $mode;
     my $octal_mode;
     my @inputs = (
-      0777, 0700, 0070, 0007,
-      0333, 0300, 0030, 0003,
-      0111, 0100, 0010, 0001,
-      0731, 0713, 0317, 0371, 0173, 0137,
-      0);
+      0777, 0700, 0470, 0407,
+      0433, 0400, 0430, 0403,
+      0111, 0100, 0110, 0101,
+      0731, 0713, 0317, 0371,
+      0173, 0137);
     my $input;
     my $octal_input;
-    $dir = catdir($tmp_base, 'chmod_test');
 
     foreach (@inputs) {
         $input = $_;
+        $dir = catdir($tmp_base, sprintf("chmod_test%04o", $input));
+        # We can skip from here because 0 is last in the list.
+        skip "Mode of 0 means assume user defaults on VMS", 1
+          if ($input == 0 && $Is_VMS);
         @created = mkpath($dir, {chmod => $input});
         $mode = (stat($dir))[2];
         $octal_mode = S_IMODE($mode);
         $octal_input = sprintf "%04o", S_IMODE($input);
-        is($octal_mode,$input, "create a new directory with chmod $input ($octal_input)");
+        SKIP: {
+           skip "permissions are not fully supported by the filesystem", 1
+                if (($^O eq 'MSWin32' || $^O eq 'cygwin') && ((Win32::FsType())[1] & 8) == 0);
+            is($octal_mode,$input, "create a new directory with chmod $input ($octal_input)");
+           }
         rmtree( $dir );
     }
 }
 
-SKIP: {
-    my $skip_count = 8; # DRY
-    skip "getpwent() not implemented on $^O", $skip_count
-        unless $Config{d_getpwent};
-    skip "getgrent() not implemented on $^O", $skip_count
-        unless $Config{d_getgrent};
-    skip 'not running as root', $skip_count
-        unless $< == 0;
-    skip "darwin's nobody and nogroup are -1", $skip_count
-        if $^O eq 'darwin';
-
-    my $dir_stem = $dir = catdir($tmp_base, 'owned-by');
-
-    # find the highest uid ('nobody' or similar)
-    my $max_uid   = 0;
-    my $max_user = undef;
-    while (my @u = getpwent()) {
-        if ($max_uid < $u[2]) {
-            $max_uid  = $u[2];
-            $max_user = $u[0];
-        }
-    }
-    skip 'getpwent() appears to be insane', $skip_count
-        unless $max_uid > 0;
-
-    # find the highest gid ('nogroup' or similar)
-    my $max_gid   = 0;
-    my $max_group = undef;
-    while (my @g = getgrent()) {
-        if ($max_gid < $g[2]) {
-            $max_gid = $g[2];
-            $max_group = $g[0];
-        }
-    }
-    skip 'getgrent() appears to be insane', $skip_count
-        unless $max_gid > 0;
-
-    $dir = catdir($dir_stem, 'aaa');
-    @created = make_path($dir, {owner => $max_user});
-    is(scalar(@created), 2, "created a directory owned by $max_user...");
-    my $dir_uid = (stat $created[0])[4];
-    is($dir_uid, $max_uid, "... owned by $max_uid");
-
-    $dir = catdir($dir_stem, 'aab');
-    @created = make_path($dir, {group => $max_group});
-    is(scalar(@created), 1, "created a directory owned by group $max_group...");
-    my $dir_gid = (stat $created[0])[5];
-    is($dir_gid, $max_gid, "... owned by group $max_gid");
-
-    $dir = catdir($dir_stem, 'aac');
-    @created = make_path($dir, {user => $max_user, group => $max_group});
-    is(scalar(@created), 1, "created a directory owned by $max_user:$max_group...");
-    ($dir_uid, $dir_gid) = (stat $created[0])[4,5];
-    is($dir_uid, $max_uid, "... owned by $max_uid");
-    is($dir_gid, $max_gid, "... owned by group $max_gid");
+my $dir_base = catdir($tmp_base,'output');
+my $dir_a    = catdir($dir_base, 'A');
+my $dir_b    = catdir($dir_base, 'B');
 
-    SKIP: {
-        skip 'Test::Output not available', 1
-               unless $has_Test_Output;
-
-        # invent a user and group that don't exist
-        do { ++$max_user  } while (getpwnam($max_user));
-        do { ++$max_group } while (getgrnam($max_group));
-
-        $dir = catdir($dir_stem, 'aad');
-        stderr_like(
-            sub {make_path($dir, {user => $max_user, group => $max_group})},
-            qr{\Aunable to map $max_user to a uid, ownership not changed: .* at \S+ line \d+
-unable to map $max_group to a gid, group ownership not changed: .* at \S+ line \d+\b},
-            "created a directory not owned by $max_user:$max_group..."
-        );
-    }
-}
+is(_run_for_verbose(sub {@created = mkpath($dir_a, 1)}),
+    _verbose_expected('mkpath', $dir_base, 0, 1)
+    . _verbose_expected('mkpath', $dir_a, 0),
+    'mkpath verbose (old style 1)'
+);
 
-SKIP: {
-    skip 'Test::Output not available', 18
-        unless $has_Test_Output;
+is(_run_for_verbose(sub {@created = mkpath([$dir_b], 1)}),
+    _verbose_expected('mkpath', $dir_b, 0),
+    'mkpath verbose (old style 2)'
+);
 
-    SKIP: {
-        $dir = catdir('EXTRA', '3');
-        skip "extra scenarios not set up, see eg/setup-extra-tests", 3
-            unless -e $dir;
-
-        $dir = catdir('EXTRA', '3', 'U');
-        stderr_like(
-            sub {rmtree($dir, {verbose => 0})},
-            qr{\Acannot make child directory read-write-exec for [^:]+: .* at \S+ line \d+},
-            q(rmtree can't chdir into root dir)
-        );
+my $verbose_expected;
 
-        $dir = catdir('EXTRA', '3');
-        stderr_like(
-            sub {rmtree($dir, {})},
-            qr{\Acannot make child directory read-write-exec for [^:]+: .* at (\S+) line (\d+)
-cannot make child directory read-write-exec for [^:]+: .* at \1 line \2
-cannot make child directory read-write-exec for [^:]+: .* at \1 line \2
-cannot remove directory for [^:]+: .* at \1 line \2},
-            'rmtree with file owned by root'
-        );
+# Must determine expectations while directories still exist.
+$verbose_expected = _verbose_expected('rmtree', $dir_a, 1)
+                  . _verbose_expected('rmtree', $dir_b, 1);
 
-        stderr_like(
-            sub {rmtree('EXTRA', {})},
-            qr{\Acannot remove directory for [^:]+: .* at (\S+) line (\d+)
-cannot remove directory for [^:]+: .* at \1 line \2
-cannot make child directory read-write-exec for [^:]+: .* at \1 line \2
-cannot make child directory read-write-exec for [^:]+: .* at \1 line \2
-cannot make child directory read-write-exec for [^:]+: .* at \1 line \2
-cannot remove directory for [^:]+: .* at \1 line \2
-cannot unlink file for [^:]+: .* at \1 line \2
-cannot restore permissions to \d+ for [^:]+: .* at \1 line \2
-cannot make child directory read-write-exec for [^:]+: .* at \1 line \2
-cannot remove directory for [^:]+: .* at \1 line \2},
-            'rmtree with insufficient privileges'
-        );
-    }
+is(_run_for_verbose(sub {$count = rmtree([$dir_a, $dir_b], 1, 1)}),
+    $verbose_expected,
+    'rmtree verbose (old style)'
+);
 
-    my $base = catdir($tmp_base,'output');
-    $dir  = catdir($base,'A');
-    $dir2 = catdir($base,'B');
+# In case we didn't delete them in safe mode.
+rmtree($dir_a) if -d $dir_a;
+rmtree($dir_b) if -d $dir_b;
 
-    stderr_like(
-        sub { rmtree( undef, 1 ) },
-        qr/\ANo root path\(s\) specified\b/,
-        "rmtree of nothing carps sensibly"
-    );
+is(_run_for_verbose(sub {@created = mkpath( $dir_a,
+                                            {verbose => 1, mask => 0750})}),
+    _verbose_expected('mkpath', $dir_a, 0),
+    'mkpath verbose (new style 1)'
+);
 
-    stderr_like(
-        sub { rmtree( '', 1 ) },
-        qr/\ANo root path\(s\) specified\b/,
-        "rmtree of empty dir carps sensibly"
-    );
+is(_run_for_verbose(sub {@created = mkpath($dir_b, 1, 0771)}),
+    _verbose_expected('mkpath', $dir_b, 0),
+    'mkpath verbose (new style 2)'
+);
 
-    stderr_is( sub { make_path() }, '', "make_path no args does not carp" );
-    stderr_is( sub { remove_tree() }, '', "remove_tree no args does not carp" );
-    stderr_is( sub { mkpath() }, '', "mkpath no args does not carp" );
+$verbose_expected = _verbose_expected('rmtree', $dir_a, 1)
+                  . _verbose_expected('rmtree', $dir_b, 1);
 
-    stdout_is(
-        sub {@created = mkpath($dir, 1)},
-        "mkdir $base\nmkdir $dir\n",
-        'mkpath verbose (old style 1)'
-    );
+is(_run_for_verbose(sub {$count = rmtree([$dir_a, $dir_b], 1, 1)}),
+    $verbose_expected,
+    'again: rmtree verbose (old style)'
+);
 
-    stdout_is(
-        sub {@created = mkpath([$dir2], 1)},
-        "mkdir $dir2\n",
-        'mkpath verbose (old style 2)'
-    );
+rmtree($dir_a) if -d $dir_a;
+rmtree($dir_b) if -d $dir_b;
 
-    stdout_is(
-        sub {$count = rmtree([$dir, $dir2], 1, 1)},
-        "rmdir $dir\nrmdir $dir2\n",
-        'rmtree verbose (old style)'
-    );
+is(_run_for_verbose(sub {@created = make_path( $dir_a, $dir_b,
+                                               {verbose => 1, mode => 0711});}),
+      _verbose_expected('make_path', $dir_a, 1)
+    . _verbose_expected('make_path', $dir_b, 1),
+    'make_path verbose with final hashref'
+);
 
-    stdout_is(
-        sub {@created = mkpath($dir, {verbose => 1, mask => 0750})},
-        "mkdir $dir\n",
-        'mkpath verbose (new style 1)'
-    );
+$verbose_expected = _verbose_expected('remove_tree', $dir_a, 0)
+                  . _verbose_expected('remove_tree', $dir_b, 0);
 
-    stdout_is(
-        sub {@created = mkpath($dir2, 1, 0771)},
-        "mkdir $dir2\n",
-        'mkpath verbose (new style 2)'
-    );
+is(_run_for_verbose(sub {@created = remove_tree( $dir_a, $dir_b,
+                                                 {verbose => 1});}),
+    $verbose_expected,
+    'remove_tree verbose with final hashref'
+);
+
+rmtree($dir_a) if -d $dir_a;
+rmtree($dir_b) if -d $dir_b;
+
+# Have to re-create these 2 directories so that next block is not skipped.
+@created = make_path(
+    $dir_a,
+    $dir_b,
+    { mode => 0711 }
+);
+is(@created, 2, "2 directories created");
 
-    stdout_is(
-        sub {$count = rmtree([$dir, $dir2], 1, 1)},
-        "rmdir $dir\nrmdir $dir2\n",
-        'again: rmtree verbose (old style)'
+SKIP: {
+    $file = catfile($dir_b, "file");
+    skip "Cannot create $file", 2 unless open OUT, "> $file";
+    print OUT "test file, safe to delete\n", scalar(localtime), "\n";
+    close OUT;
+
+    $verbose_expected = _verbose_expected('rmtree', $dir_a, 1)
+                      . _verbose_expected('unlink', $file, 0)
+                      . _verbose_expected('rmtree', $dir_b, 1);
+
+    ok(-e $file, "file created in directory");
+
+    is(_run_for_verbose(sub {$count = rmtree( $dir_a, $dir_b,
+                                              {verbose => 1, safe => 1})}),
+        $verbose_expected,
+        'rmtree safe verbose (new style)'
     );
+    rmtree($dir_a) if -d $dir_a;
+    rmtree($dir_b) if -d $dir_b;
+}
+
+{
+    my $base = catdir( $tmp_base, 'output2');
+    my $dir  = catdir( $base, 'A');
+    my $dir2 = catdir( $base, 'B');
 
-    stdout_is(
-        sub {
-            @created = make_path(
+    {
+        my $warn = _run_for_warning( sub {
+            my @created = make_path(
                 $dir,
                 $dir2,
-                { verbose => 1, mode => 0711 }
+                { mode => 0711, foo => 1, bar => 1 }
             );
-        },
-        "mkdir $dir\nmkdir $dir2\n",
-        'make_path verbose with final hashref'
-    );
+        } );
+        like($warn,
+            qr/Unrecognized option\(s\) passed to mkpath\(\) or make_path\(\):.*?bar.*?foo/,
+            'make_path with final hashref warned due to unrecognized options'
+        );
+    }
 
-    # {
-    #     local $@;
-    #     eval {
-    #         @created = make_path(
-    #             $dir,
-    #             $dir2,
-    #             { verbose => 1, mode => 0711, foo => 1, bar => 1 }
-    #         );
-    #     };
-    #     like($@,
-    #         qr/Unrecognized option\(s\) passed to make_path\(\):.*?bar.*?foo/,
-    #         'make_path with final hashref failed due to unrecognized options'
-    #     );
-    # }
-    #
-    # {
-    #     local $@;
-    #     eval {
-    #         @created = remove_tree(
-    #             $dir,
-    #             $dir2,
-    #             { verbose => 1, foo => 1, bar => 1 }
-    #         );
-    #     };
-    #     like($@,
-    #         qr/Unrecognized option\(s\) passed to remove_tree\(\):.*?bar.*?foo/,
-    #         'remove_tree with final hashref failed due to unrecognized options'
-    #     );
-    # }
-
-    stdout_is(
-        sub {
-            @created = remove_tree(
+    {
+        my $warn = _run_for_warning( sub {
+            my @created = remove_tree(
                 $dir,
                 $dir2,
-                { verbose => 1 }
+                { foo => 1, bar => 1 }
             );
-        },
-        "rmdir $dir\nrmdir $dir2\n",
-        'remove_tree verbose with final hashref'
-    );
-
-    SKIP: {
-        $file = catdir($dir2, "file");
-        skip "Cannot create $file", 2 unless open OUT, "> $file";
-        print OUT "test file, safe to delete\n", scalar(localtime), "\n";
-        close OUT;
-
-        ok(-e $file, "file created in directory");
-
-        stdout_is(
-            sub {$count = rmtree($dir, $dir2, {verbose => 1, safe => 1})},
-            "rmdir $dir\nunlink $file\nrmdir $dir2\n",
-            'rmtree safe verbose (new style)'
+        } );
+        like($warn,
+            qr/Unrecognized option\(s\) passed to remove_tree\(\):.*?bar.*?foo/,
+            'remove_tree with final hashref failed due to unrecognized options'
         );
     }
 }
 
 SKIP: {
-    skip "extra scenarios not set up, see eg/setup-extra-tests", 11
-        unless -d catdir(qw(EXTRA 1));
-
-    rmtree 'EXTRA', {safe => 0, error => \$error};
-    is( scalar(@$error), 10, 'seven deadly sins' ); # well there used to be 7
-
-    rmtree 'EXTRA', {safe => 1, error => \$error};
-    is( scalar(@$error), 9, 'safe is better' );
-    for (@$error) {
-        ($file, $message) = each %$_;
-        if ($file =~  /[123]\z/) {
-            is(index($message, 'cannot remove directory: '), 0, "failed to remove $file with rmdir")
-                or diag($message);
-        }
-        else {
-            like($message, qr(\Acannot (?:restore permissions to \d+|chdir to child|unlink file): ), "failed to remove $file with unlink")
-                or diag($message)
-        }
-    }
-}
-
-SKIP: {
     my $nr_tests = 6;
     my $cwd = getcwd() or skip "failed to getcwd: $!", $nr_tests;
     rmtree($tmp_base, {result => \$list} );
@@ -832,14 +655,17 @@ SKIP: {
     ok(mkpath($xx), "make $xx");
     ok(chdir($xx), "... and chdir $xx");
     END {
-         ok(chdir($p), "... now chdir $p");
-         ok(rmtree($xx), "... and finally rmtree $xx");
+#         ok(chdir($p), "... now chdir $p");
+#         ok(rmtree($xx), "... and finally rmtree $xx");
+       chdir($p);
+       rmtree($xx);
     }
 
     # create and delete directory
     my $px = catdir($p, $x);
     ok(mkpath($px), 'create and delete directory 2.07');
     ok(rmtree($px), '.. rmtree fails in File-Path-2.07');
+    chdir updir();
 }
 
 my $windows_dir = 'C:\Path\To\Dir';
@@ -849,3 +675,285 @@ is(
     $expect,
     "Windows path unixified as expected"
 );
+
+{
+    my ($x, $message, $object, $expect, $rv, $arg, $error);
+    my ($k, $v, $second_error, $third_error);
+    local $! = ENOENT;
+    $x = $!;
+
+    $message = 'message in a bottle';
+    $object = '/path/to/glory';
+    $expect = "$message for $object: $x";
+    $rv = _run_for_warning( sub {
+        File::Path::_error(
+            {},
+            $message,
+            $object
+        );
+    } );
+    like($rv, qr/^$expect/,
+        "no \$arg->{error}: defined 2nd and 3rd args: got expected error message");
+
+    $object = undef;
+    $expect = "$message: $x";
+    $rv = _run_for_warning( sub {
+        File::Path::_error(
+            {},
+            $message,
+            $object
+        );
+    } );
+    like($rv, qr/^$expect/,
+        "no \$arg->{error}: defined 2nd arg; undefined 3rd arg: got expected error message");
+
+    $message = 'message in a bottle';
+    $object = undef;
+    $expect = "$message: $x";
+    $arg = { error => \$error };
+    File::Path::_error(
+        $arg,
+        $message,
+        $object
+    );
+    is(ref($error->[0]), 'HASH',
+        "first element of array inside \$error is hashref");
+    ($k, $v) = %{$error->[0]};
+    is($k, '', 'key of hash is empty string, since 3rd arg was undef');
+    is($v, $expect, "value of hash is 2nd arg: $message");
+
+    $message = '';
+    $object = '/path/to/glory';
+    $expect = "$message: $x";
+    $arg = { error => \$second_error };
+    File::Path::_error(
+        $arg,
+        $message,
+        $object
+    );
+    is(ref($second_error->[0]), 'HASH',
+        "first element of array inside \$second_error is hashref");
+    ($k, $v) = %{$second_error->[0]};
+    is($k, $object, "key of hash is '$object', since 3rd arg was defined");
+    is($v, $expect, "value of hash is 2nd arg: $message");
+
+    $message = '';
+    $object = undef;
+    $expect = "$message: $x";
+    $arg = { error => \$third_error };
+    File::Path::_error(
+        $arg,
+        $message,
+        $object
+    );
+    is(ref($third_error->[0]), 'HASH',
+        "first element of array inside \$third_error is hashref");
+    ($k, $v) = %{$third_error->[0]};
+    is($k, '', "key of hash is empty string, since 3rd arg was undef");
+    is($v, $expect, "value of hash is 2nd arg: $message");
+}
+
+{
+    # https://rt.cpan.org/Ticket/Display.html?id=117019
+    # remove_tree(): Permit re-use of options hash without issuing a warning
+
+    my ($least_deep, $next_deepest, $deepest) =
+        create_3_level_subdirs( qw| ZoYhvc6RmGnl S2CrQ0lju0o7 lvOqVYWpfhcP | );
+    my @created;
+    @created = File::Path::make_path($deepest, { mode => 0711 });
+    is(scalar(@created), 3, "Created 3 subdirectories");
+
+    my $x = '';
+    my $opts = { error => \$x };
+    File::Path::remove_tree($deepest, $opts);
+    ok(! -d $deepest, "directory '$deepest' removed, as expected");
+
+    my $warn;
+    $warn = _run_for_warning( sub { File::Path::remove_tree($next_deepest, $opts); } );
+    ok(! $warn, "CPAN 117019: No warning thrown when re-using \$opts");
+    ok(! -d $next_deepest, "directory '$next_deepest' removed, as expected");
+
+    $warn = _run_for_warning( sub { File::Path::remove_tree($least_deep, $opts); } );
+    ok(! $warn, "CPAN 117019: No warning thrown when re-using \$opts");
+    ok(! -d $least_deep, "directory '$least_deep' removed, as expected");
+}
+
+{
+    # Corner cases with respect to arguments provided to functions
+    my $count;
+
+    $count = remove_tree();
+    is($count, 0,
+        "If not provided with any paths, remove_tree() will return a count of 0 things deleted");
+
+    $count = remove_tree('');
+    is($count, 0,
+        "If not provided with any paths, remove_tree() will return a count of 0 things deleted");
+
+    my $warn;
+    $warn = _run_for_warning( sub { $count = rmtree(); } );
+    like($warn, qr/No root path\(s\) specified/s, "Got expected carp");
+    is($count, 0,
+        "If not provided with any paths, remove_tree() will return a count of 0 things deleted");
+
+    $warn = _run_for_warning( sub {$count = rmtree(undef); } );
+    like($warn, qr/No root path\(s\) specified/s, "Got expected carp");
+    is($count, 0,
+        "If provided only with an undefined value, remove_tree() will return a count of 0 things deleted");
+
+    $warn = _run_for_warning( sub {$count = rmtree(''); } );
+    like($warn, qr/No root path\(s\) specified/s, "Got expected carp");
+    is($count, 0,
+        "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);
+}