Adding Cogwheel, a Moose wrapped Sprocket
[gitmo/MooseX-Daemonize.git] / t / 01.filecreate.t
CommitLineData
7d7115e5 1use Test::More tests => 2;
2use 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 28package main;
7d7115e5 29use Cwd;
a4952679 30
31## Try to make sure we are in the test directory
7d7115e5 32chdir 't' if ( Cwd::cwd() !~ m|/t$| );
a4952679 33my $cwd = Cwd::cwd();
a4952679 34
a4952679 35my $file = join( '/', $cwd, 'im_alive' );
7d7115e5 36my $daemon = FileMaker->new( pidbase => '.', filename => $file );
37
38daemonize_ok( $daemon, 'child forked okay' );
39ok( -e $file, "$file exists" );
40unlink($file);
41