Commit | Line | Data |
718e995d |
1 | use strict; |
2 | use warnings; |
3 | |
99d30e96 |
4 | use Carp qw(croak); |
718e995d |
5 | use FindBin qw/$Bin/; |
6b665c03 |
6 | use lib "$Bin/lib"; |
718e995d |
7 | |
8 | use Test::More; |
9 | use Test::Exception; |
10 | |
11 | use Catalyst::Script::Test; |
12 | use File::Temp qw/tempfile/; |
13 | use IO::Handle; |
14 | |
95389116 |
15 | is run_test('/'), "root index\n", 'correct content printed'; |
16 | is run_test('/moose/get_attribute'), "42\n", 'Correct content printed for non root action'; |
718e995d |
17 | |
18 | done_testing; |
19 | |
95389116 |
20 | sub run_test { |
21 | my $url = shift; |
22 | |
23 | my ($fh, $fn) = tempfile(); |
24 | |
25 | binmode( $fh ); |
26 | binmode( STDOUT ); |
27 | |
28 | { |
29 | local @ARGV = ($url); |
30 | my $i; |
31 | lives_ok { |
32 | $i = Catalyst::Script::Test->new_with_options(application_name => 'TestApp'); |
33 | } "new_with_options"; |
34 | ok $i; |
35 | my $saved; |
b50712ce |
36 | open( $saved, '>&'. STDOUT->fileno ) |
37 | or croak("Can't dup stdout: $!"); |
95389116 |
38 | open( STDOUT, '>&='. $fh->fileno ) |
39 | or croak("Can't open stdout: $!"); |
40 | eval { $i->run }; |
41 | ok !$@, 'Ran ok'; |
42 | |
43 | STDOUT->flush |
44 | or croak("Can't flush stdout: $!"); |
45 | |
46 | open( STDOUT, '>&'. fileno($saved) ) |
47 | or croak("Can't restore stdout: $!"); |
48 | } |
49 | |
50 | my $data = do { my $fh; open($fh, '<', $fn) or die $!; local $/; <$fh>; }; |
51 | $fh = undef; |
52 | unlink $fn if -r $fn; |
53 | |
54 | return $data; |
55 | } |