skipping tests if you don't have Test::* installed
[gitmo/MooseX-Daemonize.git] / t / 01.filecreate.t
CommitLineData
a4952679 1use Test::More no_plan => 1;
2use Proc::Daemon;
3use Cwd;
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 sub create_file {
16 my ( $self, $file ) = @_;
17 open( FILE, ">$file" ) || die $!;
18 close(FILE);
19 }
20
21 no Moose;
22}
23
24package main;
25
26## Try to make sure we are in the test directory
27my $cwd = Cwd::cwd();
28chdir 't' if ( $cwd !~ m|/t$| );
29$cwd = Cwd::cwd();
30
31## Test filename
32my $file = join( '/', $cwd, 'im_alive' );
33## Parent process will check if file created. Child becomes the daemon.
34if ( my $pid = Proc::Daemon::Fork ) {
35 sleep(5); # Punt on sleep time, 5 seconds should be enough
36 ok( -e $file, "$file exists");
37 unlink($file);
38}
39else {
40 my $daemon = FileMaker->new(pidbase => '.');
41 $daemon->start();
42 $daemon->create_file($file);
43 $daemon->stop();
44 exit;
45}