Skip to content

Commit

Permalink
subdir now has an env var
Browse files Browse the repository at this point in the history
  • Loading branch information
nothingmuch committed Oct 26, 2008
1 parent e3998a2 commit e7985e1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
2 changes: 1 addition & 1 deletion lib/Test/TempDir/Factory.pm
Expand Up @@ -61,7 +61,7 @@ has options => (
has use_subdir => (
isa => "Bool",
is => "rw",
default => 1,
default => sub { $ENV{TEST_TEMPDIR_USE_SUBDIR} ? 1 : 0 },
);

has subdir_template => (
Expand Down
1 change: 1 addition & 0 deletions lib/Test/TempDir/Handle.pm
Expand Up @@ -54,6 +54,7 @@ sub delete {
my $self = shift;
return unless -d $self->dir;
$self->rmtree({ keep_root => 0 });
$self->dir->parent->remove; # rmdir, safe, and we don't care about errors
}

sub release_lock {
Expand Down
80 changes: 40 additions & 40 deletions t/factory.t
Expand Up @@ -22,75 +22,75 @@ BEGIN {

use ok 'Test::TempDir::Factory';

delete @ENV{qw(TEST_TEMPDIR TEST_TMPDIR TEST_TEMPDIR_CLEANUP)};
delete @ENV{qw(TEST_TEMPDIR TEST_TMPDIR TEST_TEMPDIR_CLEANUP TEST_TEMPDIR_USE_SUBDIR)};

my $f = Test::TempDir::Factory->new;
foreach my $use_subdir ( 1, 0 ) {
my $f = Test::TempDir::Factory->new( use_subdir => $use_subdir );

isa_ok( $f, "Test::TempDir::Factory" );
isa_ok( $f, "Test::TempDir::Factory" );

is( $f->dir_name, dir("tmp"), "default dir_name" );
is( $f->t_dir, dir("t"), "default t_dir" );
is( $f->dir_name, dir("tmp"), "default dir_name" );
is( $f->t_dir, dir("t"), "default t_dir" );

$f->t_dir($tmp);
$f->t_dir($tmp);

my $subdir = $tmp->subdir($f->dir_name);
my $subdir = $tmp->subdir($f->dir_name);

is( $f->base_path, $subdir, "base path" );
is( $f->base_path, $subdir, "base path" );

ok( not(-d $f->base_path), "base path doesn't exist yet" );
ok( not(-d $f->base_path), "base path doesn't exist yet" );

ok( $f->use_subdir, "subdirs enabled" );
my ( $path, $lock ) = $f->create_and_lock($f->base_path);

my ( $path, $lock ) = $f->create_and_lock($f->base_path);
isa_ok( $path, "Path::Class::Dir" );

isa_ok( $path, "Path::Class::Dir" );
ok( $subdir->contains($path), "preferred path used" );

ok( $subdir->contains($path), "preferred path used" );
ok( -d $path, "created" );

ok( -d $path, "created" );
isa_ok( $lock, "File::NFSLock", "lock" );

isa_ok( $lock, "File::NFSLock", "lock" );
my ( $fallback_path, $fallback_lock ) = $f->create_and_lock_fallback($f->base_path);

my ( $fallback_path, $fallback_lock ) = $f->create_and_lock_fallback($f->base_path);
isa_ok( $fallback_path, "Path::Class::Dir" );

isa_ok( $fallback_path, "Path::Class::Dir" );
isnt( $fallback_path, $path, "fallback path is different" );

isnt( $fallback_path, $path, "fallback path is different" );
isa_ok( $fallback_lock, "File::NFSLock" );

isa_ok( $fallback_lock, "File::NFSLock" );
{
$f->lock(0);

{
$f->lock(0);
my ( $new_fb ) = $f->create_and_lock_fallback($f->base_path);

my ( $new_fb ) = $f->create_and_lock_fallback($f->base_path);
isnt( $new_fb, $path, "second fallback is different from base path" );
isnt( $new_fb, $fallback_path, "and from first fallback path" );

isnt( $new_fb, $path, "second fallback is different from base path" );
isnt( $new_fb, $fallback_path, "and from first fallback path" );

rmdir $new_fb;
}
rmdir $new_fb;
}


$f->lock(1);
$f->lock(1);

isa_ok( my $dir = $f->create, "Test::TempDir::Handle" );
isa_ok( my $dir = $f->create, "Test::TempDir::Handle" );

isa_ok( $dir->dir, "Path::Class::Dir" );
isa_ok( $dir->dir, "Path::Class::Dir" );

ok( $subdir->contains( $dir->dir ), "created in the right place" );
ok( $subdir->contains( $dir->dir ), "created in the right place" );

isa_ok( $dir->lock, "File::NFSLock" );
isa_ok( $dir->lock, "File::NFSLock" );

SKIP: {
my $lockfile = $dir->lock->{lock_file} or skip "no lockfile", 2;
SKIP: {
my $lockfile = $dir->lock->{lock_file} or skip "no lockfile", 2;

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

$dir->empty;
$dir->empty;

ok( -f $lockfile, "lockfile exists after ->empty" );
}

rmdir $fallback_path;
ok( -f $lockfile, "lockfile exists after ->empty" );
}

rmdir $fallback_path;

$f->base_path->rmtree({ keep_root => 0 });
}

0 comments on commit e7985e1

Please sign in to comment.