7 use File::Spec::Functions;
9 our @EXPORT = qw(_run_for_warning _run_for_verbose _basedir
10 _cannot_delete_safe_mode
14 return catdir( curdir(),
15 sprintf( 'test-%x-%x-%x', time, $$, rand(99999) ),
20 sub _run_for_warning {
23 local $SIG{__WARN__} = sub { $warn .= shift };
28 sub _run_for_verbose {
32 my $guard = SelectSaver->new(_ref_to_fh(\$stdout));
40 open my $fh, '>', $output;
44 # Whether a directory can be deleted without modifying permissions varies
45 # by platform and by current privileges, so we really have to do the same
46 # check the module does in safe mode to determine that.
48 sub _cannot_delete_safe_mode {
51 ? !&VMS::Filespec::candelete($path)
55 # What verbose mode reports depends on what it can do in safe mode.
56 # Plus on VMS, mkpath may report what it's operating on in a
57 # different format from the format of the path passed to it.
59 sub _verbose_expected {
60 my ($function, $path, $safe_mode, $base) = @_;
63 if ($function =~ m/^(mkpath|make_path)$/) {
64 # On VMS, mkpath reports in Unix format. Maddeningly, it
65 # reports the top-level directory without a trailing slash
66 # and everything else with.
68 $path = VMS::Filespec::unixify($path);
69 $path =~ s/\/$// if defined $base && $base;
71 $expected = "mkdir $path\n";
73 elsif ($function =~ m/^(rmtree|remove_tree)$/) {
74 # N.B. Directories must still/already exist for this to work.
75 $expected = $safe_mode && _cannot_delete_safe_mode($path)
79 elsif ($function =~ m/^(unlink)$/) {
80 $expected = "unlink $path\n";
81 $expected =~ s/\n\z/\.\n/ if $^O eq 'VMS';
84 die "Unknown function $function in _verbose_expected";
91 eval qq{#line @{[__LINE__+1]} "@{[__FILE__]}"\n} . <<'END' or die $@;
92 no warnings 'redefine';
97 my $fh = Symbol::gensym();
98 tie *$fh, 'StringIO', $output;
103 sub TIEHANDLE { bless [ $_[1] ], $_[0] }
104 sub CLOSE { @{$_[0]} = (); 1 }
105 sub PRINT { ${ $_[0][0] } .= $_[1] }
106 sub PRINTF { ${ $_[0][0] } .= sprintf $_[1], @_[2..$#_] }