Moved some PAR stuff
[catagits/Catalyst-Runtime.git] / t / live / component / controller / action / auto.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/../../../lib";
8
9 our $iters;
10
11 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 2; }
12
13 use Test::More tests => 18*$iters;
14 use Catalyst::Test 'TestApp';
15
16 if ( $ENV{CAT_BENCHMARK} ) {
17     require Benchmark;
18     Benchmark::timethis( $iters, \&run_tests );
19     
20     # new dispatcher:
21     # 11 wallclock secs (10.14 usr +  0.20 sys = 10.34 CPU) @ 15.18/s (n=157)
22     # old dispatcher (r1486):
23     # 11 wallclock secs (10.34 usr +  0.20 sys = 10.54 CPU) @ 13.76/s (n=145)
24 }
25 else {
26     for ( 1 .. $iters ) {
27         run_tests();
28     }
29 }
30     
31 sub run_tests {
32     # test auto + local method
33     {
34         my @expected = qw[
35           TestApp::Controller::Action::Auto->begin
36           TestApp::Controller::Action::Auto->auto
37           TestApp::Controller::Action::Auto->one
38           TestApp->end
39         ];
40     
41         my $expected = join( ", ", @expected );
42     
43         ok( my $response = request('http://localhost/action/auto/one'), 'auto + local' );
44         is( $response->header('X-Catalyst-Executed'),
45             $expected, 'Executed actions' );
46         is( $response->content, 'one', 'Content OK' );
47     }
48     
49     # test auto + default
50     {
51         my @expected = qw[
52           TestApp::Controller::Action::Auto->begin
53           TestApp::Controller::Action::Auto->auto
54           TestApp::Controller::Action::Auto->default
55           TestApp->end
56         ];
57     
58         my $expected = join( ", ", @expected );
59     
60         ok( my $response = request('http://localhost/action/auto/anything'), 'auto + default' );
61         is( $response->header('X-Catalyst-Executed'),
62             $expected, 'Executed actions' );
63         is( $response->content, 'default', 'Content OK' );
64     }
65     
66     # test auto + auto + local
67     {
68         my @expected = qw[
69           TestApp::Controller::Action::Auto::Deep->begin
70           TestApp::Controller::Action::Auto->auto
71           TestApp::Controller::Action::Auto::Deep->auto
72           TestApp::Controller::Action::Auto::Deep->one
73           TestApp->end
74         ];
75     
76         my $expected = join( ", ", @expected );
77     
78         ok( my $response = request('http://localhost/action/auto/deep/one'), 'auto + auto + local' );
79         is( $response->header('X-Catalyst-Executed'),
80             $expected, 'Executed actions' );
81         is( $response->content, 'deep one', 'Content OK' );
82     }
83     
84     # test auto + auto + default
85     {
86         my @expected = qw[
87           TestApp::Controller::Action::Auto::Deep->begin
88           TestApp::Controller::Action::Auto->auto
89           TestApp::Controller::Action::Auto::Deep->auto
90           TestApp::Controller::Action::Auto::Deep->default
91           TestApp->end
92         ];
93     
94         my $expected = join( ", ", @expected );
95     
96         ok( my $response = request('http://localhost/action/auto/deep/anything'), 'auto + auto + default' );
97         is( $response->header('X-Catalyst-Executed'),
98             $expected, 'Executed actions' );
99         is( $response->content, 'deep default', 'Content OK' );
100     }
101     
102     # test auto + failing auto + local + end
103     {
104         my @expected = qw[
105           TestApp::Controller::Action::Auto::Abort->begin
106           TestApp::Controller::Action::Auto->auto
107           TestApp::Controller::Action::Auto::Abort->auto
108           TestApp::Controller::Action::Auto::Abort->end
109         ];
110     
111         my $expected = join( ", ", @expected );
112     
113         ok( my $response = request('http://localhost/action/auto/abort/one'), 'auto + failing auto + local' );
114         is( $response->header('X-Catalyst-Executed'),
115             $expected, 'Executed actions' );
116         is( $response->content, 'abort end', 'Content OK' );
117     }
118     
119     # test auto + failing auto + default + end
120     {
121         my @expected = qw[
122           TestApp::Controller::Action::Auto::Abort->begin
123           TestApp::Controller::Action::Auto->auto
124           TestApp::Controller::Action::Auto::Abort->auto
125           TestApp::Controller::Action::Auto::Abort->end
126         ];
127     
128         my $expected = join( ", ", @expected );
129     
130         ok( my $response = request('http://localhost/action/auto/abort/anything'), 'auto + failing auto + default' );
131         is( $response->header('X-Catalyst-Executed'),
132             $expected, 'Executed actions' );
133         is( $response->content, 'abort end', 'Content OK' );
134     }
135 }