okay,.. I think this is ready for release
[gitmo/MooseX-Daemonize.git] / t / 01.filecreate.t
1 use Test::More tests => 4;
2 use Test::MooseX::Daemonize;
3 use MooseX::Daemonize;
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
15     has filename => ( isa => 'Str', is => 'ro' );
16     
17     after start => sub { 
18         my $self = shift;
19         $self->create_file( $self->filename ) 
20             if $self->is_daemon;
21     };
22
23     sub create_file {
24         my ( $self, $file ) = @_;
25         open( my $FILE, ">$file" ) || die $!;
26         close($FILE);
27     }
28
29     no Moose;
30 }
31
32 package main;
33 use strict;
34 use warnings;
35 use Cwd;
36
37 ## Try to make sure we are in the test directory
38 chdir 't' if ( Cwd::cwd() !~ m|/t$| );
39 my $cwd = Cwd::cwd();
40
41 my $app = FileMaker->new(
42     pidbase  => $cwd,
43     filename => "$cwd/im_alive",
44 );
45 daemonize_ok( $app, 'child forked okay' );
46 ok( -e $app->filename, "file exists" );
47 ok( $app->stop( no_exit => 1 ), 'app stopped' );
48 ok( not(-e $app->pidfile) , 'pidfile gone' );
49 unlink( $app->filename );