X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F02.stdout.t;h=b5facae69352395d0de1f65e95b70945bbf31b43;hb=f3372ec96b39b4940acc393785b63df2ac229b96;hp=dcf2706e2a6c8ce8cbd407e60fe28af6f57bc2f3;hpb=3c3db18cb8874d075ad834a5a473b13cab751350;p=gitmo%2FMooseX-Daemonize.git diff --git a/t/02.stdout.t b/t/02.stdout.t index dcf2706..b5facae 100644 --- a/t/02.stdout.t +++ b/t/02.stdout.t @@ -1,69 +1,65 @@ -use Test::More no_plan => 1; +use strict; +use warnings; + +use Test::More; use Test::Builder; use Test::MooseX::Daemonize; +use MooseX::Daemonize; my $Test = Test::Builder->new; -chdir 't' if ( Cwd::cwd() !~ m|/t$| ); -my $cwd = Cwd::cwd(); - -my $file = join( '/', $cwd, 'results' ); { package TestOutput; use Moose; with qw(MooseX::Daemonize); - with qw(Test::MooseX::Daemonize::Testable); # setup our test environment - - has max => ( isa => 'Int', is => 'ro', default => sub { 5 } ); - + with qw(Test::MooseX::Daemonize::Testable); # setup our test environment + after start => sub { my ($self) = @_; - $self->output_ok(1); + $self->output_ok() + if $self->is_daemon; }; sub output_ok { - my ( $self, $count ) = @_; - $Test->ok( $count, "$count output_ok" ); - if ( $count++ > $self->max ) { - $self->stop(); - return; + my ($self) = @_; + my $count = 1; + for ( 0 .. 3 ) { + $Test->ok( $count++, "$count output_ok" ); + sleep(1); } - $self->output_ok($count); } no Moose; } package main; -use Cwd; +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 -chdir 't' if ( Cwd::cwd() !~ m|/t$| ); -my $cwd = Cwd::cwd(); +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 $daemon = TestOutput->new( pidbase => $cwd, test_output => $file); +my $warnings = ""; +{ + local $SIG{__WARN__} = sub { $warnings .= $_[0]; warn @_ }; + $app->stop( no_exit => 1 ); +} -daemonize_ok( $daemon, 'child forked okay' ); +is($warnings, "", "No warnings from stop"); -open (my $stdout_in, '<', 'results'); -while ( my $line = <$stdout_in> ) { - $line =~ s/\s+\z//; - if ( $line =~ /\A((not\s+)?ok)(?:\s+-)(?:\s+(.*))\z/ ) { - my ( $status, $not, $text ) = ( $1, $2, $3 ); - $text ||= ''; +check_test_output($app); +unlink( $app->test_output ); - # We don't just call ok(!$not), because that generates diagnostics of - # its own for failures. We only want the diagnostics from the child. - my $num = $Test->current_test; - $Test->current_test( ++$num ); - $Test->_print("$status $num - $label: $text\n"); - } - elsif ( $line =~ s/\A#\s?// ) { - $Test->diag($line); - } - else { - $Test->_print_diag("$label: $line (unrecognised)\n"); - } -} +done_testing; -unlink($file); \ No newline at end of file +exit;