okay,.. I think this is ready for release
[gitmo/MooseX-Daemonize.git] / t / 01.filecreate.t
CommitLineData
3543c999 1use Test::More tests => 4;
7d7115e5 2use Test::MooseX::Daemonize;
3543c999 3use MooseX::Daemonize;
a4952679 4
5## Since a daemon will not be able to print terminal output, we
6## have a test daemon create a file, and another process test for
7## its existence.
8
9{
10
11 package FileMaker;
12 use Moose;
13 with qw(MooseX::Daemonize);
14
7d7115e5 15 has filename => ( isa => 'Str', is => 'ro' );
2eced271 16
7d7115e5 17 after start => sub { $_[0]->create_file( $_[0]->filename ) };
18
a4952679 19 sub create_file {
20 my ( $self, $file ) = @_;
3543c999 21 open( my $FILE, ">$file" ) || die $!;
22 close($FILE);
a4952679 23 }
24
25 no Moose;
26}
27
28package main;
b916501e 29use strict;
30use warnings;
7d7115e5 31use Cwd;
a4952679 32
33## Try to make sure we are in the test directory
7d7115e5 34chdir 't' if ( Cwd::cwd() !~ m|/t$| );
a4952679 35my $cwd = Cwd::cwd();
a4952679 36
3543c999 37my $app = FileMaker->new(
38 pidbase => $cwd,
39 filename => "$cwd/im_alive",
40);
41daemonize_ok( $app, 'child forked okay' );
b916501e 42ok( -e $app->filename, "file exists" );
3543c999 43ok( $app->stop( no_exit => 1 ), 'app stopped' );
b916501e 44ok( not(-e $app->pidfile) , 'pidfile gone' );
3543c999 45unlink( $app->filename );