| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | croak 'usage: provedaia( $file | $glob | $string )' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
builtin::reftype($suite) eq "GLOB" or builtin::blessed($suite) and $suite->isa("IO::File")
builtin::blessed($suite) and $suite->isa("IO::File")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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]/
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]/
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | open (my $fh, '<', $suite) or croak "failed to open daia test suite $suite"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 4 | ▶ | $json ||= '{ }'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$json ||= "{ }"
MC/DC0%0/1
$json ||= "{ }"
$json
Truth table50%1/2
A
A= $json
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 4 | my $server_name = $server; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | ▶ | if ( $server !~ qr{^https?://}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 6 | $test_json = decode_json($test_json); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 6 | ▶ | if (ref($server)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 35 | ▶ | $args{end} = 0 if /__END__/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 35 | next; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 15 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 15 | ▶ | $comment = $1 if /^#(.*)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 15 | s/^(#.*|\s+)$//; # empty line or comment | |||||||||||||||||||||||||||||||||||||||||
| 81 | 15 | $line++; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 15 | ▶ | if (defined $json) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | $json .= $_; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | ▶ | if ($_ eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | @ids = $value eq '' ? () : ($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $vars{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | diag( "$key = $value" ) if $args{verbose}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||