Fix perlcritic test so it doesn't bomb if Perl::Critic isn't installed
[gitmo/MooseX-Daemonize.git] / t / 01.filecreate.t
CommitLineData
3543c999 1use Test::More tests => 4;
7d7115e5 2use Test::MooseX::Daemonize;
3543c999 3use MooseX::Daemonize;
a4952679 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
7d7115e5 15 has filename => ( isa => 'Str', is => 'ro' );
7d7115e5 16 after start => sub { $_[0]->create_file( $_[0]->filename ) };
17
a4952679 18 sub create_file {
19 my ( $self, $file ) = @_;
3543c999 20 open( my $FILE, ">$file" ) || die $!;
21 close($FILE);
a4952679 22 }
23
24 no Moose;
25}
26
27package main;
7d7115e5 28use Cwd;
a4952679 29
30## Try to make sure we are in the test directory
7d7115e5 31chdir 't' if ( Cwd::cwd() !~ m|/t$| );
a4952679 32my $cwd = Cwd::cwd();
a4952679 33
3543c999 34my $app = FileMaker->new(
35 pidbase => $cwd,
36 filename => "$cwd/im_alive",
37);
38daemonize_ok( $app, 'child forked okay' );
39ok( -e $app->filename, "$file exists" );
40ok( $app->stop( no_exit => 1 ), 'app stopped' );
41ok( -e $app->pidfile == undef, 'pidfile gone' );
42unlink( $app->filename );