add Test::MooseX::Daemonize
[gitmo/MooseX-Daemonize.git] / t / 01.filecreate.t
1 use Test::More tests => 2;
2 use Test::MooseX::Daemonize;
3
4 ##  Since a daemon will not be able to print terminal output, we
5 ##  have a test daemon create a file, and another process test for
6 ##  its existence.
7
8 {
9
10     package FileMaker;
11     use Moose;
12     with qw(MooseX::Daemonize);
13
14     has filename => ( isa => 'Str', is => 'ro' );
15
16     after start => sub { $_[0]->create_file( $_[0]->filename ) };
17
18     sub create_file {
19         my ( $self, $file ) = @_;
20         open( FILE, ">$file" ) || die $!;
21         close(FILE);
22     }
23
24     no Moose;
25 }
26
27
28 package main;
29 use Cwd;
30
31 ## Try to make sure we are in the test directory
32 chdir 't' if ( Cwd::cwd() !~ m|/t$| );
33 my $cwd = Cwd::cwd();
34
35 my $file = join( '/', $cwd, 'im_alive' );
36 my $daemon = FileMaker->new( pidbase => '.', filename => $file );
37
38 daemonize_ok( $daemon, 'child forked okay' );
39 ok( -e $file, "$file exists" );
40 unlink($file);
41