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