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