X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F01.filecreate.t;h=127c0e830a1382688a37ded84ce8e32c9c19d6c0;hb=f3372ec96b39b4940acc393785b63df2ac229b96;hp=d4e977af93b6205632243fc70fb2d4849fe7ae17;hpb=92cf56b7c3fd91568e4b964319a7862fc4f1d651;p=gitmo%2FMooseX-Daemonize.git diff --git a/t/01.filecreate.t b/t/01.filecreate.t index d4e977a..127c0e8 100644 --- a/t/01.filecreate.t +++ b/t/01.filecreate.t @@ -1,23 +1,23 @@ -#!/usr/bin/perl - use strict; use warnings; -use Cwd; use File::Spec::Functions; use Test::More tests => 29; use Test::Moose; +use File::Temp qw(tempdir); + +my $dir = tempdir( CLEANUP => 1 ); + BEGIN { use_ok('MooseX::Daemonize'); } use constant DEBUG => 0; -my $CWD = Cwd::cwd; -my $FILENAME = "$CWD/im_alive"; -$ENV{MX_DAEMON_STDOUT} = catfile($CWD, 'Out.txt'); -$ENV{MX_DAEMON_STDERR} = catfile($CWD, 'Err.txt'); +my $FILENAME = catfile($dir, "im_alive"); +$ENV{MX_DAEMON_STDOUT} = catfile($dir, 'Out.txt'); +$ENV{MX_DAEMON_STDERR} = catfile($dir, 'Err.txt'); { @@ -26,8 +26,8 @@ $ENV{MX_DAEMON_STDERR} = catfile($CWD, 'Err.txt'); with qw(MooseX::Daemonize); has filename => ( isa => 'Str', is => 'ro' ); - - after start => sub { + + after start => sub { my $self = shift; if ($self->is_daemon) { $self->create_file( $self->filename ); @@ -38,11 +38,12 @@ $ENV{MX_DAEMON_STDERR} = catfile($CWD, 'Err.txt'); my ( $self, $file ) = @_; open( my $FILE, ">$file" ) || die $!; close($FILE); + sleep 1 while 1; } } my $app = FileMaker->new( - pidbase => $CWD, + pidbase => "$dir/subdir", filename => $FILENAME, ); isa_ok($app, 'FileMaker'); @@ -52,7 +53,7 @@ does_ok($app, 'MooseX::Daemonize::Core'); isa_ok($app->pidfile, 'MooseX::Daemonize::Pid::File'); -is($app->pidfile->file, "$CWD/filemaker.pid", '... got the right PID file path'); +is($app->pidfile->file, catfile("$dir/subdir", "filemaker.pid"), '... got the right PID file path'); ok(not(-e $app->pidfile->file), '... our pidfile does not exist'); ok(!$app->status, '... the daemon is running'); @@ -81,14 +82,14 @@ is($app->exit_code, MooseX::Daemonize->OK, '... got the right error code'); if (DEBUG) { diag `ps $pid`; - diag "Status is: " . $app->status_message; + diag "Status is: " . $app->status_message; } ok( -e $app->filename, "file exists" ); if (DEBUG) { diag `ps $pid`; - diag "Status is: " . $app->status_message; + diag "Status is: " . $app->status_message; } ok( $app->stop, '... app stopped' ); @@ -101,7 +102,7 @@ is($app->exit_code, MooseX::Daemonize->ERROR, '... got the right error code'); if (DEBUG) { diag `ps $pid`; - diag "Status is: " . $app->status_message; + diag "Status is: " . $app->status_message; } ok( not(-e $app->pidfile->file) , '... pidfile gone' );