blib/lib/Plack/Test/Suite.pm

filter: Statementstmt 98.7% 383 / 388 Branchbran 65.3% 17 / 26 Conditioncond 54.5% 6 / 11 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 99.0% 99 / 100 Podpod 0.0% 0 / 3 totaltotal 94.7% 506 / 534 CC 21 SCAR 3.5
CC
21
Cov
96%
__ANON__
3.2
__ANON__
3.0
__ANON__
3.0
CRAP 1.4
« blib/lib/Plack/App/PSGIBin.pm ↑ Summary blib/lib/Plack/TempBuffer.pm »
1 package Plack::Test::Suite;
2 42 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 42 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 42 ▶use Digest::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 42 ▶use File::ShareDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 42 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 42 ▶use HTTP::Request::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 42 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 42 ▶use Test::TCP;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 42 ▶use Plack::Loader;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 42 ▶use Plack::Middleware::Lint;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 42 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 42 ▶use Plack::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 42 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 42 ▶use Plack::LWPish;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 42 ▶my $share_dir = try { File::ShareDir::dist_dir('Plack') } || 'share';
Subroutine __ANON__: called CC=1 SCAR=0.2
Condition50%1/2
&try(sub { File::ShareDir::dist_dir('Plack'); } ) || 'share'
l!l
420
MC/DC0%0/1
&try(sub { File::ShareDir::dist_dir('Plack'); } ) || 'share'
&try(sub { File::ShareDir::dist_dir('Plack'); } )
Truth table50%1/2
A
A= &try(sub { File::ShareDir::dist_dir('Plack'); } )
Aresult
11
00
18  
19 42 $ENV{PLACK_TEST_SCRIPT_NAME} = '';
20  
21 # 0: test name
22 # 1: request generator coderef.
23 # 2: request handler
24 # 3: test case for response
25 our @TEST = (
26 [
27 'SCRIPT_NAME',
28 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
29 3 my $cb = shift;
30 3 my $res = $cb->(GET "http://127.0.0.1/");
31 3 is $res->content, "script_name=$ENV{PLACK_TEST_SCRIPT_NAME}";
32 },
33 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
34 2 my $env = shift;
35 2 return [ 200, ["Content-Type", "text/plain"], [ "script_name=$env->{SCRIPT_NAME}" ] ];
36 },
37 ],
38 [
39 'GET',
40 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
41 3 my $cb = shift;
42 3 my $res = $cb->(GET "http://127.0.0.1/?name=miyagawa");
43 3 is $res->code, 200;
44 3 is $res->message, 'OK';
45 3 is $res->header('content_type'), 'text/plain';
46 3 is $res->content, 'Hello, name=miyagawa';
47 },
48 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
49 2 my $env = shift;
50 return [
51 200,
52 [ 'Content-Type' => 'text/plain', ],
53 2 [ 'Hello, ' . $env->{QUERY_STRING} ],
54 ];
55 },
56 ],
57 [
58 'POST',
59 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
60 3 my $cb = shift;
61 3 my $res = $cb->(POST "http://127.0.0.1/", [name => 'tatsuhiko']);
62 3 is $res->code, 200;
63 3 is $res->message, 'OK';
64 3 is $res->header('Client-Content-Length'), 14;
65 3 is $res->header('Client-Content-Type'), 'application/x-www-form-urlencoded';
66 3 is $res->header('content_type'), 'text/plain';
67 3 is $res->content, 'Hello, name=tatsuhiko';
68 },
69 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
70 2 my $env = shift;
71 2 my $body;
72 2 $env->{'psgi.input'}->read($body, $env->{CONTENT_LENGTH});
73 return [
74 200,
75 [ 'Content-Type' => 'text/plain',
76 'Client-Content-Length' => $env->{CONTENT_LENGTH},
77 'Client-Content-Type' => $env->{CONTENT_TYPE},
78 2 ],
79 [ 'Hello, ' . $body ],
80 ];
81 },
82 ],
83 [
84 'big POST',
85 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
86 3 my $cb = shift;
87 3 my $chunk = "abcdefgh" x 12000;
88 3 my $req = HTTP::Request->new(POST => "http://127.0.0.1/");
89 3 $req->content_length(length $chunk);
90 3 $req->content_type('application/octet-stream');
91 3 $req->content($chunk);
92  
93 3 my $res = $cb->($req);
94 3 is $res->code, 200;
95 3 is $res->message, 'OK';
96 3 is $res->header('Client-Content-Length'), length $chunk;
97 3 is length $res->content, length $chunk;
98 3 is Digest::MD5::md5_hex($res->content), Digest::MD5::md5_hex($chunk);
99 },
100 2 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
101 2 my $env = shift;
102 2 my $len = $env->{CONTENT_LENGTH};
103 2 my $body = '';
104 2 my $spin;
105 2 ▶ while ($len > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 0) 2 2 4
106 2 my $rc = $env->{'psgi.input'}->read($body, $env->{CONTENT_LENGTH}, length $body);
107 2 $len -= $rc;
108 2 ▶ last if $spin++ > 2000;
Branch: 1 branch
BranchTrueFalseTotal
if $spin++ > 2000 0 2 2
109 }
110 return [
111 200,
112 [ 'Content-Type' => 'text/plain',
113 'Client-Content-Length' => $env->{CONTENT_LENGTH},
114 'Client-Content-Type' => $env->{CONTENT_TYPE},
115 2 ],
116 [ $body ],
117 ];
118 },
119 ],
120 [
121 'psgi.url_scheme',
122 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
123 3 my $cb = shift;
124 3 my $res = $cb->(POST "http://127.0.0.1/");
125 3 is $res->code, 200;
126 3 is $res->message, 'OK';
127 3 is $res->header('content_type'), 'text/plain';
128 3 is $res->content, 'http';
129 },
130 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
131 2 my $env = $_[0];
132 return [
133 200,
134 [ 'Content-Type' => 'text/plain', ],
135 2 [ $env->{'psgi.url_scheme'} ],
136 ];
137 },
138 ],
139 [
140 'return glob',
141 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
142 3 my $cb = shift;
143 3 my $res = $cb->(GET "http://127.0.0.1/");
144 3 is $res->code, 200;
145 3 is $res->message, 'OK';
146 3 is $res->header('content_type'), 'text/plain';
147 3 like $res->content, qr/^package /;
148 3 like $res->content, qr/END_MARK_FOR_TESTING$/;
149 },
150 2 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
151 2 my $env = shift;
152 2 ▶ open my $fh, '<', __FILE__ or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", __FILE__ or die $! 2 0 2
153 return [
154 2 200,
155 [ 'Content-Type' => 'text/plain', ],
156 $fh,
157 ];
158 },
159 ],
160 [
161 'filehandle',
162 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
163 3 my $cb = shift;
164 3 my $res = $cb->(GET "http://127.0.0.1/foo.jpg");
165 3 is $res->code, 200;
166 3 is $res->message, 'OK';
167 3 is $res->header('content_type'), 'image/jpeg';
168 3 is length $res->content, 2898;
169 },
170 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
171 2 my $env = shift;
172 2 open my $fh, '<', "$share_dir/face.jpg";
173 return [
174 2 200,
175 [ 'Content-Type' => 'image/jpeg', 'Content-Length' => -s $fh ],
176 $fh
177 ];
178 },
179 ],
180 [
181 'bigger file',
182 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
183 3 my $cb = shift;
184 3 my $res = $cb->(GET "http://127.0.0.1/baybridge.jpg");
185 3 is $res->code, 200;
186 3 is $res->message, 'OK';
187 3 is $res->header('content_type'), 'image/jpeg';
188 3 is length $res->content, 14750;
189 3 is Digest::MD5::md5_hex($res->content), '70546a79c7abb9c497ca91730a0686e4';
190 },
191 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
192 2 my $env = shift;
193 2 open my $fh, '<', "$share_dir/baybridge.jpg";
194 2 binmode $fh;
195 return [
196 2 200,
197 [ 'Content-Type' => 'image/jpeg', 'Content-Length' => -s $fh ],
198 $fh
199 ];
200 },
201 ],
202 [
203 'handle HTTP-Header',
204 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
205 3 my $cb = shift;
206 3 my $res = $cb->(GET "http://127.0.0.1/foo/?dankogai=kogaidan", Foo => "Bar");
207 3 is $res->code, 200;
208 3 is $res->message, 'OK';
209 3 is $res->header('content_type'), 'text/plain';
210 3 is $res->content, 'Bar';
211 },
212 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
213 2 my $env = shift;
214 return [
215 200,
216 [ 'Content-Type' => 'text/plain', ],
217 2 [$env->{HTTP_FOO}],
218 ];
219 },
220 ],
221 [
222 'handle HTTP-Cookie',
223 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
224 3 my $cb = shift;
225 3 my $res = $cb->(GET "http://127.0.0.1/foo/?dankogai=kogaidan", Cookie => "foo");
226 3 is $res->code, 200;
227 3 is $res->message, 'OK';
228 3 is $res->header('content_type'), 'text/plain';
229 3 is $res->content, 'foo';
230 },
231 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
232 2 my $env = shift;
233 return [
234 200,
235 [ 'Content-Type' => 'text/plain', ],
236 2 [$env->{HTTP_COOKIE}],
237 ];
238 },
239 ],
240 [
241 'validate env',
242 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
243 3 my $cb = shift;
244 3 my $res = $cb->(GET "http://127.0.0.1/foo/?dankogai=kogaidan");
245 3 is $res->code, 200;
246 3 is $res->message, 'OK';
247 3 is $res->header('content_type'), 'text/plain';
248 3 is $res->content, join("\n",
249 'REQUEST_METHOD:GET',
250 "SCRIPT_NAME:$ENV{PLACK_TEST_SCRIPT_NAME}",
251 'PATH_INFO:/foo/',
252 'QUERY_STRING:dankogai=kogaidan',
253 'SERVER_NAME:127.0.0.1',
254 "SERVER_PORT:" . $res->request->uri->port,
255 )."\n";
256 },
257 2 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
258 2 my $env = shift;
259 2 my $body;
260 2 $body .= $_ . ':' . $env->{$_} . "\n" for qw/REQUEST_METHOD SCRIPT_NAME PATH_INFO QUERY_STRING SERVER_NAME SERVER_PORT/;
261 return [
262 2 200,
263 [ 'Content-Type' => 'text/plain', ],
264 [$body],
265 ];
266 },
267 ],
268 [
269 '% encoding in PATH_INFO',
270 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
271 3 my $cb = shift;
272 3 my $res = $cb->(GET "http://127.0.0.1/foo/bar%2cbaz");
273 3 is $res->content, "/foo/bar,baz", "PATH_INFO should be decoded per RFC 3875";
274 },
275 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
276 2 my $env = shift;
277 return [
278 200,
279 [ 'Content-Type' => 'text/plain', ],
280 2 [ $env->{PATH_INFO} ],
281 ];
282 },
283 ],
284 [
285 '% double encoding in PATH_INFO',
286 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
287 3 my $cb = shift;
288 3 my $res = $cb->(GET "http://127.0.0.1/foo/bar%252cbaz");
289 3 is $res->content, "/foo/bar%2cbaz", "PATH_INFO should be decoded only once, per RFC 3875";
290 },
291 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
292 2 my $env = shift;
293 return [
294 200,
295 [ 'Content-Type' => 'text/plain', ],
296 2 [ $env->{PATH_INFO} ],
297 ];
298 },
299 ],
300 [
301 '% encoding in PATH_INFO (outside of URI characters)',
302 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
303 3 my $cb = shift;
304 3 my $res = $cb->(GET "http://127.0.0.1/foo%E3%81%82");
305 3 is $res->content, "/foo\x{e3}\x{81}\x{82}";
306 },
307 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
308 2 my $env = shift;
309 return [
310 200,
311 [ 'Content-Type' => 'text/plain', ],
312 2 [ $env->{PATH_INFO} ],
313 ];
314 },
315 ],
316 [
317 'SERVER_PROTOCOL is required',
318 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
319 3 my $cb = shift;
320 3 my $res = $cb->(GET "http://127.0.0.1/foo/?dankogai=kogaidan");
321 3 is $res->code, 200;
322 3 is $res->message, 'OK';
323 3 is $res->header('content_type'), 'text/plain';
324 3 like $res->content, qr{^HTTP/1\.[01]$};
325 },
326 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
327 2 my $env = shift;
328 return [
329 200,
330 [ 'Content-Type' => 'text/plain', ],
331 2 [$env->{SERVER_PROTOCOL}],
332 ];
333 },
334 ],
335 [
336 'SCRIPT_NAME should not be undef',
337 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
338 3 my $cb = shift;
339 3 my $res = $cb->(GET "http://127.0.0.1/foo/?dankogai=kogaidan");
340 3 is $res->content, 1;
341 },
342 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
343 2 my $env = shift;
344 2 my $cont = defined $env->{'SCRIPT_NAME'};
345 return [
346 2 200,
347 [ 'Content-Type' => 'text/plain', ],
348 [$cont],
349 ];
350 },
351 ],
352 [
353 'call close after read IO::Handle-like',
354 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
355 3 my $cb = shift;
356 3 my $res = $cb->(GET "http://127.0.0.1/call_close");
357 3 is($res->content, '1234');
358 },
359 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
360 2 my $env = shift;
361 {
362 2 our $closed = -1;
363 2 ▶ sub CalledClose::new { $closed = 0; my $i=0; bless \$i, 'CalledClose' }
Subroutine new: called CC=1 SCAR=0.0
364 10 ▶ sub CalledClose::getline {
Subroutine getline: called CC=2 SCAR=6.9
365 10 my $self = shift;
366 10 ▶ return $$self++ < 4 ? $$self : undef;
Branch: 1 branch
BranchTrueFalseTotal
$$self++ < 4 ? : 8 2 10
367 }
368 2 ▶ sub CalledClose::close { ::ok(1, 'closed') if defined &::ok }
Subroutine close: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
if defined &main::ok 2 0 2
369 }
370 2 return [
371 2 200,
372 [ 'Content-Type' => 'text/plain', ],
373 CalledClose->new(),
374 ];
375 },
376 ],
377 [
378 'has errors',
379 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
380 3 my $cb = shift;
381 3 my $res = $cb->(GET "http://127.0.0.1/has_errors");
382 3 is $res->content, 1;
383 },
384 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
385 2 my $env = shift;
386 2 my $err = $env->{'psgi.errors'};
387 2 my $has_errors = defined $err;
388 return [
389 2 200,
390 [ 'Content-Type' => 'text/plain', ],
391 [$has_errors]
392 ];
393 },
394 ],
395 [
396 'status line',
397 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
398 3 my $cb = shift;
399 3 my $res = $cb->(GET "http://127.0.0.1/foo/?dankogai=kogaidan");
400 3 is($res->status_line, '200 OK');
401 },
402 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
403 2 my $env = shift;
404 return [
405 2 200,
406 [ 'Content-Type' => 'text/plain', ],
407 [1]
408 ];
409 },
410 ],
411 [
412 'Do not crash when the app dies',
413 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
414 3 my $cb = shift;
415 3 my $res = $cb->(GET "http://127.0.0.1/");
416 3 is $res->code, 500;
417 3 is $res->message, 'Internal Server Error';
418 },
419 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
420 2 my $env = shift;
421 2 open my $io, '>', \my $error;
422 2 $env->{'psgi.errors'} = $io;
423 2 die "Throwing an exception from app handler. Server shouldn't crash.";
424 },
425 ],
426 [
427 'multi headers (request)',
428 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
429 3 my $cb = shift;
430 3 my $req = HTTP::Request->new(
431 GET => "http://127.0.0.1/",
432 );
433 3 $req->push_header(Foo => "bar");
434 3 $req->push_header(Foo => "baz");
435 3 my $res = $cb->($req);
436 3 like($res->content, qr/^bar,\s*baz$/);
437 },
438 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
439 2 my $env = shift;
440 return [
441 200,
442 [ 'Content-Type' => 'text/plain', ],
443 2 [ $env->{HTTP_FOO} ]
444 ];
445 },
446 ],
447 [
448 'multi headers (response)',
449 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
450 3 my $cb = shift;
451 3 my $res = $cb->(HTTP::Request->new(GET => "http://127.0.0.1/"));
452 3 my $foo = $res->header('X-Foo');
453 3 like $foo, qr/foo,\s*bar,\s*baz/;
454 },
455 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
456 2 my $env = shift;
457 return [
458 2 200,
459 [ 'Content-Type' => 'text/plain', 'X-Foo', 'foo', 'X-Foo', 'bar, baz' ],
460 [ 'hi' ]
461 ];
462 },
463 ],
464 [
465 'Do not set $env->{COOKIE}',
466 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
467 3 my $cb = shift;
468 3 my $req = HTTP::Request->new(
469 GET => "http://127.0.0.1/",
470 );
471 3 $req->push_header(Cookie => "foo=bar");
472 3 my $res = $cb->($req);
473 3 is($res->header('X-Cookie'), 0);
474 3 is $res->content, 'foo=bar';
475 },
476 2 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
477 2 my $env = shift;
478 return [
479 200,
480 [ 'Content-Type' => 'text/plain', 'X-Cookie' => $env->{COOKIE} ? 1 : 0 ],
481 2 ▶ [ $env->{HTTP_COOKIE} ]
Branch: 1 branch
BranchTrueFalseTotal
$env->{'COOKIE'} ? : 0 2 2
482 ];
483 },
484 ],
485 [
486 'no entity headers on 304',
487 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
488 3 my $cb = shift;
489 3 my $res = $cb->(GET "http://127.0.0.1/");
490 3 is $res->code, 304;
491 3 is $res->message, 'Not Modified';
492 3 is $res->content, '';
493 3 ok ! defined $res->header('content_type'), "No Content-Type";
494 3 ok ! defined $res->header('content_length'), "No Content-Length";
495 3 ok ! defined $res->header('transfer_encoding'), "No Transfer-Encoding";
496 },
497 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
498 2 my $env = shift;
499 2 return [ 304, [], [] ];
500 },
501 ],
502 [
503 'REQUEST_URI is set',
504 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
505 3 my $cb = shift;
506 3 my $res = $cb->(GET "http://127.0.0.1/foo/bar%20baz%73?x=a");
507 3 is $res->content, $ENV{PLACK_TEST_SCRIPT_NAME} . "/foo/bar%20baz%73?x=a";
508 },
509 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
510 2 my $env = shift;
511 2 return [ 200, [ 'Content-Type' => 'text/plain' ], [ $env->{REQUEST_URI} ] ];
512 },
513 ],
514 [
515 'filehandle with path()',
516 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
517 3 my $cb = shift;
518 3 my $res = $cb->(GET "http://127.0.0.1/foo.jpg");
519 3 is $res->code, 200;
520 3 is $res->message, 'OK';
521 3 is $res->header('content_type'), 'image/jpeg';
522 3 is length $res->content, 2898;
523 },
524 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
525 2 my $env = shift;
526 2 open my $fh, '<', "$share_dir/face.jpg";
527 2 Plack::Util::set_io_path($fh, "$share_dir/face.jpg");
528 return [
529 2 200,
530 [ 'Content-Type' => 'image/jpeg', 'Content-Length' => -s $fh ],
531 $fh
532 ];
533 },
534 ],
535 [
536 'a big header value > 128 bytes',
537 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
538 3 my $cb = shift;
539 3 my $req = GET "http://127.0.0.1/";
540 3 my $v = ("abcdefgh" x 16);
541 3 $req->header('X-Foo' => $v);
542 3 my $res = $cb->($req);
543 3 is $res->code, 200;
544 3 is $res->message, 'OK';
545 3 is $res->content, $v;
546 },
547 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
548 2 my $env = shift;
549 return [
550 200,
551 [ 'Content-Type' => 'text/plain' ],
552 2 [ $env->{HTTP_X_FOO} ],
553 ];
554 },
555 ],
556 [
557 'coderef res',
558 3 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
559 3 my $cb = shift;
560 3 my $res = $cb->(GET "http://127.0.0.1/?name=miyagawa");
561 3 ▶ return if $res->code == 501;
Branch: 1 branch
BranchTrueFalseTotal
if $res->code == 501 0 3 3
562  
563 3 is $res->code, 200;
564 3 is $res->message, 'OK';
565 3 is $res->header('content_type'), 'text/plain';
566 3 is $res->content, 'Hello, name=miyagawa';
567 },
568 2 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
569 2 my $env = shift;
570 2 ▶ $env->{'psgi.streaming'} or return [ 501, ['Content-Type','text/plain'], [] ];
Branch: 1 branch
BranchTrueFalseTotal
$env->{"psgi.streaming"} or return [501, ["Content-Type", "text/plain"], []] 2 0 2
571 2 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
572 2 my $respond = shift;
573 $respond->([
574 200,
575 [ 'Content-Type' => 'text/plain', ],
576 2 [ 'Hello, ' . $env->{QUERY_STRING} ],
577 ]);
578 }
579 2 },
580 ],
581 [
582 'coderef streaming',
583 3 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
584 3 my $cb = shift;
585 3 my $res = $cb->(GET "http://127.0.0.1/?name=miyagawa");
586 3 ▶ return if $res->code == 501;
Branch: 1 branch
BranchTrueFalseTotal
if $res->code == 501 0 3 3
587  
588 3 is $res->code, 200;
589 3 is $res->message, 'OK';
590 3 is $res->header('content_type'), 'text/plain';
591 3 is $res->content, 'Hello, name=miyagawa';
592 },
593 2 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
594 2 my $env = shift;
595 2 ▶ $env->{'psgi.streaming'} or return [ 501, ['Content-Type','text/plain'], [] ];
Branch: 1 branch
BranchTrueFalseTotal
$env->{"psgi.streaming"} or return [501, ["Content-Type", "text/plain"], []] 2 0 2
596  
597 2 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
598 2 my $respond = shift;
599  
600 2 my $writer = $respond->([
601 200,
602 [ 'Content-Type' => 'text/plain', ],
603 ]);
604  
605 2 $writer->write("Hello, ");
606 2 $writer->write($env->{QUERY_STRING});
607 2 $writer->close();
608 }
609 2 },
610 ],
611 [
612 'CRLF output and FCGI parse bug',
613 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
614 3 my $cb = shift;
615 3 my $res = $cb->(GET "http://127.0.0.1/");
616  
617 3 is $res->header("Foo"), undef;
618 3 is $res->content, "Foo: Bar\r\n\r\nHello World";
619 },
620 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
621 2 return [ 200, [ "Content-Type", "text/plain" ], [ "Foo: Bar\r\n\r\nHello World" ] ];
622 },
623 ],
624 [
625 'newlines',
626 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
627 3 my $cb = shift;
628 3 my $res = $cb->(GET "http://127.0.0.1/");
629 3 is length($res->content), 7;
630 },
631 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
632 2 return [ 200, [ "Content-Type", "text/plain" ], [ "Bar\nBaz" ] ];
633 },
634 ],
635 [
636 'test 404',
637 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
638 3 my $cb = shift;
639 3 my $res = $cb->(GET "http://127.0.0.1/");
640 3 is $res->code, 404;
641 3 is $res->message, 'Not Found';
642 3 is $res->content, 'Not Found';
643 },
644 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
645 2 return [ 404, [ "Content-Type", "text/plain" ], [ "Not Found" ] ];
646 },
647 ],
648 [
649 'request->input seekable',
650 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
651 3 my $cb = shift;
652 3 my $req = HTTP::Request->new(POST => "http://127.0.0.1/");
653 3 $req->content("body");
654 3 $req->content_type('text/plain');
655 3 $req->content_length(4);
656 3 my $res = $cb->($req);
657 3 is $res->content, 'body';
658 },
659 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
660 2 my $req = Plack::Request->new(shift);
661 2 return [ 200, [ "Content-Type", "text/plain" ], [ $req->content ] ];
662 },
663 ],
664 [
665 'request->content on GET',
666 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
667 3 my $cb = shift;
668 3 my $res = $cb->(GET "http://127.0.0.1/");
669 3 ok $res->is_success;
670 },
671 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
672 2 my $req = Plack::Request->new(shift);
673 2 $req->content;
674 2 return [ 200, [ "Content-Type", "text/plain" ], [ "OK" ] ];
675 },
676 ],
677 [
678 'handle Authorization header',
679 3 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
680 3 my $cb = shift;
681 SKIP: {
682 3 ▶ skip "Authorization header is unsupported under CGI", 4 if ($ENV{PLACK_TEST_HANDLER} || "") eq "CGI";
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"PLACK_TEST_HANDLER"} || "") eq "CGI" 0 3 3
Condition50%1/2
$ENV{'PLACK_TEST_HANDLER'} || ''
l!l
03
MC/DC0%0/1
$ENV{'PLACK_TEST_HANDLER'} || ''
$ENV{'PLACK_TEST_HANDLER'}
Truth table50%1/2
A
A= $ENV{'PLACK_TEST_HANDLER'}
Aresult
11
00
683  
684 {
685 3 my $req = HTTP::Request->new(
686 GET => "http://127.0.0.1/",
687 );
688 3 $req->push_header(Authorization => 'Basic XXXX');
689 3 my $res = $cb->($req);
690 3 is $res->header('X-AUTHORIZATION'), 1;
691 3 is $res->content, 'Basic XXXX';
692 };
693  
694 {
695 3 my $req = HTTP::Request->new(
696 GET => "http://127.0.0.1/",
697 );
698 3 my $res = $cb->($req);
699 3 is $res->header('X-AUTHORIZATION'), 0;
700 3 is $res->content, 'no_auth';
701 };
702 };
703 },
704 4 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
705 4 my $env = shift;
706 return [
707 200,
708 [ 'Content-Type' => 'text/plain', 'X-AUTHORIZATION' => exists($env->{HTTP_AUTHORIZATION}) ? 1 : 0 ],
709 4 ▶ [ $env->{HTTP_AUTHORIZATION} || 'no_auth' ],
Branch: 1 branch
BranchTrueFalseTotal
exists $env->{'HTTP_AUTHORIZATION'} ? : 2 2 4
Condition100%2/2
$env->{'HTTP_AUTHORIZATION'} || 'no_auth'
l!l
22
MC/DC100%1/1
$env->{'HTTP_AUTHORIZATION'} || 'no_auth'
$env->{'HTTP_AUTHORIZATION'}
Truth table100%2/2
A
A= $env->{'HTTP_AUTHORIZATION'}
Aresult
11
00
710 ];
711 },
712 ],
713 [
714 'repeated slashes',
715 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
716 3 my $cb = shift;
717 3 my $res = $cb->(GET "http://127.0.0.1//foo///bar/baz");
718 3 is $res->code, 200;
719 3 is $res->message, 'OK';
720 3 is $res->header('content_type'), 'text/plain';
721 3 is $res->content, '//foo///bar/baz';
722 },
723 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
724 2 my $env = shift;
725 return [
726 200,
727 [ 'Content-Type' => 'text/plain', ],
728 2 [ $env->{PATH_INFO} ],
729 ];
730 },
731 42 ],
732 );
733  
734 1 ▶sub runtests {
Subroutine runtests: called CC=2 SCAR=6.9
Pod undocumented
735 1 my($class, $runner) = @_;
736 1 for my $test (@TEST) {
737 36 $runner->(@$test);
738 }
739 }
740  
741 39 ▶sub run_server_tests {
Subroutine run_server_tests: called CC=2 SCAR=7.2
Pod undocumented
742 39 my($class, $server, $server_port, $http_port, %args) = @_;
743  
744 39 ▶ if (ref $server ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $server ne "CODE") 1 38 39
745 1 my $server_class = $server;
746 0 ▶ $server = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
747 0 my($port, $app) = @_;
748 0 my $server = Plack::Loader->load($server_class, port => $port, host => "127.0.0.1", %args);
749 0 $app = Plack::Middleware::Lint->wrap($app);
750 0 $server->run($app);
751 }
752 1 }
753  
754 test_tcp(
755 2 ▶ client => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
756 2 my $port = shift;
757 2 my $ua = Plack::LWPish->new( no_proxy => [qw/127.0.0.1/] );
758 2 for my $i (0..$#TEST) {
759 72 my $test = $TEST[$i];
760 72 note $test->[0];
761 74 ▶ my $cb = sub {
Subroutine __ANON__: called CC=3 SCAR=11.8
762 74 my $req = shift;
763 74 ▶ $req->uri->port($http_port || $port);
Condition33%1/3
$http_port || $port
l!l&&r!l&&!r
0740
MC/DC0%0/2
$http_port || $port
$http_port $port
Truth table33%1/3
A || B
A= $http_portB= $port
ABresult
1X1
011
000
764 74 ▶ $req->uri->path(($ENV{PLACK_TEST_SCRIPT_NAME}||"") . $req->uri->path);
Condition50%1/2
$ENV{'PLACK_TEST_SCRIPT_NAME'} || ''
l!l
074
MC/DC0%0/1
$ENV{'PLACK_TEST_SCRIPT_NAME'} || ''
$ENV{'PLACK_TEST_SCRIPT_NAME'}
Truth table50%1/2
A
A= $ENV{'PLACK_TEST_SCRIPT_NAME'}
Aresult
11
00
765 74 $req->header('X-Plack-Test' => $i);
766 74 return $ua->request($req);
767 72 };
768  
769 72 $test->[1]->($cb);
770 }
771 },
772 37 ▶ server => sub {
Subroutine __ANON__: called CC=1 SCAR=0.2
773 37 my $port = shift;
774 37 my $app = $class->test_app_handler;
775 37 $server->($port, $app);
776 0 exit(0); # for Test::TCP
777 },
778 39 port => $server_port,
779 );
780 }
781  
782 37 ▶sub test_app_handler {
Subroutine test_app_handler: called CC=1 SCAR=0.0
Pod undocumented
783 37 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
784 37 my $env = shift;
785 37 $TEST[$env->{HTTP_X_PLACK_TEST}][2]->($env);
786 37 };
787 }
788  
789 42 1;
790 __END__
« blib/lib/Plack/App/PSGIBin.pm ↑ Summary blib/lib/Plack/TempBuffer.pm »