summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/cpan/File-Temp/t/rmtree.t
blob: c5c98d75e45dbd15909b14903ac85109a8cd7e34 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/perl

use Test::More tests => 1;

use File::Spec;
use File::Path;
use File::Temp;

rmtree "testing";
mkdir "testing" or die "mkdir failed: $!";
chdir "testing";
mkdir "tmp" or die "mkdir failed: $!";

my $tempdirstr;
{
    my $dir = File::Temp->newdir( DIR => "tmp" );
    $tempdirstr = "$dir";

    mkdir "hide" or die "mkdir failed: $!";
    chdir "hide";
}

chdir File::Spec->updir;
$tempdirstr = File::Spec->rel2abs($tempdirstr);
ok !-d $tempdirstr or diag dircontent("tmp", $tempdirstr);

# cleanup
chdir File::Spec->updir;
rmtree( "testing" );

exit;

sub dircontent {
  my $dir = shift;
  my $tempdirstr = shift;
  my $str = "Contents of $dir (should not contain \"$tempdirstr\"):\n";
  opendir(my $DH, $dir) or die "opendir failed; $!";
  my @contents = grep { $_ !~ /^\.+/; } readdir($DH);
  closedir($DH);
  for my $ls (@contents) {
    $str .= "  $ls\n";
  }
  return $str;
}