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