xref: /openbsd/gnu/usr.bin/perl/cpan/File-Temp/t/rmtree.t (revision 5af055cd)
1#!/usr/bin/perl
2
3use Test::More tests => 1;
4
5use File::Spec;
6use File::Path;
7use File::Temp;
8
9rmtree "testing";
10mkdir "testing" or die "mkdir failed: $!";
11chdir "testing";
12mkdir "tmp" or die "mkdir failed: $!";
13
14my $tempdirstr;
15{
16    my $dir = File::Temp->newdir( DIR => "tmp" );
17    $tempdirstr = "$dir";
18
19    mkdir "hide" or die "mkdir failed: $!";
20    chdir "hide";
21}
22
23chdir File::Spec->updir;
24$tempdirstr = File::Spec->rel2abs($tempdirstr);
25ok !-d $tempdirstr or diag dircontent("tmp", $tempdirstr);
26
27# cleanup
28chdir File::Spec->updir;
29rmtree( "testing" );
30
31exit;
32
33sub dircontent {
34  my $dir = shift;
35  my $tempdirstr = shift;
36  my $str = "Contents of $dir (should not contain \"$tempdirstr\"):\n";
37  opendir(my $DH, $dir) or die "opendir failed; $!";
38  my @contents = grep { $_ !~ /^\.+/; } readdir($DH);
39  closedir($DH);
40  for my $ls (@contents) {
41    $str .= "  $ls\n";
42  }
43  return $str;
44}
45