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