File: handle.t

package info (click to toggle)
libtest-tempdir-perl 0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 324 kB
  • sloc: perl: 422; makefile: 2
file content (62 lines) | stat: -rw-r--r-- 1,205 bytes parent folder | download | duplicates (4)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use strict;
use warnings;

use Test::More 0.88;

use Path::Class;
use File::Temp qw(tempdir);
use File::Path 2.04;    # for reliable keep_root

my $tmp;

BEGIN {
    use File::Spec;

    plan skip_all => "No writable temp dir" unless grep { -d && -w } File::Spec->tmpdir;
    $tmp = dir( tempdir( CLEANUP => 1 ) );
    plan skip_all => "couldn't create temp dir" unless -d $tmp && -w $tmp;
}

use ok 'Test::TempDir::Handle';

isa_ok( my $h = Test::TempDir::Handle->new( dir => $tmp ), "Test::TempDir::Handle" );

is( $h->dir, $tmp, "dir set" );

is( $h->cleanup_policy, "success", "default cleanup policy" );

my $file = $h->dir->file("foo");
my $subdir = $h->dir->subdir("bar");

$file->touch;
$subdir->mkpath;

ok( -f $file, "file created" );
ok( -d $subdir, "subdir created" );

$h->empty;

ok( not(-f $file), "file removed by empty" );
ok( not(-d $subdir), "subdir removed by empty" );

is_deeply( [ $h->dir->children ], [], "no children" );

ok( -d $tmp, "dir exists" );

$file->touch;

ok( -f $file, "file exists" );

$h->cleanup_policy("never");

$h->cleanup;

ok( -f $file, "file exists" );

$h->cleanup_policy("always");

$h->cleanup;

ok( not(-d $tmp), "dir removed by delete" );

done_testing;