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