1use strict;
2use Test::More;
3use lib './t';
4use FilePathTest qw(
5    create_3_level_subdirs
6    cleanup_3_level_subdirs
7);
8use File::Path;
9use Cwd;
10use File::Spec::Functions;
11use Carp;
12
13plan skip_all  => 'not win32' unless $^O eq 'MSWin32';
14my ($ignore, $major, $minor, $build, $id) = Win32::GetOSVersion();
15plan skip_all  => "WinXP or later"
16     unless $id >= 2 && ($major > 5 || $major == 5 && $minor >= 1);
17plan tests     => 9;
18
19my $tmp_base = catdir(
20    curdir(),
21    sprintf( 'test-%x-%x-%x', time, $$, rand(99999) ),
22);
23
24my $UNC_path = catdir(getcwd(), $tmp_base, 'uncdir');
25#dont compute a SMB path with $ENV{COMPUTERNAME}, since SMB may be turned off
26#firewalled, disabled, blocked, or no NICs are on and there the PC has no
27#working TCPIP stack, \\?\ will always work
28$UNC_path = '\\\\?\\'.$UNC_path;
29
30is(mkpath($UNC_path), 2, 'mkpath on Win32 UNC path returns made 2 dir - base and uncdir');
31
32ok(-d $UNC_path, 'mkpath on Win32 UNC path made dir');
33
34my $removed = rmtree($UNC_path);
35
36cmp_ok($removed, '>', 0, "removed $removed entries from $UNC_path");
37
38{
39    my ($least_deep, $next_deepest, $deepest) =
40        create_3_level_subdirs( qw| IsVFFJfJ03Rk jD7ToWQFmcjm hMZR6S1qNSf5 | );
41    my (@created, $error);
42    my $user = join('_' => 'foobar', $$);
43    {
44        my $warn;
45        $SIG{__WARN__} = sub { $warn = shift };
46
47        @created = mkpath($deepest, { mode => 0711, user => $user, error => \$error });
48        like($warn,
49            qr/Option\(s\) implausible on Win32 passed to mkpath\(\) or make_path\(\)/,
50            'make_path with final hashref warned due to options implausible on Win32'
51        );
52        TODO: {
53            local $TODO = "Notwithstanding the Win32-implausible 'user', mkpath will actually create subdirectories; should it?";
54            is(scalar(@created), 0, "No subdirectories created");
55        }
56        is(scalar(@created), 3, "3 subdirectories created");
57        is(scalar(@$error), 0, "no error condition" );
58    }
59
60    cleanup_3_level_subdirs($least_deep);
61}
62
63