Commit | Line | Data |
50cc3183 |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use FindBin; |
a2e038a1 |
7 | use lib "$FindBin::Bin/lib"; |
50cc3183 |
8 | |
9 | our $iters; |
10 | |
6b25e555 |
11 | BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; } |
50cc3183 |
12 | |
cccc8f68 |
13 | use Test::More tests => 28*$iters; |
50cc3183 |
14 | use Catalyst::Test 'TestApp'; |
15 | |
048f45ee |
16 | use Catalyst::Request; |
17 | |
50cc3183 |
18 | if ( $ENV{CAT_BENCHMARK} ) { |
19 | require Benchmark; |
20 | Benchmark::timethis( $iters, \&run_tests ); |
21 | } |
22 | else { |
23 | for ( 1 .. $iters ) { |
24 | run_tests(); |
25 | } |
26 | } |
27 | |
28 | sub run_tests { |
29 | { |
30 | ok( my $response = request('http://localhost/action/regexp/10/hello'), |
31 | 'Request' ); |
32 | ok( $response->is_success, 'Response Successful 2xx' ); |
33 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
34 | is( $response->header('X-Catalyst-Action'), |
35 | '^action/regexp/(\d+)/(\w+)$', 'Test Action' ); |
36 | is( |
37 | $response->header('X-Test-Class'), |
38 | 'TestApp::Controller::Action::Regexp', |
39 | 'Test Class' |
40 | ); |
41 | like( |
42 | $response->content, |
43 | qr/^bless\( .* 'Catalyst::Request' \)$/s, |
44 | 'Content is a serialized Catalyst::Request' |
45 | ); |
46 | } |
47 | |
48 | { |
49 | ok( my $response = request('http://localhost/action/regexp/hello/10'), |
50 | 'Request' ); |
51 | ok( $response->is_success, 'Response Successful 2xx' ); |
52 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
53 | is( $response->header('X-Catalyst-Action'), |
54 | '^action/regexp/(\w+)/(\d+)$', 'Test Action' ); |
55 | is( |
56 | $response->header('X-Test-Class'), |
57 | 'TestApp::Controller::Action::Regexp', |
58 | 'Test Class' |
59 | ); |
60 | like( |
61 | $response->content, |
62 | qr/^bless\( .* 'Catalyst::Request' \)$/s, |
63 | 'Content is a serialized Catalyst::Request' |
64 | ); |
65 | } |
cccc8f68 |
66 | |
67 | { |
68 | ok( my $response = request('http://localhost/action/regexp/mandatory'), |
69 | 'Request' ); |
70 | ok( $response->is_success, 'Response Successful 2xx' ); |
71 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
72 | is( $response->header('X-Catalyst-Action'), |
73 | '^action/regexp/(mandatory)(/optional)?$', 'Test Action' ); |
74 | is( |
75 | $response->header('X-Test-Class'), |
76 | 'TestApp::Controller::Action::Regexp', |
77 | 'Test Class' |
78 | ); |
79 | my $content = $response->content; |
80 | my $req = eval $content; |
81 | |
82 | is( scalar @{ $req->captures }, 2, 'number of captures' ); |
83 | is( $req->captures->[ 0 ], 'mandatory', 'mandatory capture' ); |
84 | ok( !defined $req->captures->[ 1 ], 'optional capture' ); |
85 | } |
86 | |
87 | { |
88 | ok( my $response = request('http://localhost/action/regexp/mandatory/optional'), |
89 | 'Request' ); |
90 | ok( $response->is_success, 'Response Successful 2xx' ); |
91 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
92 | is( $response->header('X-Catalyst-Action'), |
93 | '^action/regexp/(mandatory)(/optional)?$', 'Test Action' ); |
94 | is( |
95 | $response->header('X-Test-Class'), |
96 | 'TestApp::Controller::Action::Regexp', |
97 | 'Test Class' |
98 | ); |
99 | my $content = $response->content; |
100 | my $req = eval $content; |
101 | |
102 | is( scalar @{ $req->captures }, 2, 'number of captures' ); |
103 | is( $req->captures->[ 0 ], 'mandatory', 'mandatory capture' ); |
104 | is( $req->captures->[ 1 ], '/optional', 'optional capture' ); |
105 | } |
50cc3183 |
106 | } |