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
43d819aa 17 after start => sub {
18 my $self = shift;
19 $self->create_file( $self->filename )
20 if $self->is_daemon;
21 };
7d7115e5 22
a4952679 23 sub create_file {
24 my ( $self, $file ) = @_;
3543c999 25 open( my $FILE, ">$file" ) || die $!;
26 close($FILE);
a4952679 27 }
28
29 no Moose;
30}
31
32package main;
b916501e 33use strict;
34use warnings;
7d7115e5 35use Cwd;
a4952679 36
37## Try to make sure we are in the test directory
7d7115e5 38chdir 't' if ( Cwd::cwd() !~ m|/t$| );
a4952679 39my $cwd = Cwd::cwd();
a4952679 40
3543c999 41my $app = FileMaker->new(
42 pidbase => $cwd,
43 filename => "$cwd/im_alive",
44);
45daemonize_ok( $app, 'child forked okay' );
b916501e 46ok( -e $app->filename, "file exists" );
3543c999 47ok( $app->stop( no_exit => 1 ), 'app stopped' );
b916501e 48ok( not(-e $app->pidfile) , 'pidfile gone' );
3543c999 49unlink( $app->filename );