1use strict; 2use warnings; 3 4use FindBin; 5use lib "$FindBin::Bin/../lib"; 6 7our $iters; 8 9BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; } 10 11use Test::More; 12use Catalyst::Test 'TestApp'; 13 14if ( $ENV{CAT_BENCHMARK} ) { 15 require Benchmark; 16 Benchmark::timethis( $iters, \&run_tests ); 17 18 # new dispatcher: 19 # 11 wallclock secs (10.14 usr + 0.20 sys = 10.34 CPU) @ 15.18/s (n=157) 20 # old dispatcher (r1486): 21 # 11 wallclock secs (10.34 usr + 0.20 sys = 10.54 CPU) @ 13.76/s (n=145) 22} 23else { 24 for ( 1 .. $iters ) { 25 run_tests(); 26 } 27} 28 29sub run_tests { 30 # test auto + local method 31 { 32 my @expected = qw[ 33 TestApp::Controller::Action::Auto->begin 34 TestApp::Controller::Action::Auto->auto 35 TestApp::Controller::Action::Auto->one 36 TestApp::Controller::Root->end 37 ]; 38 39 my $expected = join( ", ", @expected ); 40 41 ok( my $response = request('http://localhost/action/auto/one'), 'auto + local' ); 42 is( $response->header('X-Catalyst-Executed'), 43 $expected, 'Executed actions' ); 44 is( $response->content, 'one', 'Content OK' ); 45 } 46 47 # test auto + default 48 { 49 my @expected = qw[ 50 TestApp::Controller::Action::Auto->begin 51 TestApp::Controller::Action::Auto->auto 52 TestApp::Controller::Action::Auto->default 53 TestApp::Controller::Root->end 54 ]; 55 56 my $expected = join( ", ", @expected ); 57 58 ok( my $response = request('http://localhost/action/auto/anything'), 'auto + default' ); 59 is( $response->header('X-Catalyst-Executed'), 60 $expected, 'Executed actions' ); 61 is( $response->content, 'default', 'Content OK' ); 62 } 63 64 # test auto + auto + local 65 { 66 my @expected = qw[ 67 TestApp::Controller::Action::Auto::Deep->begin 68 TestApp::Controller::Action::Auto->auto 69 TestApp::Controller::Action::Auto::Deep->auto 70 TestApp::Controller::Action::Auto::Deep->one 71 TestApp::Controller::Root->end 72 ]; 73 74 my $expected = join( ", ", @expected ); 75 76 ok( my $response = request('http://localhost/action/auto/deep/one'), 'auto + auto + local' ); 77 is( $response->header('X-Catalyst-Executed'), 78 $expected, 'Executed actions' ); 79 is( $response->content, 'deep one', 'Content OK' ); 80 } 81 82 # test auto + auto + default 83 { 84 my @expected = qw[ 85 TestApp::Controller::Action::Auto::Deep->begin 86 TestApp::Controller::Action::Auto->auto 87 TestApp::Controller::Action::Auto::Deep->auto 88 TestApp::Controller::Action::Auto::Deep->default 89 TestApp::Controller::Root->end 90 ]; 91 92 my $expected = join( ", ", @expected ); 93 94 ok( my $response = request('http://localhost/action/auto/deep/anything'), 'auto + auto + default' ); 95 is( $response->header('X-Catalyst-Executed'), 96 $expected, 'Executed actions' ); 97 is( $response->content, 'deep default', 'Content OK' ); 98 } 99 100 # test auto + failing auto + local + end 101 { 102 my @expected = qw[ 103 TestApp::Controller::Action::Auto::Abort->begin 104 TestApp::Controller::Action::Auto->auto 105 TestApp::Controller::Action::Auto::Abort->auto 106 TestApp::Controller::Action::Auto::Abort->end 107 ]; 108 109 my $expected = join( ", ", @expected ); 110 111 ok( my $response = request('http://localhost/action/auto/abort/one'), 'auto + failing auto + local' ); 112 is( $response->header('X-Catalyst-Executed'), 113 $expected, 'Executed actions' ); 114 is( $response->content, 'abort end', 'Content OK' ); 115 } 116 117 # test auto + default (bug on invocation of default twice) 118 { 119 my @expected = qw[ 120 TestApp::Controller::Action::Auto::Default->begin 121 TestApp::Controller::Action::Auto->auto 122 TestApp::Controller::Action::Auto::Default->auto 123 TestApp::Controller::Action::Auto::Default->default 124 TestApp::Controller::Action::Auto::Default->end 125 ]; 126 127 my $expected = join( ", ", @expected ); 128 129 ok( my $response = request('http://localhost/action/auto/default/moose'), 'auto + default' ); 130 is( $response->header('X-Catalyst-Executed'), 131 $expected, 'Executed actions' ); 132 is( $response->content, 'default (auto: 1)', 'Content OK' ); 133 } 134 135 # test detach in auto 136 { 137 my @expected = qw[ 138 TestApp::Controller::Action::Auto::Detach->begin 139 TestApp::Controller::Action::Auto->auto 140 TestApp::Controller::Action::Auto::Detach->auto 141 TestApp::Controller::Root->end 142 ]; 143 144 my $expected = join( ", ", @expected ); 145 146 ok( my $response = request('http://localhost/action/auto/detach'), 'auto with detach' ); 147 is( $response->header('X-Catalyst-Executed'), 148 $expected, 'Executed actions' ); 149 is( $response->content, 'detach auto', 'Content OK' ); 150 } 151 152 # test detach in auto forward 153 { 154 my @expected = qw[ 155 TestApp::Controller::Action::Auto::Detach->begin 156 TestApp::Controller::Action::Auto->auto 157 TestApp::Controller::Action::Auto::Detach->auto 158 TestApp::Controller::Action::Auto::Detach->with_forward_detach 159 TestApp::Controller::Root->end 160 ]; 161 162 my $expected = join( ", ", @expected ); 163 164 ok( my $response = request('http://localhost/action/auto/detach?with_forward_detach=1'), 'auto with_forward_detach' ); 165 is( $response->header('X-Catalyst-Executed'), 166 $expected, 'Executed actions' ); 167 is( $response->content, 'detach with_forward_detach', 'Content OK' ); 168 } 169 170 # test detach in auto forward detach action 171 { 172 my @expected = qw[ 173 TestApp::Controller::Action::Auto::Detach->begin 174 TestApp::Controller::Action::Auto->auto 175 TestApp::Controller::Action::Auto::Detach->auto 176 TestApp::Controller::Action::Auto::Detach->with_forward_detach 177 TestApp::Controller::Action::Auto::Detach->detach_action 178 TestApp::Controller::Root->end 179 ]; 180 181 my $expected = join( ", ", @expected ); 182 183 ok( my $response = request('http://localhost/action/auto/detach?with_forward_detach=1&detach_to_action=1'), 'auto with_forward_detach to detach_action' ); 184 is( $response->header('X-Catalyst-Executed'), 185 $expected, 'Executed actions' ); 186 is( $response->content, 'detach_action', 'Content OK' ); 187 } 188} 189 190done_testing; 191 192