X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Faggregate%2Funit_core_script_test.t;h=e475651219338d2a10a3f9d74a92e551d6dbdac1;hp=cc91a3af2c217ac87be47709b776cdc2c59989b5;hb=9c74923de2304b8c8f0a7a2faa0854ad9b4d3a92;hpb=718e995d7eaead630c5ae91d66ef84e7513c33ae diff --git a/t/aggregate/unit_core_script_test.t b/t/aggregate/unit_core_script_test.t index cc91a3a..e475651 100644 --- a/t/aggregate/unit_core_script_test.t +++ b/t/aggregate/unit_core_script_test.t @@ -1,6 +1,7 @@ use strict; use warnings; +use Carp qw(croak); use FindBin qw/$Bin/; use lib "$Bin/../lib"; @@ -11,38 +12,44 @@ use Catalyst::Script::Test; use File::Temp qw/tempfile/; use IO::Handle; -my ($fh, $fn) = tempfile(); - -binmode( $fh ); -binmode( STDOUT ); - -{ - local @ARGV = ('/'); - my $i; - lives_ok { - $i = Catalyst::Script::Test->new_with_options(application_name => 'TestApp'); - } "new_with_options"; - ok $i; - my $saved; - open( $saved, '<&'. STDIN->fileno ) - or croak("Can't dup stdin: $!"); - open( STDOUT, '>&='. $fh->fileno ) - or croak("Can't open stdout: $!"); - eval { $i->run }; - ok !$@, 'Ran ok'; - - STDOUT->flush - or croak("Can't flush stdout: $!"); - - open( STDOUT, '>&'. fileno($saved) ) - or croak("Can't restore stdout: $!"); -} - -my $data = do { my $fh; open($fh, '<', $fn) or die $!; local $/; <$fh>; }; -$fh = undef; -unlink $fn if -r $fn; - -is $data, "root index\n", 'correct content printed'; +is run_test('/'), "root index\n", 'correct content printed'; +is run_test('/moose/get_attribute'), "42\n", 'Correct content printed for non root action'; done_testing; +sub run_test { + my $url = shift; + + my ($fh, $fn) = tempfile(); + + binmode( $fh ); + binmode( STDOUT ); + + { + local @ARGV = ($url); + my $i; + lives_ok { + $i = Catalyst::Script::Test->new_with_options(application_name => 'TestApp'); + } "new_with_options"; + ok $i; + my $saved; + open( $saved, '>&'. STDOUT->fileno ) + or croak("Can't dup stdout: $!"); + open( STDOUT, '>&='. $fh->fileno ) + or croak("Can't open stdout: $!"); + eval { $i->run }; + ok !$@, 'Ran ok'; + + STDOUT->flush + or croak("Can't flush stdout: $!"); + + open( STDOUT, '>&'. fileno($saved) ) + or croak("Can't restore stdout: $!"); + } + + my $data = do { my $fh; open($fh, '<', $fn) or die $!; local $/; <$fh>; }; + $fh = undef; + unlink $fn if -r $fn; + + return $data; +}