blib/lib/Plack/App/DAIA/Test/Suite.pm

filter: Statementstmt 88.8% 88 / 99 Branchbran 63.6% 28 / 44 Conditioncond 27.2% 3 / 11 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 12 / 12 Podpod 100% 1 / 1 totaltotal 76.8% 133 / 173 CC 29 SCAR 29.3
CC
29
Cov
77%
provedaia
30.9
__ANON__
9.9
BEGIN
1.0
CRAP 18.7
« blib/lib/Plack/App/DAIA/Validator.pm ↑ Summary blib/lib/Plack/App/DAIA.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Plack::App::DAIA::Test::Suite;
4 #ABSTRACT: Test DAIA Servers via a test scripting language
5 1 our $VERSION = '0.55'; #VERSION
6 1 ▶use base 'Test::Builder::Module';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 our @EXPORT = qw(provedaia);
8  
9 1 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Plack::App::DAIA::Test;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Scalar::Util qw(reftype blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Test::JSON::Entails;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 ▶sub provedaia {
Subroutine provedaia: called CC=21 SCAR=34.3
Pod documented
17 3 my ($suite, %args) = @_;
18  
19 3 my $test = __PACKAGE__->builder;
20 3 my @lines;
21  
22 3 ▶ if ( ref($suite) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $suite) { } 0 3 3
elsif (not $suite =~ qr"^https?://" || $suite =~ /[\r\n]/) { } 2 1 3
23 0 ▶ croak 'usage: provedaia( $file | $glob | $string )'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::reftype($suite) eq "GLOB" or builtin::blessed($suite) and $suite->isa("IO::File") 0 0 0
Condition0%0/6
builtin::reftype($suite) eq "GLOB" or builtin::blessed($suite) and $suite->isa("IO::File")
l!l&&r!l&&!r
000
builtin::blessed($suite) and $suite->isa("IO::File")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::reftype($suite) eq "GLOB" or builtin::blessed($suite) and $suite->isa("IO::File")
builtin::reftype($suite) eq "GLOB" builtin::blessed($suite) $suite->isa("IO::File")
Truth table0%0/4
A or B and C
A= builtin::reftype($suite) eq "GLOB"B= builtin::blessed($suite)C= $suite->isa("IO::File")
ABCresult
1XX1
0111
00X0
0100
24 unless reftype($suite) eq 'GLOB' or blessed($suite) and $suite->isa('IO::File');
25 0 @lines = <$suite>;
26 ▶ } elsif ( $suite !~ qr{^https?://} and $suite !~ /[\r\n]/ ) {
Condition66%2/3
$suite =~ qr"^https?://" || $suite =~ /[\r\n]/
l!l&&r!l&&!r
012
MC/DC50%1/2
$suite =~ qr"^https?://" || $suite =~ /[\r\n]/
$suite =~ qr"^https?://" $suite =~ /[\r\n]/
Truth table66%2/3
A || B
A= $suite =~ qr"^https?://"B= $suite =~ /[\r\n]/
ABresult
1X1
011
000
27 2 ▶ open (my $fh, '<', $suite) or croak "failed to open daia test suite $suite";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $suite or croak("failed to open daia test suite $suite") 2 0 2
28 2 @lines = <$fh>;
29 2 close $fh;
30 } else {
31 1 @lines = split /\n/, $suite;
32 }
33  
34 3 my $line = 0;
35 3 my $comment = '';
36 3 my $json = undef;
37 3 my %vars = ( server => $args{server} );
38 3 my @ids;
39 3 ▶ @ids = @{$args{ids}} if $args{ids};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"ids"} 1 2 3
40  
41 4 ▶ my $run = sub {
Subroutine __ANON__: called CC=9 SCAR=22.9
42 4 ▶ my $server = $vars{server} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $server = $vars{"server"} or return 4 0 4
43 4 ▶ $json ||= '{ }';
Condition50%1/2
$json ||= "{ }"
l!l
40
MC/DC0%0/1
$json ||= "{ }"
$json
Truth table50%1/2
A
A= $json
Aresult
11
00
44 4 my $server_name = $server;
45 4 ▶ if ( $server !~ qr{^https?://}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($server =~ qr"^https?://") 4 0 4
46 1 ▶ no warnings 'redefine'; # we may load the same twice
Subroutine BEGIN: called CC=1 SCAR=0.0
47 4 $_ = Plack::Util::load_psgi($server);
48 4 ▶ if ( ref($_) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_) { } 4 0 4
49 4 diag("loaded PSGI from $server");
50 4 $server = $_;
51 } else {
52 0 fail("failed to load PSGI from $server");
53 0 return;
54 }
55 }
56 4 foreach my $id (@ids) {
57 6 my $test_name = "$server_name?id=$id";
58 6 $comment =~ s/^\s+|\s+$//g;
59 6 ▶ $test_name .= " ($comment)" if $comment ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $comment ne "" 3 3 6
60 6 local $Test::Builder::Level = $Test::Builder::Level + 2; # called 2 levels above
61 6 my $test_json = $json;
62 6 $vars{id} = $id;
63 6 ▶ $test_json =~ s/\$([a-z]+)/defined $vars{$1} ? $vars{$1} : "\$$1"/emg;
Branch: 1 branch
BranchTrueFalseTotal
defined $vars{$1} ? : 5 0 5
64 6 $test_json = decode_json($test_json);
65 6 ▶ if (ref($server)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $server) { } 6 0 6
66 6 test_daia_psgi $server, $id => $test_json, $test_name;
67 } else {
68 0 test_daia $server, $id => $test_json, $test_name;
69 }
70 }
71 3 };
72  
73 3 foreach (@lines) {
74 50 ▶ if ($args{end}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"end"}) 35 15 50
75 35 ▶ $args{end} = 0 if /__END__/;
Branch: 1 branch
BranchTrueFalseTotal
if /__END__/ 1 34 35
76 35 next;
77 }
78 15 chomp;
79 15 ▶ $comment = $1 if /^#(.*)/;
Branch: 1 branch
BranchTrueFalseTotal
if /^#(.*)/ 2 13 15
80 15 s/^(#.*|\s+)$//; # empty line or comment
81 15 $line++;
82  
83 15 ▶ if (defined $json) {
Branch: 4 branches
BranchTrueFalseTotal
if (defined $json) { } 3 12 15
elsif ($_ eq '') { } 5 7 12
elsif ($_ =~ qr/^([a-z]+)\s*=\s*(.*)/i) { } 0 7 7
elsif ($_ =~ qr/^\s*{/) { } 4 3 7
84 3 $json .= $_;
85 3 ▶ if ($_ eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "") 1 2 3
86 1 $run->();
87 1 $json = undef;
88 1 $comment = '';
89 }
90 } elsif ( $_ eq '' ) {
91 5 next;
92 } elsif( $_ =~ qr{^([a-z]+)\s*=\s*(.*)}i ) {
93 0 $comment = '';
94 0 my ($key, $value) = ($1,$2);
95 0 ▶ if ($1 =~ /^id[s]?/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 =~ /^id[s]?/) { } 0 0 0
96 0 ▶ @ids = $value eq '' ? () : ($value);
Branch: 1 branch
BranchTrueFalseTotal
$value eq '' ? : 0 0 0
97 } else {
98 0 $vars{$key} = $value;
99 }
100 0 ▶ diag( "$key = $value" ) if $args{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"verbose"} 0 0 0
101 } elsif( $_ =~ qr/^\s*{/ ) {
102 4 $json = $_;
103 } else { # identifier
104 3 $comment = '';
105 3 push @ids, $_;
106 }
107 }
108 3 $run->();
109 }
110  
111 1 1;
112  
113 __END__
« blib/lib/Plack/App/DAIA/Validator.pm ↑ Summary blib/lib/Plack/App/DAIA.pm »