File Coverage: t/01_invoke.t

# File Coverage

File: | t/01_invoke.t
Coverage: | 95.2%

line | stmt | bran | cond | sub | time | code
--- | --- | --- | --- | --- | --- | ---
1 | 1 1 1 |  |  | 1 | 3525 4 40 | use strict;
2 | 1 1 1 |  |  | 1 | 5 3 34 | use warnings;
3 |
4 | 1 1 1 |  |  | 1 | 404 19658 9 | use Test::More tests => 6;
5 | 1 1 1 |  |  | 1 | 688 28952 69 | use Class::Load qw( try_load_class );
6 |
7 | 1 1 1 |  |  | 1 | 268 1053 1639 | use FindBin qw( $Bin );
8 | 1 |  |  |  | 101734 | my $command = "$^X $Bin/../bin/plackbench";
9 |
10 |  |  |  |  |  | SKIP: {
11 | 1 1 | 50 |  |  | 3 4 | if ( !try_load_class('Capture::Tiny') ) {
12 | 0 |  |  |  | 0 | skip 'Capture::Tiny not installed', 6;
13 |  |  |  |  |  | }
14 |
15 | 1 |  |  |  | 25484 | my ($stdout, $stderr, $exit);
16 |
17 | 1 |  |  |  | 5 | ($stdout, $stderr, $exit) = run($command);
18 | 1 |  |  |  | 733 | like($stdout, qr/Usage/, 'should output a usage message with no args');
19 | 1 |  |  |  | 372 | ok($exit, 'should exit unsuccessfully when passed no args');
20 |
21 | 1 |  |  |  | 260 | ($stdout, $stderr, $exit) = run("$command -n 10 $Bin/test_app.psgi /ok");
22 | 1 |  |  |  | 735 | ok(!$exit, 'should exit successfully');
23 | 1 |  |  |  | 423 | like($stdout, qr/Request times/, 'should output something reasonable');
24 |
25 | 1 |  |  |  | 260 | ($stdout, $stderr, $exit) = run("$command -e'\$_->url(\"/fail\")' $Bin/test_app.psgi /ok");
26 | 1 |  |  |  | 734 | ok($exit, 'should use -e flag as a fixup');
27 |
28 | 1 |  |  |  | 424 | ($stdout, $stderr, $exit) = run("$command -f $Bin/fail_redirect $Bin/test_app.psgi /ok");
29 | 1 |  |  |  | 700 | ok($exit, 'should use -f flag as a fixup file path');
30 |  |  |  |  |  | }
31 |
32 |  |  |  |  |  | sub run {
33 | 4 |  |  | 4 | 13 | my $command = shift;
34 |  |  |  |  |  | return Capture::Tiny::capture(sub {
35 | 4 |  |  | 4 | 3067839 | system($command);
36 | 4 |  |  |  | 304 | });
37 |  |  |  |  |  | }