Commit | Line | Data |
7d7115e5 |
1 | use Test::More tests => 2; |
2 | use Test::MooseX::Daemonize; |
a4952679 |
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 | |
7d7115e5 |
14 | has filename => ( isa => 'Str', is => 'ro' ); |
15 | |
16 | after start => sub { $_[0]->create_file( $_[0]->filename ) }; |
17 | |
a4952679 |
18 | sub create_file { |
19 | my ( $self, $file ) = @_; |
20 | open( FILE, ">$file" ) || die $!; |
21 | close(FILE); |
22 | } |
23 | |
24 | no Moose; |
25 | } |
26 | |
7d7115e5 |
27 | |
a4952679 |
28 | package main; |
7d7115e5 |
29 | use Cwd; |
a4952679 |
30 | |
31 | ## Try to make sure we are in the test directory |
7d7115e5 |
32 | chdir 't' if ( Cwd::cwd() !~ m|/t$| ); |
a4952679 |
33 | my $cwd = Cwd::cwd(); |
a4952679 |
34 | |
a4952679 |
35 | my $file = join( '/', $cwd, 'im_alive' ); |
7d7115e5 |
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 | |