1use strict; 2use warnings; 3 4use Test::More 0.88; 5use Test::Builder; 6use Test::MooseX::Daemonize; 7use MooseX::Daemonize; 8 9my $Test = Test::Builder->new; 10 11{ 12 13 package TestOutput; 14 use Moose; 15 with qw(MooseX::Daemonize); 16 with qw(Test::MooseX::Daemonize::Testable); # setup our test environment 17 18 after start => sub { 19 my ($self) = @_; 20 $self->output_ok() 21 if $self->is_daemon; 22 }; 23 24 sub output_ok { 25 my ($self) = @_; 26 my $count = 1; 27 for ( 0 .. 3 ) { 28 $Test->ok( $count++, "$count output_ok" ); 29 sleep(1); 30 } 31 } 32 no Moose; 33} 34 35package main; 36use strict; 37use warnings; 38 39use File::Spec::Functions; 40use File::Temp qw(tempdir); 41 42my $dir = tempdir( CLEANUP => 1 ); 43 44## Try to make sure we are in the test directory 45my $app = TestOutput->new( 46 pidbase => $dir, 47 test_output => catfile($dir, 'results'), 48); 49daemonize_ok( $app, 'child forked okay' ); 50sleep(3); # give ourself a chance to produce some output 51 52my $warnings = ""; 53{ 54 local $SIG{__WARN__} = sub { $warnings .= $_[0]; warn @_ }; 55 $app->stop( no_exit => 1 ); 56} 57 58is($warnings, "", "No warnings from stop"); 59 60check_test_output($app); 61unlink( $app->test_output ); 62 63done_testing; 64 65exit; 66