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