blib/lib/Langertha/Holmgang/Structure.pm

filter: Statementstmt 60.2% 537 / 891 Branchbran 48.3% 295 / 610 Conditioncond 37.4% 226 / 603 MC/DCmcdc 24.6% 82 / 333 Subroutinesub 65.3% 51 / 78 Podpod 100% 14 / 14 totaltotal 47.6% 1205 / 2529 CC 689 SCAR 48.8
CC
689
Cov
50%
case
496.1
case
496.1
suite_head
214.2
CRAP 131.9
« blib/lib/Langertha/Holmgang/Sim/Linux.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Backup.pm »
1 package Langertha::Holmgang::Structure;
2 # ABSTRACT: The shape checks of suite format 2, shared by the loader and the DSL
3  
4 36 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 36 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 36 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 36 ▶use Digest::SHA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 36 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 36 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 36 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 36 ▶use Langertha::Holmgang::Case;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 36 ▶use Langertha::Holmgang::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 36 ▶use Langertha::Holmgang::Excerpt;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 36 ▶use Langertha::Holmgang::Expectation ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 36 ▶use Langertha::Holmgang::Haystack;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 36 ▶use Langertha::Holmgang::Simulators;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 36 ▶use Langertha::Holmgang::Target ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 36 ▶use Langertha::Holmgang::ToolSchema qw( check_schema );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 36 ▶use Langertha::Holmgang::World;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 36 our $VERSION = '0.001';
23  
24 # true constants: the vocabulary of format 2
25 36 our @RULE_KINDS = qw( state unchanged_except calls not_called only_tools check packet login );
26 36 our @MATCHERS = @Langertha::Holmgang::Expectation::MATCHERS;
27 36 our @MODIFIERS = @Langertha::Holmgang::Expectation::MODIFIERS;
28 36 our @OPS = @Langertha::Holmgang::World::OPS;
29 36 our @CASE_KEYS = qw( id title tags difficulty system messages state observe rules solution
30 alternatives wrong_solutions temperature max_tokens max_turns source weight );
31 36 our @SUITE_KEYS = qw( format id version title description license defaults source tools topic threshold repeat );
32  
33 # images on a user message (k27): at most this many per message, each at most
34 # this many bytes; true constants
35 36 our $IMAGES_PER_MESSAGE = 4;
36 36 our $IMAGE_MAX_BYTES = 2 * 1024 * 1024;
37  
38 36 my %SIMULATOR_PARAMS = ( run_command => [qw( host command )], write_file => [qw( host path content )] );
39 36 my %HOOK = map { $_ => 1 } qw( prerouting input forward output postrouting );
40 36 my %L4 = map { $_ => 1 } qw( tcp udp icmp icmpv6 );
41  
42 36 my $ID_RE = qr/\A[a-z0-9][a-z0-9-]{0,63}\z/;
43 36 my $TOOL_RE = qr/\A[A-Za-z_][A-Za-z0-9_-]{0,63}\z/;
44  
45  
46 36 has simulators => (
47 is => 'ro',
48 lazy => 1,
49 builder => '_build_simulators',
50 );
51 0 ▶sub _build_simulators { Langertha::Holmgang::Simulators->new }
Subroutine _build_simulators: not called CC=1 SCAR=6.9
52  
53  
54 36 has haystack => (
55 is => 'ro',
56 lazy => 1,
57 builder => '_build_haystack',
58 );
59 0 ▶sub _build_haystack { Langertha::Holmgang::Haystack->new }
Subroutine _build_haystack: not called CC=1 SCAR=6.9
60  
61  
62 36 has excerpt => (
63 is => 'ro',
64 lazy => 1,
65 builder => '_build_excerpt',
66 );
67 71 ▶sub _build_excerpt { Langertha::Holmgang::Excerpt->new }
Subroutine _build_excerpt: called CC=1 SCAR=0.0
68  
69  
70 96 ▶sub _refuse {
Subroutine _refuse: called CC=1 SCAR=1.2
71 0 ▶ my ( $self, $field, $reason ) = @_;
Subroutine _refuse: not called CC=1 SCAR=1.2
72 0 Langertha::Holmgang::Error->throw( $field, $reason );
73 }
74  
75 909 ▶sub valid_id {
Subroutine valid_id: called CC=4 SCAR=21.3
Pod documented
76 0 ▶ my ( $self, $id ) = @_;
Subroutine valid_id: not called CC=4 SCAR=21.3
Pod documented
77 0 ▶ return defined $id && !ref $id && $id =~ $ID_RE ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
defined $id && !ref($id) && $id =~ /$ID_RE/ ? : 908 1 909
defined $id && !ref($id) && $id =~ /$ID_RE/ ? : 0 0 0
Condition25%3/12
defined $id and not ref $id and $id =~ /$ID_RE/
!ll&&!rl&&r
01908
defined $id and not ref $id
!ll&&!rl&&r
00909
defined $id and not ref $id and $id =~ /$ID_RE/
!ll&&!rl&&r
000
defined $id and not ref $id
!ll&&!rl&&r
000
MC/DC33%1/3
defined $id and not ref $id and $id =~ /$ID_RE/
defined $id not ref $id $id =~ /$ID_RE/
MC/DC0%0/3
defined $id and not ref $id and $id =~ /$ID_RE/
defined $id not ref $id $id =~ /$ID_RE/
Truth table50%2/4
A and not(B) and C
A= defined $idB= not ref $idC= $id =~ /$ID_RE/
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and not(B) and C
A= defined $idB= not ref $idC= $id =~ /$ID_RE/
ABCresult
0XX0
10X0
1100
1111
78 }
79  
80  
81 #### Small checks
82  
83 5762 ▶sub _keys_ok {
Subroutine _keys_ok: called CC=4 SCAR=18.9
84 0 ▶ my ( $self, $h, $field, @ok ) = @_;
Subroutine _keys_ok: not called CC=4 SCAR=18.9
85 0 ▶ $self->_refuse( $field, 'not a hash' ) unless ref $h eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $h eq "HASH" 0 5762 5762
unless ref $h eq "HASH" 0 0 0
86 0 my %ok = map { $_ => 1 } @ok;
87 0 for my $k ( sort keys %$h ) {
88 0 ▶ $self->_refuse( $field.'.'.$k, 'unknown key' ) unless $ok{$k};
Branch: 2 branches
BranchTrueFalseTotal
unless $ok{$k} 9 15678 15687
unless $ok{$k} 0 0 0
89 }
90 0 return;
91 }
92  
93 7160 ▶sub _text {
Subroutine _text: called CC=6 SCAR=25.9
94 0 ▶ my ( $self, $v, $field, $optional ) = @_;
Subroutine _text: not called CC=6 SCAR=25.9
95 0 ▶ return undef if $optional && !defined $v;
Branch: 2 branches
BranchTrueFalseTotal
if $optional and not defined $v 735 6425 7160
if $optional and not defined $v 0 0 0
Condition50%3/6
$optional and not defined $v
!ll&&!rl&&r
5780645735
$optional and not defined $v
!ll&&!rl&&r
000
MC/DC100%2/2
$optional and not defined $v
$optional not defined $v
MC/DC0%0/2
$optional and not defined $v
$optional not defined $v
Truth table100%3/3
A and not(B)
A= $optionalB= not defined $v
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $optionalB= not defined $v
ABresult
0X0
100
111
96 0 ▶ $self->_refuse( $field, 'text missing' ) if !defined $v || ref $v || !length $v;
Branch: 2 branches
BranchTrueFalseTotal
if not defined $v or ref $v or not length $v 1 6424 6425
if not defined $v or ref $v or not length $v 0 0 0
Condition25%3/12
not defined $v or ref $v or not length $v
l!l&&r!l&&!r
016424
not defined $v or ref $v
l!l&&r!l&&!r
006425
not defined $v or ref $v or not length $v
l!l&&r!l&&!r
000
not defined $v or ref $v
l!l&&r!l&&!r
000
MC/DC33%1/3
not defined $v or ref $v or not length $v
not defined $v ref $v not length $v
MC/DC0%0/3
not defined $v or ref $v or not length $v
not defined $v ref $v not length $v
Truth table50%2/4
not(A) or B or not(C)
A= not defined $vB= ref $vC= not length $v
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
not(A) or B or not(C)
A= not defined $vB= ref $vC= not length $v
ABCresult
1XX1
01X1
0011
0000
97 0 return "$v";
98 }
99  
100 286 ▶sub _num {
Subroutine _num: called CC=7 SCAR=29.4
101 0 ▶ my ( $self, $v, $field, $min, $max ) = @_;
Subroutine _num: not called CC=7 SCAR=29.4
102 0 ▶ $self->_refuse( $field, 'not a number' ) if !defined $v || ref $v || $v !~ /\A-?(?:\d+\.?\d*|\.\d+)\z/;
Branch: 2 branches
BranchTrueFalseTotal
if not defined $v or ref $v or not $v =~ /\A-?(?:\d+\.?\d*|\.\d+)\z/ 0 286 286
if not defined $v or ref $v or not $v =~ /\A-?(?:\d+\.?\d*|\.\d+)\z/ 0 0 0
Condition16%2/12
not defined $v or ref $v or not $v =~ /\A-?(?:\d+\.?\d*|\.\d+)\z/
l!l&&r!l&&!r
00286
not defined $v or ref $v
l!l&&r!l&&!r
00286
not defined $v or ref $v or not $v =~ /\A-?(?:\d+\.?\d*|\.\d+)\z/
l!l&&r!l&&!r
000
not defined $v or ref $v
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $v or ref $v or not $v =~ /\A-?(?:\d+\.?\d*|\.\d+)\z/
not defined $v ref $v not $v =~ /\A-?(?:\d+\.?\d*|\.\d+)\z/
MC/DC0%0/3
not defined $v or ref $v or not $v =~ /\A-?(?:\d+\.?\d*|\.\d+)\z/
not defined $v ref $v not $v =~ /\A-?(?:\d+\.?\d*|\.\d+)\z/
Truth table25%1/4
not(A) or B or not(C)
A= not defined $vB= ref $vC= not $v =~ /\A-?(?:\d+\.?\d*|\.\d+)\z/
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
not(A) or B or not(C)
A= not defined $vB= ref $vC= not $v =~ /\A-?(?:\d+\.?\d*|\.\d+)\z/
ABCresult
1XX1
01X1
0011
0000
103 0 ▶ $self->_refuse( $field, 'outside '.$min.'..'.$max ) if $v < $min || defined $max && $v > $max;
Branch: 2 branches
BranchTrueFalseTotal
if $v < $min or defined $max and $v > $max 6 280 286
if $v < $min or defined $max and $v > $max 0 0 0
Condition50%6/12
$v < $min or defined $max and $v > $max
l!l&&r!l&&!r
24280
defined $max and $v > $max
!ll&&!rl&&r
192614
$v < $min or defined $max and $v > $max
l!l&&r!l&&!r
000
defined $max and $v > $max
!ll&&!rl&&r
000
MC/DC100%3/3
$v < $min or defined $max and $v > $max
$v < $min defined $max $v > $max
MC/DC0%0/3
$v < $min or defined $max and $v > $max
$v < $min defined $max $v > $max
Truth table100%4/4
A or B and C
A= $v < $minB= defined $maxC= $v > $max
ABCresult
1XX1
0111
00X0
0100
Truth table0%0/4
A or B and C
A= $v < $minB= defined $maxC= $v > $max
ABCresult
1XX1
0111
00X0
0100
104 0 return 0 + $v;
105 }
106  
107 98 ▶sub _regex {
Subroutine _regex: called CC=2 SCAR=9.2
108 0 ▶ my ( $self, $v, $field ) = @_;
Subroutine _regex: not called CC=2 SCAR=9.2
109 0 $self->_text( $v, $field );
110 0 ▶ $self->_refuse( $field, 'invalid regular expression' ) unless eval { qr/$v/; 1 };
Branch: 2 branches
BranchTrueFalseTotal
unless eval { do { qr/$v/; 1 } } 1 97 98
unless eval { do { qr/$v/; 1 } } 0 0 0
111 0 return "$v";
112 }
113  
114 # a mark true/false (missing = false)
115 524 ▶sub _flag {
Subroutine _flag: called CC=5 SCAR=22.8
116 0 ▶ my ( $self, $v, $field ) = @_;
Subroutine _flag: not called CC=5 SCAR=22.8
117 0 ▶ return 0 unless defined $v;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $v 502 22 524
unless defined $v 0 0 0
118 $self->_refuse( $field, 'true or false' )
119 0 ▶ if ref $v ? !JSON::MaybeXS::is_bool($v) : !grep { $v eq $_ } '1', '0', '';
Branch: 4 branches
BranchTrueFalseTotal
if ref $v ? !JSON::MaybeXS::is_bool($v) : !grep({$v eq $_;} 1, 0, "") 2 20 22
ref $v ? : 0 22 22
if ref $v ? !JSON::MaybeXS::is_bool($v) : !grep({$v eq $_;} 1, 0, "") 0 0 0
ref $v ? : 0 0 0
120 0 ▶ return $v ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$v ? : 20 0 20
$v ? : 0 0 0
121 }
122  
123 4052 ▶sub _list {
Subroutine _list: called CC=4 SCAR=17.9
124 0 ▶ my ( $self, $v, $field, $nonempty ) = @_;
Subroutine _list: not called CC=4 SCAR=17.9
125 0 ▶ $self->_refuse( $field, 'not a list' ) unless ref $v eq 'ARRAY';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $v eq "ARRAY" 3 4049 4052
unless ref $v eq "ARRAY" 0 0 0
126 0 ▶ $self->_refuse( $field, 'empty list' ) if $nonempty && !@$v;
Branch: 2 branches
BranchTrueFalseTotal
if $nonempty and not @$v 1 4048 4049
if $nonempty and not @$v 0 0 0
Condition50%3/6
$nonempty and not @$v
!ll&&!rl&&r
156124871
$nonempty and not @$v
!ll&&!rl&&r
000
MC/DC100%2/2
$nonempty and not @$v
$nonempty not @$v
MC/DC0%0/2
$nonempty and not @$v
$nonempty not @$v
Truth table100%3/3
A and not(B)
A= $nonemptyB= not @$v
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $nonemptyB= not @$v
ABresult
0X0
100
111
127 0 return $v;
128 }
129  
130 15 ▶sub _scalars {
Subroutine _scalars: called CC=3 SCAR=17.0
131 0 ▶ my ( $self, $v, $field ) = @_;
Subroutine _scalars: not called CC=3 SCAR=17.0
132 0 $self->_list( $v, $field, 1 );
133 0 ▶ $self->_refuse( $field, 'list of values expected' ) if grep { !defined || ref } @$v;
Branch: 2 branches
BranchTrueFalseTotal
if grep {not defined $_ or ref $_;} @$v 0 15 15
if grep {not defined $_ or ref $_;} @$v 0 0 0
Condition16%1/6
!defined($_) || ref $_
l!l&&r!l&&!r
0030
!defined($_) || ref $_
l!l&&r!l&&!r
000
MC/DC0%0/2
!defined($_) || ref $_
!defined($_) ref $_
MC/DC0%0/2
!defined($_) || ref $_
!defined($_) ref $_
Truth table33%1/3
not(A) || B
A= !defined($_)B= ref $_
ABresult
1X1
011
000
Truth table0%0/3
not(A) || B
A= !defined($_)B= ref $_
ABresult
1X1
011
000
134 0 return $v;
135 }
136  
137 # a path: dotted text or a list of segments
138 1012 ▶sub _path {
Subroutine _path: called CC=7 SCAR=30.1
139 0 ▶ my ( $self, $p, $field ) = @_;
Subroutine _path: not called CC=7 SCAR=30.1
140 0 ▶ if ( ref $p eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $p eq "ARRAY") 75 937 1012
if (ref $p eq "ARRAY") 0 0 0
141 0 ▶ $self->_refuse( $field, 'empty path' ) unless @$p;
Branch: 2 branches
BranchTrueFalseTotal
unless @$p 0 75 75
unless @$p 0 0 0
142 0 ▶ $self->_refuse( $field, 'segments must be text' ) if grep { !defined || ref || !length } @$p;
Branch: 2 branches
BranchTrueFalseTotal
if grep {not defined $_ or ref $_ or not length $_;} @$p 0 75 75
if grep {not defined $_ or ref $_ or not length $_;} @$p 0 0 0
Condition16%2/12
!defined($_) || ref $_ || !length($_)
l!l&&r!l&&!r
00272
not defined $_ or ref $_
l!l&&r!l&&!r
00272
!defined($_) || ref $_ || !length($_)
l!l&&r!l&&!r
000
not defined $_ or ref $_
l!l&&r!l&&!r
000
MC/DC0%0/3
!defined($_) || ref $_ || !length($_)
not defined $_ ref $_ !length($_)
MC/DC0%0/3
!defined($_) || ref $_ || !length($_)
not defined $_ ref $_ !length($_)
Truth table25%1/4
not(A) or B || not(C)
A= not defined $_B= ref $_C= !length($_)
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
not(A) or B || not(C)
A= not defined $_B= ref $_C= !length($_)
ABCresult
1XX1
01X1
0011
0000
143 0 return $p;
144 }
145 0 $self->_text( $p, $field );
146 0 ▶ $self->_refuse( $field, 'path with an empty segment' ) if grep { !length } split /\./, $p, -1;
Branch: 2 branches
BranchTrueFalseTotal
if grep {not length $_;} split(/\./, $p, -1) 0 937 937
if grep {not length $_;} split(/\./, $p, -1) 0 0 0
147 0 return $p;
148 }
149  
150 308 ▶sub _arg_patterns {
Subroutine _arg_patterns: called CC=3 SCAR=15.7
151 0 ▶ my ( $self, $m, $field ) = @_;
Subroutine _arg_patterns: not called CC=3 SCAR=15.7
152 0 ▶ $self->_refuse( $field, 'not a hash' ) unless ref $m eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $m eq "HASH" 0 308 308
unless ref $m eq "HASH" 0 0 0
153 0 $self->_regex( $m->{$_}, $field.'.'.$_ ) for sort keys %$m;
154 0 return $m;
155 }
156  
157 # a pattern for a list element: a regex (text) or a hash field -> regex | expectations
158 8 ▶sub _element {
Subroutine _element: called CC=6 SCAR=28.1
159 0 ▶ my ( $self, $m, $field ) = @_;
Subroutine _element: not called CC=6 SCAR=28.1
160 0 ▶ return $self->_regex( $m, $field ) unless ref $m;
Branch: 2 branches
BranchTrueFalseTotal
unless ref $m 0 8 8
unless ref $m 0 0 0
161 0 ▶ $self->_refuse( $field, 'pattern (text) or hash field -> pattern expected' ) unless ref $m eq 'HASH' && %$m;
Branch: 2 branches
BranchTrueFalseTotal
unless ref $m eq "HASH" and %$m 0 8 8
unless ref $m eq "HASH" and %$m 0 0 0
Condition16%1/6
ref $m eq "HASH" and %$m
!ll&&!rl&&r
008
ref $m eq "HASH" and %$m
!ll&&!rl&&r
000
MC/DC0%0/2
ref $m eq "HASH" and %$m
ref $m eq "HASH" %$m
MC/DC0%0/2
ref $m eq "HASH" and %$m
ref $m eq "HASH" %$m
Truth table33%1/3
A and B
A= ref $m eq "HASH"B= %$m
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $m eq "HASH"B= %$m
ABresult
0X0
100
111
162 0 for my $f ( sort keys %$m ) {
163 0 ▶ ref $m->{$f} ? $self->_matchers( $m->{$f}, $field.'.'.$f, 1 ) : $self->_regex( $m->{$f}, $field.'.'.$f );
Branch: 2 branches
BranchTrueFalseTotal
ref $m->{$f} ? : 0 8 8
ref $$m{$f} ? : 0 0 0
164 }
165 0 return $m;
166 }
167  
168 # expectations on a value (Expectation::condition); with $bare without path
169 421 ▶sub _matchers {
Subroutine _matchers: called CC=29 SCAR=53.5
170 0 ▶ my ( $self, $c, $field, $bare ) = @_;
Subroutine _matchers: not called CC=29 SCAR=53.5
171 0 ▶ $self->_keys_ok( $c, $field, ( $bare ? () : 'path' ), @MATCHERS, @MODIFIERS );
Branch: 2 branches
BranchTrueFalseTotal
$bare ? : 5 416 421
$bare ? : 0 0 0
172 0 ▶ $self->_path( $c->{path}, $field.'.path' ) unless $bare;
Branch: 2 branches
BranchTrueFalseTotal
unless $bare 414 5 419
unless $bare 0 0 0
173 0 ▶ if ( exists $c->{tolerance} ) { # k49: qualifies a numeric equals
Branch: 2 branches
BranchTrueFalseTotal
if (exists $c->{"tolerance"}) 13 406 419
if (exists $$c{"tolerance"}) 0 0 0
174 0 ▶ $self->_refuse( $field.'.tolerance', 'needs equals' ) unless exists $c->{equals};
Branch: 2 branches
BranchTrueFalseTotal
unless exists $c->{"equals"} 2 11 13
unless exists $$c{"equals"} 0 0 0
175 0 my $num = qr/\A-?(?:\d+\.?\d*|\.\d+)\z/;
176 0 my ( $e, $t ) = @$c{qw( equals tolerance )};
177 0 ▶ $self->_refuse( $field.'.equals', 'number expected beside tolerance' ) if !defined $e || ref $e || $e !~ $num;
Branch: 2 branches
BranchTrueFalseTotal
if not defined $e or ref $e or not $e =~ /$num/ 1 10 11
if not defined $e or ref $e or not $e =~ /$num/ 0 0 0
Condition25%3/12
not defined $e or ref $e or not $e =~ /$num/
l!l&&r!l&&!r
0110
not defined $e or ref $e
l!l&&r!l&&!r
0011
not defined $e or ref $e or not $e =~ /$num/
l!l&&r!l&&!r
000
not defined $e or ref $e
l!l&&r!l&&!r
000
MC/DC33%1/3
not defined $e or ref $e or not $e =~ /$num/
not defined $e ref $e not $e =~ /$num/
MC/DC0%0/3
not defined $e or ref $e or not $e =~ /$num/
not defined $e ref $e not $e =~ /$num/
Truth table50%2/4
not(A) or B or not(C)
A= not defined $eB= ref $eC= not $e =~ /$num/
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
not(A) or B or not(C)
A= not defined $eB= ref $eC= not $e =~ /$num/
ABCresult
1XX1
01X1
0011
0000
178 0 ▶ $self->_refuse( $field.'.tolerance', 'number of 0 or more expected' ) if !defined $t || ref $t || $t !~ $num || $t < 0;
Branch: 2 branches
BranchTrueFalseTotal
if not defined $t or ref $t or not $t =~ /$num/ or $t < 0 3 7 10
if not defined $t or ref $t or not $t =~ /$num/ or $t < 0 0 0 0
Condition44%8/18
not defined $t or ref $t or not $t =~ /$num/ or $t < 0
l!l&&r!l&&!r
217
not defined $t or ref $t or not $t =~ /$num/
l!l&&r!l&&!r
118
not defined $t or ref $t
l!l&&r!l&&!r
019
not defined $t or ref $t or not $t =~ /$num/ or $t < 0
l!l&&r!l&&!r
000
not defined $t or ref $t or not $t =~ /$num/
l!l&&r!l&&!r
000
not defined $t or ref $t
l!l&&r!l&&!r
000
MC/DC75%3/4
not defined $t or ref $t or not $t =~ /$num/ or $t < 0
not defined $t ref $t not $t =~ /$num/ $t < 0
MC/DC0%0/4
not defined $t or ref $t or not $t =~ /$num/ or $t < 0
not defined $t ref $t not $t =~ /$num/ $t < 0
Truth table80%4/5
not(A) or B or not(C) or D
A= not defined $tB= ref $tC= not $t =~ /$num/D= $t < 0
ABCDresult
1XXX1
01XX1
001X1
00011
00000
Truth table0%0/5
not(A) or B or not(C) or D
A= not defined $tB= ref $tC= not $t =~ /$num/D= $t < 0
ABCDresult
1XXX1
01XX1
001X1
00011
00000
179 }
180 0 my @m = grep { exists $c->{$_} } @MATCHERS;
181 0 ▶ $self->_refuse( $field, 'no expectation ('.join( ', ', @MATCHERS ).')' ) unless @m;
Branch: 2 branches
BranchTrueFalseTotal
unless @m 0 413 413
unless @m 0 0 0
182 0 for my $k ( @m ) {
183 0 my $v = $c->{$k};
184 0 ▶ if ( $k eq 'exists' || $k eq 'absent' ) { }
Branch: 12 branches
BranchTrueFalseTotal
if ($k eq 'exists' or $k eq 'absent') { } 16 409 425
elsif ($k eq 'equals') { } 333 76 409
elsif ($k eq 'in' or $k eq 'contains' or $k eq 'excludes') { } 15 61 76
elsif ($k eq 'regex') { } 40 21 61
elsif ($k eq 'length') { } 13 8 21
elsif ($k eq 'any' or $k eq 'none') { } 8 0 8
if ($k eq 'exists' or $k eq 'absent') { } 0 0 0
elsif ($k eq 'equals') { } 0 0 0
elsif ($k eq 'in' or $k eq 'contains' or $k eq 'excludes') { } 0 0 0
elsif ($k eq 'regex') { } 0 0 0
elsif ($k eq 'length') { } 0 0 0
elsif ($k eq 'any' or $k eq 'none') { } 0 0 0
Condition33%2/6
$k eq "exists" or $k eq "absent"
l!l&&r!l&&!r
160409
$k eq "exists" or $k eq "absent"
l!l&&r!l&&!r
000
MC/DC50%1/2
$k eq "exists" or $k eq "absent"
$k eq "exists" $k eq "absent"
MC/DC0%0/2
$k eq "exists" or $k eq "absent"
$k eq "exists" $k eq "absent"
Truth table66%2/3
A or B
A= $k eq "exists"B= $k eq "absent"
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $k eq "exists"B= $k eq "absent"
ABresult
1X1
011
000
185 0 ▶ elsif ( $k eq 'equals' ) { $self->_refuse( $field.'.equals', 'value expected' ) if !defined $v || ref $v }
Branch: 2 branches
BranchTrueFalseTotal
if not defined $v or ref $v 2 331 333
if not defined $v or ref $v 0 0 0
Condition33%2/6
not defined $v or ref $v
l!l&&r!l&&!r
02331
not defined $v or ref $v
l!l&&r!l&&!r
000
MC/DC50%1/2
not defined $v or ref $v
not defined $v ref $v
MC/DC0%0/2
not defined $v or ref $v
not defined $v ref $v
Truth table66%2/3
not(A) or B
A= not defined $vB= ref $v
ABresult
1X1
011
000
Truth table0%0/3
not(A) or B
A= not defined $vB= ref $v
ABresult
1X1
011
000
186 0 ▶ elsif ( $k eq 'in' || $k eq 'contains' || $k eq 'excludes' ) { $self->_scalars( $v, $field.'.'.$k ) }
Condition41%5/12
$k eq "in" or $k eq "contains" or $k eq "excludes"
l!l&&r!l&&!r
15061
$k eq "in" or $k eq "contains"
l!l&&r!l&&!r
31261
$k eq "in" or $k eq "contains" or $k eq "excludes"
l!l&&r!l&&!r
000
$k eq "in" or $k eq "contains"
l!l&&r!l&&!r
000
MC/DC66%2/3
$k eq "in" or $k eq "contains" or $k eq "excludes"
$k eq "in" $k eq "contains" $k eq "excludes"
MC/DC0%0/3
$k eq "in" or $k eq "contains" or $k eq "excludes"
$k eq "in" $k eq "contains" $k eq "excludes"
Truth table75%3/4
A or B or C
A= $k eq "in"B= $k eq "contains"C= $k eq "excludes"
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
A or B or C
A= $k eq "in"B= $k eq "contains"C= $k eq "excludes"
ABCresult
1XX1
01X1
0011
0000
187 0 elsif ( $k eq 'regex' ) { $self->_regex( $v, $field.'.regex' ) }
188 0 elsif ( $k eq 'length' ) { $self->_num( $v, $field.'.length', 0, 100_000 ) }
189 0 ▶ elsif ( $k eq 'any' || $k eq 'none' ) { $self->_element( $v, $field.'.'.$k ) }
Condition33%2/6
$k eq "any" or $k eq "none"
l!l&&r!l&&!r
440
$k eq "any" or $k eq "none"
l!l&&r!l&&!r
000
MC/DC0%0/2
$k eq "any" or $k eq "none"
$k eq "any" $k eq "none"
MC/DC0%0/2
$k eq "any" or $k eq "none"
$k eq "any" $k eq "none"
Truth table66%2/3
A or B
A= $k eq "any"B= $k eq "none"
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $k eq "any"B= $k eq "none"
ABresult
1X1
011
000
190 else { # before
191 0 ▶ $self->_refuse( $field.'.before', 'exactly two patterns' ) unless ref $v eq 'ARRAY' && @$v == 2;
Branch: 2 branches
BranchTrueFalseTotal
unless ref $v eq "ARRAY" and @$v == 2 0 0 0
unless ref $v eq "ARRAY" and @$v == 2 0 0 0
Condition0%0/6
ref $v eq "ARRAY" and @$v == 2
!ll&&!rl&&r
000
ref $v eq "ARRAY" and @$v == 2
!ll&&!rl&&r
000
MC/DC0%0/2
ref $v eq "ARRAY" and @$v == 2
ref $v eq "ARRAY" @$v == 2
MC/DC0%0/2
ref $v eq "ARRAY" and @$v == 2
ref $v eq "ARRAY" @$v == 2
Truth table0%0/3
A and B
A= ref $v eq "ARRAY"B= @$v == 2
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $v eq "ARRAY"B= @$v == 2
ABresult
0X0
100
111
192 0 $self->_element( $v->[$_], $field.'.before['.$_.']' ) for 0, 1;
193 }
194 }
195 0 return $c;
196 }
197  
198 273 ▶sub _op {
Subroutine _op: called CC=6 SCAR=26.0
199 0 ▶ my ( $self, $o, $field ) = @_;
Subroutine _op: not called CC=6 SCAR=26.0
200 0 ▶ $self->_refuse( $field, 'not a hash' ) unless ref $o eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $o eq "HASH" 0 273 273
unless ref $o eq "HASH" 0 0 0
201 0 my @kind = grep { exists $o->{$_} } @OPS;
202 0 ▶ $self->_refuse( $field, 'exactly one change ('.join( ', ', @OPS ).')' ) unless @kind == 1;
Branch: 2 branches
BranchTrueFalseTotal
unless @kind == 1 0 273 273
unless @kind == 1 0 0 0
203 0 my $kind = $kind[0];
204 0 my %need = ( set => ['value'], push => ['value'], insert => [qw( at value )], delete => [],
205 remove => ['where'], move => [qw( from to )] );
206 0 $self->_keys_ok( $o, $field, $kind, @{ $need{$kind} } );
207 0 ▶ exists $o->{$_} or $self->_refuse( $field.'.'.$_, 'missing' ) for @{ $need{$kind} };
Branch: 2 branches
BranchTrueFalseTotal
exists $o->{$_} or $self->_refuse($field . '.' . $_, "missing") 275 0 275
exists $$o{$_} or $self->_refuse($field . '.' . $_, "missing") 0 0 0
208 0 $self->_path( $o->{$kind}, $field.'.'.$kind );
209 0 ▶ $self->_element( $o->{where}, $field.'.where' ) if exists $o->{where};
Branch: 2 branches
BranchTrueFalseTotal
if exists $o->{"where"} 0 273 273
if exists $$o{"where"} 0 0 0
210 0 return $o;
211 }
212  
213 286 ▶sub _handler {
Subroutine _handler: called CC=8 SCAR=27.7
214 0 ▶ my ( $self, $h, $field, @keys ) = @_;
Subroutine _handler: not called CC=8 SCAR=27.7
215 0 ▶ $self->_keys_ok( $h, $field, @keys ? @keys : qw( match when apply output error ) );
Branch: 2 branches
BranchTrueFalseTotal
@keys ? : 6 280 286
@keys ? : 0 0 0
216 0 ▶ $self->_arg_patterns( $h->{match} // {}, $field.'.match' );
Condition50%2/4
$h->{"match"} // {}
l!l
35251
$$h{"match"} // {}
l!l
00
MC/DC100%1/1
$h->{"match"} // {}
$h->{"match"}
MC/DC0%0/1
$$h{"match"} // {}
$$h{"match"}
Truth table100%2/2
A
A= $h->{"match"}
Aresult
11
00
Truth table0%0/2
A
A= $$h{"match"}
Aresult
11
00
217 0 ▶ my $when = $self->_list( $h->{when} // [], $field.'.when' );
Condition50%2/4
$h->{"when"} // []
l!l
16270
$$h{"when"} // []
l!l
00
MC/DC100%1/1
$h->{"when"} // []
$h->{"when"}
MC/DC0%0/1
$$h{"when"} // []
$$h{"when"}
Truth table100%2/2
A
A= $h->{"when"}
Aresult
11
00
Truth table0%0/2
A
A= $$h{"when"}
Aresult
11
00
218 0 $self->_matchers( $when->[$_], $field.'.when['.$_.']' ) for 0 .. $#$when;
219 0 ▶ my $apply = $self->_list( $h->{apply} // [], $field.'.apply' );
Condition50%2/4
$h->{"apply"} // []
l!l
27313
$$h{"apply"} // []
l!l
00
MC/DC100%1/1
$h->{"apply"} // []
$h->{"apply"}
MC/DC0%0/1
$$h{"apply"} // []
$$h{"apply"}
Truth table100%2/2
A
A= $h->{"apply"}
Aresult
11
00
Truth table0%0/2
A
A= $$h{"apply"}
Aresult
11
00
220 0 $self->_op( $apply->[$_], $field.'.apply['.$_.']' ) for 0 .. $#$apply;
221 0 ▶ $self->_text( $h->{output}, $field.'.output', 1 ) unless @keys;
Branch: 2 branches
BranchTrueFalseTotal
unless @keys 280 6 286
unless @keys 0 0 0
222 0 return $h;
223 }
224  
225 #### Suite head and tools
226  
227 531 ▶sub tool {
Subroutine tool: called CC=22 SCAR=47.7
Pod documented
228 0 ▶ my ( $self, $t, $field ) = @_;
Subroutine tool: not called CC=22 SCAR=47.7
Pod documented
229 0 $self->_keys_ok( $t, $field, qw( name description parameters handlers simulator ) );
230 0 ▶ my $name = $t->{name} // '';
Condition25%1/4
$t->{"name"} // ""
l!l
5310
$$t{"name"} // ""
l!l
00
MC/DC0%0/1
$t->{"name"} // ""
$t->{"name"}
MC/DC0%0/1
$$t{"name"} // ""
$$t{"name"}
Truth table50%1/2
A
A= $t->{"name"}
Aresult
11
00
Truth table0%0/2
A
A= $$t{"name"}
Aresult
11
00
231 0 ▶ $self->_refuse( $field.'.name', 'invalid tool name' ) unless !ref $name && $name =~ $TOOL_RE;
Branch: 2 branches
BranchTrueFalseTotal
unless not ref $name and $name =~ /$TOOL_RE/ 0 531 531
unless not ref $name and $name =~ /$TOOL_RE/ 0 0 0
Condition16%1/6
not ref $name and $name =~ /$TOOL_RE/
!ll&&!rl&&r
00531
not ref $name and $name =~ /$TOOL_RE/
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $name and $name =~ /$TOOL_RE/
not ref $name $name =~ /$TOOL_RE/
MC/DC0%0/2
not ref $name and $name =~ /$TOOL_RE/
not ref $name $name =~ /$TOOL_RE/
Truth table33%1/3
not(A) and B
A= not ref $nameB= $name =~ /$TOOL_RE/
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not ref $nameB= $name =~ /$TOOL_RE/
ABresult
0X0
100
111
232 0 ▶ my $params = $t->{parameters} // { type => 'object', properties => {} };
Condition50%2/4
$t->{"parameters"} // {"type", "object", "properties", {}}
l!l
5283
$$t{"parameters"} // {"type", "object", "properties", {}}
l!l
00
MC/DC100%1/1
$t->{"parameters"} // {"type", "object", "properties", {}}
$t->{"parameters"}
MC/DC0%0/1
$$t{"parameters"} // {"type", "object", "properties", {}}
$$t{"parameters"}
Truth table100%2/2
A
A= $t->{"parameters"}
Aresult
11
00
Truth table0%0/2
A
A= $$t{"parameters"}
Aresult
11
00
233 $self->_refuse( $field.'.parameters', 'JSON Schema (type: object) expected' )
234 0 ▶ unless ref $params eq 'HASH' && ( $params->{type} // '' ) eq 'object';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $params eq "HASH" and ($params->{"type"} // "") eq "object" 0 531 531
unless ref $params eq "HASH" and ($$params{"type"} // "") eq "object" 0 0 0
Condition20%2/10
ref $params eq "HASH" and ($params->{"type"} // "") eq "object"
!ll&&!rl&&r
00531
$params->{"type"} // ""
l!l
5310
ref $params eq "HASH" and ($$params{"type"} // "") eq "object"
!ll&&!rl&&r
000
$$params{"type"} // ""
l!l
00
MC/DC0%0/2
ref $params eq "HASH" and ($params->{"type"} // "") eq "object"
ref $params eq "HASH" $params->{"type"}
MC/DC0%0/2
ref $params eq "HASH" and ($$params{"type"} // "") eq "object"
ref $params eq "HASH" $$params{"type"}
Truth table33%1/3
A and B
A= ref $params eq "HASH"B= $params->{"type"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $params eq "HASH"B= $$params{"type"}
ABresult
0X0
100
111
235 0 check_schema( $params, $field.'.parameters' );
236 0 $self->_text( $t->{description}, $field.'.description' );
237 0 ▶ if ( defined( my $sim = $t->{simulator} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $sim = $t->{'simulator'})) { } 253 276 529
if (defined(my $sim = $$t{'simulator'})) { } 0 0 0
238 0 my $sims = $self->simulators;
239 0 ▶ my $world = !ref $sim && !$SIMULATOR_PARAMS{$sim} ? $sims->world_tools($sim) : undef;
Branch: 2 branches
BranchTrueFalseTotal
!(ref $sim || $SIMULATOR_PARAMS{$sim}) ? : 33 220 253
!(ref $sim || $SIMULATOR_PARAMS{$sim}) ? : 0 0 0
Condition33%2/6
ref $sim || $SIMULATOR_PARAMS{$sim}
l!l&&r!l&&!r
022033
ref $sim || $SIMULATOR_PARAMS{$sim}
l!l&&r!l&&!r
000
MC/DC50%1/2
ref $sim || $SIMULATOR_PARAMS{$sim}
ref $sim $SIMULATOR_PARAMS{$sim}
MC/DC0%0/2
ref $sim || $SIMULATOR_PARAMS{$sim}
ref $sim $SIMULATOR_PARAMS{$sim}
Truth table66%2/3
A || B
A= ref $simB= $SIMULATOR_PARAMS{$sim}
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= ref $simB= $SIMULATOR_PARAMS{$sim}
ABresult
1X1
011
000
240 $self->_refuse( $field.'.simulator', 'run_command, write_file or an answer world ('
241 0 .join( ', ', grep { $sims->world_tools($_) } $sims->types ).')' )
242 0 ▶ unless !ref $sim && ( $SIMULATOR_PARAMS{$sim} || $world );
Branch: 2 branches
BranchTrueFalseTotal
unless not ref $sim and $SIMULATOR_PARAMS{$sim} || $world 1 252 253
unless not ref $sim and $SIMULATOR_PARAMS{$sim} || $world 0 0 0
Condition41%5/12
not ref $sim and $SIMULATOR_PARAMS{$sim} || $world
!ll&&!rl&&r
01252
$SIMULATOR_PARAMS{$sim} or $world
l!l&&r!l&&!r
220321
not ref $sim and $SIMULATOR_PARAMS{$sim} || $world
!ll&&!rl&&r
000
$SIMULATOR_PARAMS{$sim} or $world
l!l&&r!l&&!r
000
MC/DC66%2/3
not ref $sim and $SIMULATOR_PARAMS{$sim} || $world
not ref $sim $SIMULATOR_PARAMS{$sim} $world
MC/DC0%0/3
not ref $sim and $SIMULATOR_PARAMS{$sim} || $world
not ref $sim $SIMULATOR_PARAMS{$sim} $world
Truth table75%3/4
not(A) and B or C
A= not ref $simB= $SIMULATOR_PARAMS{$sim}C= $world
ABCresult
0XX0
1000
11X1
1011
Truth table0%0/4
not(A) and B or C
A= not ref $simB= $SIMULATOR_PARAMS{$sim}C= $world
ABCresult
0XX0
1000
11X1
1011
243 0 ▶ $self->_refuse( $field.'.handlers', 'simulator or handlers, not both' ) if exists $t->{handlers};
Branch: 2 branches
BranchTrueFalseTotal
if exists $t->{"handlers"} 1 251 252
if exists $$t{"handlers"} 0 0 0
244 $self->_refuse( $field.'.name', 'the world '.$sim.' has no tool '.$name.' ('.join( ', ', sort keys %$world ).')' )
245 0 ▶ if $world && !$world->{$name};
Branch: 2 branches
BranchTrueFalseTotal
if $world and not $world->{$name} 1 250 251
if $world and not $$world{$name} 0 0 0
Condition50%3/6
$world and not $world->{$name}
!ll&&!rl&&r
220301
$world and not $$world{$name}
!ll&&!rl&&r
000
MC/DC100%2/2
$world and not $world->{$name}
$world not $world->{$name}
MC/DC0%0/2
$world and not $$world{$name}
$world not $$world{$name}
Truth table100%3/3
A and not(B)
A= $worldB= not $world->{$name}
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $worldB= not $$world{$name}
ABresult
0X0
100
111
246 0 ▶ for my $p ( @{ $world ? $world->{$name} : $SIMULATOR_PARAMS{$sim} } ) {
Branch: 2 branches
BranchTrueFalseTotal
$world ? : 30 220 250
$world ? : 0 0 0
247 $self->_refuse( $field.'.parameters', 'required parameter '.$p.' missing' )
248 0 ▶ unless grep { $_ eq $p } @{ $params->{required} || [] };
Branch: 2 branches
BranchTrueFalseTotal
unless grep {$_ eq $p;} @{$params->{"required"} or [];} 2 512 514
unless grep {$_ eq $p;} @{$$params{"required"} or [];} 0 0 0
Condition25%1/4
$params->{'required'} || []
l!l
5140
$$params{'required'} || []
l!l
00
MC/DC0%0/1
$params->{'required'} || []
$params->{'required'}
MC/DC0%0/1
$$params{'required'} || []
$$params{'required'}
Truth table50%1/2
A
A= $params->{'required'}
Aresult
11
00
Truth table0%0/2
A
A= $$params{'required'}
Aresult
11
00
249 }
250 }
251 else {
252 0 my $hs = $self->_list( $t->{handlers}, $field.'.handlers', 1 );
253 0 $self->_handler( $hs->[$_], $field.'.handlers['.$_.']' ) for 0 .. $#$hs;
254 }
255 0 return $t;
256 }
257  
258  
259 314 ▶sub suite_head {
Subroutine suite_head: called CC=33 SCAR=53.7
Pod documented
260 0 ▶ my ( $self, $head, %o ) = @_;
Subroutine suite_head: not called CC=33 SCAR=53.7
Pod documented
261 0 ▶ $self->_refuse( 'suite.yaml', 'not a hash' ) unless ref $head eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $head eq "HASH" 0 314 314
unless ref $head eq "HASH" 0 0 0
262 0 ▶ if ( exists $o{format} || exists $head->{format} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $o{"format"} or exists $head->{"format"}) 256 58 314
if (exists $o{"format"} or exists $$head{"format"}) 0 0 0
Condition33%2/6
exists $o{"format"} or exists $head->{"format"}
l!l&&r!l&&!r
256058
exists $o{"format"} or exists $$head{"format"}
l!l&&r!l&&!r
000
MC/DC50%1/2
exists $o{"format"} or exists $head->{"format"}
exists $o{"format"} exists $head->{"format"}
MC/DC0%0/2
exists $o{"format"} or exists $$head{"format"}
exists $o{"format"} exists $$head{"format"}
Truth table66%2/3
A or B
A= exists $o{"format"}B= exists $head->{"format"}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= exists $o{"format"}B= exists $$head{"format"}
ABresult
1X1
011
000
263 0 ▶ my $format = $head->{format} // '';
Condition50%2/4
$head->{"format"} // ""
l!l
2542
$$head{"format"} // ""
l!l
00
MC/DC100%1/1
$head->{"format"} // ""
$head->{"format"}
MC/DC0%0/1
$$head{"format"} // ""
$$head{"format"}
Truth table100%2/2
A
A= $head->{"format"}
Aresult
11
00
Truth table0%0/2
A
A= $$head{"format"}
Aresult
11
00
264 0 ▶ $self->_refuse( 'format', 'format 1 (judge and rubric) is not read any more — format 2: end state and rules' )
Branch: 2 branches
BranchTrueFalseTotal
if $format eq 1 2 254 256
if $format eq 1 0 0 0
265 if $format eq '1';
266 0 ▶ $self->_refuse( 'format', 'only format 2 is known' ) unless $format eq '2';
Branch: 2 branches
BranchTrueFalseTotal
unless $format eq 2 4 250 254
unless $format eq 2 0 0 0
267 }
268 0 $self->_keys_ok( $head, 'suite.yaml', @SUITE_KEYS );
269 0 my %out;
270 0 ▶ if ( defined( my $t = $head->{threshold} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $t = $head->{"threshold"})) 57 251 308
if (defined(my $t = $$head{"threshold"})) 0 0 0
271 0 $self->_keys_ok( $t, 'threshold', qw( pass_rate pass_k ) );
272 0 ▶ $self->_refuse( 'threshold', 'pass_rate or pass_k (0..1) expected' ) unless exists $t->{pass_rate} || exists $t->{pass_k};
Branch: 2 branches
BranchTrueFalseTotal
unless exists $t->{"pass_rate"} or exists $t->{"pass_k"} 1 55 56
unless exists $$t{"pass_rate"} or exists $$t{"pass_k"} 0 0 0
Condition50%3/6
exists $t->{"pass_rate"} or exists $t->{"pass_k"}
l!l&&r!l&&!r
5321
exists $$t{"pass_rate"} or exists $$t{"pass_k"}
l!l&&r!l&&!r
000
MC/DC100%2/2
exists $t->{"pass_rate"} or exists $t->{"pass_k"}
exists $t->{"pass_rate"} exists $t->{"pass_k"}
MC/DC0%0/2
exists $$t{"pass_rate"} or exists $$t{"pass_k"}
exists $$t{"pass_rate"} exists $$t{"pass_k"}
Truth table100%3/3
A or B
A= exists $t->{"pass_rate"}B= exists $t->{"pass_k"}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= exists $$t{"pass_rate"}B= exists $$t{"pass_k"}
ABresult
1X1
011
000
273 0 $self->_num( $t->{$_}, 'threshold.'.$_, 0, 1 ) for grep { exists $t->{$_} } qw( pass_rate pass_k );
274 0 $out{threshold} = { map { $_ => 0 + $t->{$_} } grep { exists $t->{$_} } qw( pass_rate pass_k ) };
275 }
276 0 my $repeat = $head->{repeat};
277 0 ▶ $self->_refuse( 'repeat', 'integer 1..100 (runs per suite)' )
Branch: 2 branches
BranchTrueFalseTotal
if defined $repeat and ref $repeat || !($repeat =~ /\A[1-9]\d{0,2}\z/) || $repeat > 100 4 299 303
if defined $repeat and ref $repeat || !($repeat =~ /\A[1-9]\d{0,2}\z/) || $repeat > 100 0 0 0
Condition44%8/18
defined $repeat and ref $repeat || !($repeat =~ /\A[1-9]\d{0,2}\z/) || $repeat > 100
!ll&&!rl&&r
29364
ref $repeat or not $repeat =~ /\A[1-9]\d{0,2}\z/ or $repeat > 100
l!l&&r!l&&!r
316
ref $repeat or not $repeat =~ /\A[1-9]\d{0,2}\z/
l!l&&r!l&&!r
037
defined $repeat and ref $repeat || !($repeat =~ /\A[1-9]\d{0,2}\z/) || $repeat > 100
!ll&&!rl&&r
000
ref $repeat or not $repeat =~ /\A[1-9]\d{0,2}\z/ or $repeat > 100
l!l&&r!l&&!r
000
ref $repeat or not $repeat =~ /\A[1-9]\d{0,2}\z/
l!l&&r!l&&!r
000
MC/DC75%3/4
defined $repeat and ref $repeat || !($repeat =~ /\A[1-9]\d{0,2}\z/) || $repeat > 100
defined $repeat ref $repeat not $repeat =~ /\A[1-9]\d{0,2}\z/ $repeat > 100
MC/DC0%0/4
defined $repeat and ref $repeat || !($repeat =~ /\A[1-9]\d{0,2}\z/) || $repeat > 100
defined $repeat ref $repeat not $repeat =~ /\A[1-9]\d{0,2}\z/ $repeat > 100
Truth table80%4/5
A and B or not(C) or D
A= defined $repeatB= ref $repeatC= not $repeat =~ /\A[1-9]\d{0,2}\z/D= $repeat > 100
ABCDresult
0XXX0
10000
11XX1
101X1
10011
Truth table0%0/5
A and B or not(C) or D
A= defined $repeatB= ref $repeatC= not $repeat =~ /\A[1-9]\d{0,2}\z/D= $repeat > 100
ABCDresult
0XXX0
10000
11XX1
101X1
10011
278 if defined $repeat && ( ref $repeat || $repeat !~ /\A[1-9]\d{0,2}\z/ || $repeat > 100 );
279 0 ▶ $out{repeat} = 0 + $repeat if defined $repeat;
Branch: 2 branches
BranchTrueFalseTotal
if defined $repeat 6 293 299
if defined $repeat 0 0 0
280 0 ▶ if ( defined $head->{topic} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $head->{"topic"}) 67 232 299
if (defined $$head{"topic"}) 0 0 0
281 0 ▶ $self->_refuse( 'topic', 'topic as an id ([a-z0-9-])' ) unless $self->valid_id( $head->{topic} );
Branch: 2 branches
BranchTrueFalseTotal
unless $self->valid_id($head->{"topic"}) 0 67 67
unless $self->valid_id($$head{"topic"}) 0 0 0
282 0 $out{topic} = $head->{topic};
283 }
284 0 my @tools;
285 0 ▶ if ( defined $head->{tools} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $head->{"tools"}) 299 0 299
if (defined $$head{"tools"}) 0 0 0
286 0 my $l = $self->_list( $head->{tools}, 'suite.yaml: tools' );
287 0 my %seen;
288 0 for my $i ( 0 .. $#$l ) {
289 0 my $tool = $self->tool( $l->[$i], 'suite.yaml: tools['.$i.']' );
290 0 ▶ $self->_refuse( 'suite.yaml: tools', 'tool '.$tool->{name}.' twice' ) if $seen{ $tool->{name} }++;
Branch: 2 branches
BranchTrueFalseTotal
if $seen{$tool->{"name"}}++ 1 523 524
if $seen{$$tool{"name"}}++ 0 0 0
291 0 push @tools, $tool;
292 }
293 }
294 0 my $id = $head->{id};
295 0 ▶ if ( defined $o{dirname} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $o{'dirname'}) { } 281 10 291
if (defined $o{'dirname'}) { } 0 0 0
296 $self->_refuse( 'id', "must be '".$o{dirname}."' (the directory)" )
297 0 ▶ unless !ref $id && ( $id // '' ) eq $o{dirname} && $self->valid_id( $o{dirname} );
Branch: 2 branches
BranchTrueFalseTotal
unless not ref $id and ($id // "") eq $o{"dirname"} and $self->valid_id($o{"dirname"}) 2 279 281
unless not ref $id and ($id // "") eq $o{"dirname"} and $self->valid_id($o{"dirname"}) 0 0 0
Condition31%5/16
not ref $id and ($id // "") eq $o{"dirname"} and $self->valid_id($o{"dirname"})
!ll&&!rl&&r
20279
not ref $id and ($id // "") eq $o{"dirname"}
!ll&&!rl&&r
02279
$id // ""
l!l
2810
not ref $id and ($id // "") eq $o{"dirname"} and $self->valid_id($o{"dirname"})
!ll&&!rl&&r
000
not ref $id and ($id // "") eq $o{"dirname"}
!ll&&!rl&&r
000
$id // ""
l!l
00
MC/DC0%0/3
not ref $id and ($id // "") eq $o{"dirname"} and $self->valid_id($o{"dirname"})
not ref $id $id $self->valid_id($o{"dirname"})
MC/DC0%0/3
not ref $id and ($id // "") eq $o{"dirname"} and $self->valid_id($o{"dirname"})
not ref $id $id $self->valid_id($o{"dirname"})
Truth table25%1/4
not(A) and B and C
A= not ref $idB= $idC= $self->valid_id($o{"dirname"})
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
not(A) and B and C
A= not ref $idB= $idC= $self->valid_id($o{"dirname"})
ABCresult
0XX0
10X0
1100
1111
298 }
299 else {
300 0 ▶ $self->_refuse( 'id', 'invalid id' ) unless $self->valid_id($id);
Branch: 2 branches
BranchTrueFalseTotal
unless $self->valid_id($id) 0 10 10
unless $self->valid_id($id) 0 0 0
301 }
302 0 my $version = $head->{version};
303 0 ▶ $self->_refuse( 'version', 'integer >= 1' ) unless defined $version && !ref $version && $version =~ /\A[1-9]\d{0,5}\z/;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $version and not ref $version and $version =~ /\A[1-9]\d{0,5}\z/ 1 288 289
unless defined $version and not ref $version and $version =~ /\A[1-9]\d{0,5}\z/ 0 0 0
Condition33%4/12
defined $version and not ref $version and $version =~ /\A[1-9]\d{0,5}\z/
!ll&&!rl&&r
10288
defined $version and not ref $version
!ll&&!rl&&r
10288
defined $version and not ref $version and $version =~ /\A[1-9]\d{0,5}\z/
!ll&&!rl&&r
000
defined $version and not ref $version
!ll&&!rl&&r
000
MC/DC33%1/3
defined $version and not ref $version and $version =~ /\A[1-9]\d{0,5}\z/
defined $version not ref $version $version =~ /\A[1-9]\d{0,5}\z/
MC/DC0%0/3
defined $version and not ref $version and $version =~ /\A[1-9]\d{0,5}\z/
defined $version not ref $version $version =~ /\A[1-9]\d{0,5}\z/
Truth table50%2/4
A and not(B) and C
A= defined $versionB= not ref $versionC= $version =~ /\A[1-9]\d{0,5}\z/
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and not(B) and C
A= defined $versionB= not ref $versionC= $version =~ /\A[1-9]\d{0,5}\z/
ABCresult
0XX0
10X0
1100
1111
304 0 ▶ my $defaults = $head->{defaults} // {};
Condition50%2/4
$head->{"defaults"} // {}
l!l
65223
$$head{"defaults"} // {}
l!l
00
MC/DC100%1/1
$head->{"defaults"} // {}
$head->{"defaults"}
MC/DC0%0/1
$$head{"defaults"} // {}
$$head{"defaults"}
Truth table100%2/2
A
A= $head->{"defaults"}
Aresult
11
00
Truth table0%0/2
A
A= $$head{"defaults"}
Aresult
11
00
305 0 $self->_keys_ok( $defaults, 'defaults', qw( system temperature max_tokens max_turns ) );
306 0 $self->_text( $head->{title}, 'title' );
307 0 $self->_text( $head->{$_}, $_, 1 ) for qw( description license );
308 0 $self->_source( $head->{source}, 'source' );
309 return (
310 %out,
311 id => $id,
312 version => 0 + $version,
313 title => $head->{title},
314 defaults => $defaults,
315 tools => \@tools,
316 0 ▶ ( map { defined $head->{$_} ? ( $_ => $head->{$_} ) : () } qw( description license source ) ),
Branch: 2 branches
BranchTrueFalseTotal
defined $head->{$_} ? : 135 729 864
defined $$head{$_} ? : 0 0 0
317 );
318 }
319  
320  
321 627 ▶sub _source {
Subroutine _source: called CC=3 SCAR=14.2
322 0 ▶ my ( $self, $src, $field ) = @_;
Subroutine _source: not called CC=3 SCAR=14.2
323 0 ▶ return unless defined $src;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $src 581 46 627
unless defined $src 0 0 0
324 0 $self->_keys_ok( $src, $field, qw( title authors license url location ) );
325 0 $self->_text( $src->{title}, $field.'.title' );
326 0 $self->_text( $src->{$_}, $field.'.'.$_, 1 ) for qw( authors license url location );
327 0 return $src;
328 }
329  
330 #### Generated content
331  
332 403 ▶sub generated {
Subroutine generated: called CC=11 SCAR=34.8
Pod documented
333 0 ▶ my ( $self, $data, $f, %o ) = @_;
Subroutine generated: not called CC=11 SCAR=34.8
Pod documented
334 0 my @out;
335 0 ▶ return @out unless ref $data eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $data eq "HASH" 0 403 403
unless ref $data eq "HASH" 0 0 0
336 449 ▶ my $put = sub {
Subroutine __ANON__: called CC=3 SCAR=14.2
337 0 ▶ my ( $v, $field ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=14.2
338 0 ▶ return unless ref $v eq 'HASH' || ref $v eq 'ARRAY';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $v eq "HASH" or ref $v eq "ARRAY" 414 35 449
unless ref $v eq "HASH" or ref $v eq "ARRAY" 0 0 0
Condition50%3/6
ref $v eq "HASH" or ref $v eq "ARRAY"
l!l&&r!l&&!r
134414
ref $v eq "HASH" or ref $v eq "ARRAY"
l!l&&r!l&&!r
000
MC/DC100%2/2
ref $v eq "HASH" or ref $v eq "ARRAY"
ref $v eq "HASH" ref $v eq "ARRAY"
MC/DC0%0/2
ref $v eq "HASH" or ref $v eq "ARRAY"
ref $v eq "HASH" ref $v eq "ARRAY"
Truth table100%3/3
A or B
A= ref $v eq "HASH"B= ref $v eq "ARRAY"
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= ref $v eq "HASH"B= ref $v eq "ARRAY"
ABresult
1X1
011
000
339 0 push @out, [ $field, $self->haystack->resolve( $v, $field ) ];
340 0 };
341 0 ▶ if ( ref $data->{messages} eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $data->{"messages"} eq "ARRAY") 403 0 403
if (ref $$data{"messages"} eq "ARRAY") 0 0 0
342 0 my $i = 0;
343 0 for my $m ( @{ $data->{messages} } ) {
344 0 my $field = $f.': messages['.$i.'].content';
345 0 ▶ $put->( $self->excerpt->expand( $m->{content}, $field, $o{dir} ), $field ) if ref $m eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
if ref $m eq "HASH" 451 0 451
if ref $m eq "HASH" 0 0 0
346 0 $i++;
347 }
348 }
349 0 ▶ return @out unless ref $data->{state} eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $data->{"state"} eq "HASH" 0 400 400
unless ref $$data{"state"} eq "HASH" 0 0 0
350 0 for my $dev ( sort keys %{ $data->{state} } ) {
351 0 ▶ my $files = ref $data->{state}{$dev} eq 'HASH' ? $data->{state}{$dev}{files} : undef;
Branch: 2 branches
BranchTrueFalseTotal
ref $data->{'state'}{$dev} eq 'HASH' ? : 340 106 446
ref $$data{'state'}{$dev} eq 'HASH' ? : 0 0 0
352 0 ▶ next unless ref $files eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $files eq "HASH" 406 40 446
unless ref $files eq "HASH" 0 0 0
353 0 for my $p ( sort keys %$files ) {
354 0 ▶ $put->( $files->{$p}{content}, $f.': state.'.$dev.'.files.'.$p.'.content' ) if ref $files->{$p} eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
if ref $files->{$p} eq "HASH" 0 40 40
if ref $$files{$p} eq "HASH" 0 0 0
355 }
356 }
357 0 return @out;
358 }
359  
360  
361 #### Cases
362  
363 412 ▶sub case {
Subroutine case: called CC=52 SCAR=62.1
Pod documented
364 0 ▶ my ( $self, $data, %o ) = @_;
Subroutine case: not called CC=52 SCAR=62.1
Pod documented
365 0 ▶ my $f = defined $o{file} ? 'cases/'.$o{file} : $o{field} // 'case';
Branch: 2 branches
BranchTrueFalseTotal
defined $o{'file'} ? : 285 127 412
defined $o{'file'} ? : 0 0 0
Condition50%2/4
$o{"field"} // "case"
l!l
1261
$o{"field"} // "case"
l!l
00
MC/DC100%1/1
$o{"field"} // "case"
$o{"field"}
MC/DC0%0/1
$o{"field"} // "case"
$o{"field"}
Truth table100%2/2
A
A= $o{"field"}
Aresult
11
00
Truth table0%0/2
A
A= $o{"field"}
Aresult
11
00
366 0 $self->_keys_ok( $data, $f, @CASE_KEYS );
367 0 ▶ my $id = $data->{id} // '';
Condition25%1/4
$data->{"id"} // ""
l!l
4090
$$data{"id"} // ""
l!l
00
MC/DC0%0/1
$data->{"id"} // ""
$data->{"id"}
MC/DC0%0/1
$$data{"id"} // ""
$$data{"id"}
Truth table50%1/2
A
A= $data->{"id"}
Aresult
11
00
Truth table0%0/2
A
A= $$data{"id"}
Aresult
11
00
368 0 ▶ if ( defined $o{file} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $o{"file"}) 282 127 409
if (defined $o{"file"}) 0 0 0
369 0 ( my $want = $o{file} ) =~ s/\.yaml\z//;
370 0 ▶ $self->_refuse( $f.': id', "must be '".$want."' (the file name)" ) unless !ref $id && $id eq $want;
Branch: 2 branches
BranchTrueFalseTotal
unless not ref $id and $id eq $want 1 281 282
unless not ref $id and $id eq $want 0 0 0
Condition33%2/6
not ref $id and $id eq $want
!ll&&!rl&&r
01281
not ref $id and $id eq $want
!ll&&!rl&&r
000
MC/DC50%1/2
not ref $id and $id eq $want
not ref $id $id eq $want
MC/DC0%0/2
not ref $id and $id eq $want
not ref $id $id eq $want
Truth table66%2/3
not(A) and B
A= not ref $idB= $id eq $want
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not ref $idB= $id eq $want
ABresult
0X0
100
111
371 }
372 0 ▶ $self->_refuse( $f.': id', 'invalid id' ) unless $self->valid_id($id);
Branch: 2 branches
BranchTrueFalseTotal
unless $self->valid_id($id) 0 408 408
unless $self->valid_id($id) 0 0 0
373  
374 # messages
375 0 ▶ $self->_refuse( $f.': messages', 'list missing' ) unless ref $data->{messages} eq 'ARRAY' && @{ $data->{messages} };
Branch: 2 branches
BranchTrueFalseTotal
unless ref $data->{"messages"} eq "ARRAY" and @{$data->{"messages"};} 0 408 408
unless ref $$data{"messages"} eq "ARRAY" and @{$$data{"messages"};} 0 0 0
Condition16%1/6
ref $data->{"messages"} eq "ARRAY" and @{$data->{"messages"};}
!ll&&!rl&&r
00408
ref $$data{"messages"} eq "ARRAY" and @{$$data{"messages"};}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $data->{"messages"} eq "ARRAY" and @{$data->{"messages"};}
ref $data->{"messages"} eq "ARRAY" @{$data->{"messages"};}
MC/DC0%0/2
ref $$data{"messages"} eq "ARRAY" and @{$$data{"messages"};}
ref $$data{"messages"} eq "ARRAY" @{$$data{"messages"};}
Truth table33%1/3
A and B
A= ref $data->{"messages"} eq "ARRAY"B= @{$data->{"messages"};}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $$data{"messages"} eq "ARRAY"B= @{$$data{"messages"};}
ABresult
0X0
100
111
376 0 my ( @prompt, %images );
377 0 my $i = 0;
378 0 for my $m ( @{ $data->{messages} } ) {
379 0 my $mf = $f.': messages['.$i.']';
380 0 $self->_keys_ok( $m, $mf, qw( role content untrusted images ) );
381 0 $self->_flag( $m->{untrusted}, $mf.'.untrusted' );
382 0 ▶ my $role = $m->{role} // '';
Condition25%1/4
$m->{"role"} // ""
l!l
4550
$$m{"role"} // ""
l!l
00
MC/DC0%0/1
$m->{"role"} // ""
$m->{"role"}
MC/DC0%0/1
$$m{"role"} // ""
$$m{"role"}
Truth table50%1/2
A
A= $m->{"role"}
Aresult
11
00
Truth table0%0/2
A
A= $$m{"role"}
Aresult
11
00
383 0 ▶ $self->_refuse( $mf.'.role', 'user or assistant (the system prompt goes under system:)' )
Branch: 2 branches
BranchTrueFalseTotal
unless $role eq "user" or $role eq "assistant" 1 454 455
unless $role eq "user" or $role eq "assistant" 0 0 0
Condition50%3/6
$role eq "user" or $role eq "assistant"
l!l&&r!l&&!r
430241
$role eq "user" or $role eq "assistant"
l!l&&r!l&&!r
000
MC/DC100%2/2
$role eq "user" or $role eq "assistant"
$role eq "user" $role eq "assistant"
MC/DC0%0/2
$role eq "user" or $role eq "assistant"
$role eq "user" $role eq "assistant"
Truth table100%3/3
A or B
A= $role eq "user"B= $role eq "assistant"
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $role eq "user"B= $role eq "assistant"
ABresult
1X1
011
000
384 unless $role eq 'user' || $role eq 'assistant';
385 0 my $content = $self->excerpt->expand( $m->{content}, $mf.'.content', $o{dir} );
386 0 ▶ $content = $self->haystack->resolve( $content, $mf.'.content' ) if ref $content;
Branch: 2 branches
BranchTrueFalseTotal
if ref $content 35 418 453
if ref $content 0 0 0
387 0 $content = $self->_text( $content, $mf.'.content' );
388 0 ▶ if ( exists $m->{images} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $m->{"images"}) 53 399 452
if (exists $$m{"images"}) 0 0 0
389 0 ▶ $self->_refuse( $mf.'.images', 'only on a user message' ) unless $role eq 'user';
Branch: 2 branches
BranchTrueFalseTotal
unless $role eq "user" 1 52 53
unless $role eq "user" 0 0 0
390 0 my @parts = map { $self->_image( $_, $o{dir}, \%images ) } $self->_image_list( $m->{images}, $mf.'.images' );
391 0 $content = [ { type => 'text', text => $content }, @parts ];
392 }
393 0 push @prompt, { role => $role, content => $content };
394 0 $i++;
395 }
396 0 ▶ $self->_refuse( $f.': messages', 'the last message must be from the user' ) unless $prompt[-1]{role} eq 'user';
Branch: 2 branches
BranchTrueFalseTotal
unless $prompt[-1]{"role"} eq "user" 1 388 389
unless $prompt[-1]{"role"} eq "user" 0 0 0
397  
398 # state, prepared once to check it
399 0 my $initial = $self->_state( $data->{state}, $f.': state' );
400  
401 0 ▶ my @tools = sort { $a->{name} cmp $b->{name} } @{ $o{tools} || [] };
Condition25%1/4
$o{'tools'} || []
l!l
3790
$o{'tools'} || []
l!l
00
MC/DC0%0/1
$o{'tools'} || []
$o{'tools'}
MC/DC0%0/1
$o{'tools'} || []
$o{'tools'}
Truth table50%1/2
A
A= $o{'tools'}
Aresult
11
00
Truth table0%0/2
A
A= $o{'tools'}
Aresult
11
00
402 0 ▶ $self->_refuse( $f.': tools', 'the suite offers no tools (suite.yaml: tools)' ) unless @tools;
Branch: 2 branches
BranchTrueFalseTotal
unless @tools 0 379 379
unless @tools 0 0 0
403 0 my %tools = map { $_->{name} => 1 } @tools;
404  
405 0 ▶ my $ol = $self->_list( $data->{observe} // [], $f.': observe' );
Condition50%2/4
$data->{"observe"} // []
l!l
8371
$$data{"observe"} // []
l!l
00
MC/DC100%1/1
$data->{"observe"} // []
$data->{"observe"}
MC/DC0%0/1
$$data{"observe"} // []
$$data{"observe"}
Truth table100%2/2
A
A= $data->{"observe"}
Aresult
11
00
Truth table0%0/2
A
A= $$data{"observe"}
Aresult
11
00
406 0 $self->_observe( $ol->[$_], $f.': observe['.$_.']' ) for 0 .. $#$ol;
407  
408 0 my $rl = $self->_list( $data->{rules}, $f.': rules', 1 );
409 0 my @kinds = map { $self->_rule( $rl->[$_], $f.': rules['.$_.']', \%tools, $data->{state} ) } 0 .. $#$rl;
410 0 my @required = map { $kinds[$_] } grep { _required( $rl->[$_] ) } 0 .. $#$rl;
411 0 ▶ $self->_refuse( $f.': rules', 'at least one required rule' ) unless @required;
Branch: 2 branches
BranchTrueFalseTotal
unless @required 0 349 349
unless @required 0 0 0
412 # the "no tool" family: doing nothing is right. An empty solution only with the
413 # required rule only_tools: [] — then lint checks that every wrong solution fails.
414 0 ▶ my $nothing = ref $data->{solution} eq 'ARRAY' && !@{ $data->{solution} };
Condition33%2/6
ref $data->{'solution'} eq 'ARRAY' && !@{$data->{'solution'};}
!ll&&!rl&&r
03436
ref $$data{'solution'} eq 'ARRAY' && !@{$$data{'solution'};}
!ll&&!rl&&r
000
MC/DC50%1/2
ref $data->{'solution'} eq 'ARRAY' && !@{$data->{'solution'};}
ref $data->{'solution'} eq 'ARRAY' !@{$data->{'solution'};}
MC/DC0%0/2
ref $$data{'solution'} eq 'ARRAY' && !@{$$data{'solution'};}
ref $$data{'solution'} eq 'ARRAY' !@{$$data{'solution'};}
Truth table66%2/3
A && not(B)
A= ref $data->{'solution'} eq 'ARRAY'B= !@{$data->{'solution'};}
ABresult
0X0
100
111
Truth table0%0/3
A && not(B)
A= ref $$data{'solution'} eq 'ARRAY'B= !@{$$data{'solution'};}
ABresult
0X0
100
111
415 $self->_refuse( $f.': solution', 'empty only with the required rule only_tools: [] (the "no tool" family)' )
416 0 ▶ if $nothing && !grep { _required( $_ ) && exists $_->{only_tools} && ref $_->{only_tools} eq 'ARRAY' && !@{ $_->{only_tools} } } @$rl;
Branch: 2 branches
BranchTrueFalseTotal
if $nothing and not grep({_required($_) and exists $_->{"only_tools"} and ref $_->{"only_tools"} eq "ARRAY" and not @{$_->{"only_tools"};};} @$rl) 2 347 349
if $nothing and not grep({_required($_) and exists $$_{"only_tools"} and ref $$_{"only_tools"} eq "ARRAY" and not @{$$_{"only_tools"};};} @$rl) 0 0 0
Condition41%10/24
$nothing and not grep({_required($_) and exists $_->{"only_tools"} and ref $_->{"only_tools"} eq "ARRAY" and not @{$_->{"only_tools"};};} @$rl)
!ll&&!rl&&r
34342
_required($_) && exists $_->{'only_tools'} && ref $_->{'only_tools'} eq 'ARRAY' && !@{$_->{'only_tools'};}
!ll&&!rl&&r
124
_required($_) and exists $_->{"only_tools"} and ref $_->{"only_tools"} eq "ARRAY"
!ll&&!rl&&r
106
_required($_) and exists $_->{"only_tools"}
!ll&&!rl&&r
106
$nothing and not grep({_required($_) and exists $$_{"only_tools"} and ref $$_{"only_tools"} eq "ARRAY" and not @{$$_{"only_tools"};};} @$rl)
!ll&&!rl&&r
000
_required($_) && exists $$_{'only_tools'} && ref $$_{'only_tools'} eq 'ARRAY' && !@{$$_{'only_tools'};}
!ll&&!rl&&r
000
_required($_) and exists $$_{"only_tools"} and ref $$_{"only_tools"} eq "ARRAY"
!ll&&!rl&&r
000
_required($_) and exists $$_{"only_tools"}
!ll&&!rl&&r
000
MC/DC100%2/2
$nothing and not grep({_required($_) and exists $_->{"only_tools"} and ref $_->{"only_tools"} eq "ARRAY" and not @{$_->{"only_tools"};};} @$rl)
$nothing not grep({_required($_) and exists $_->{"only_tools"} and ref $_->{"only_tools"} eq "ARRAY" and not @{$_->{"only_tools"};};} @$rl)
MC/DC50%2/4
_required($_) && exists $_->{'only_tools'} && ref $_->{'only_tools'} eq 'ARRAY' && !@{$_->{'only_tools'};}
_required($_) exists $_->{"only_tools"} ref $_->{"only_tools"} eq "ARRAY" !@{$_->{'only_tools'};}
MC/DC0%0/2
$nothing and not grep({_required($_) and exists $$_{"only_tools"} and ref $$_{"only_tools"} eq "ARRAY" and not @{$$_{"only_tools"};};} @$rl)
$nothing not grep({_required($_) and exists $$_{"only_tools"} and ref $$_{"only_tools"} eq "ARRAY" and not @{$$_{"only_tools"};};} @$rl)
MC/DC0%0/4
_required($_) && exists $$_{'only_tools'} && ref $$_{'only_tools'} eq 'ARRAY' && !@{$$_{'only_tools'};}
_required($_) exists $$_{"only_tools"} ref $$_{"only_tools"} eq "ARRAY" !@{$$_{'only_tools'};}
Truth table100%3/3
A and not(B)
A= $nothingB= not grep({_required($_) and exists $_->{"only_tools"} and ref $_->{"only_tools"} eq "ARRAY" and not @{$_->{"only_tools"};};} @$rl)
ABresult
0X0
100
111
Truth table60%3/5
A and B and C && not(D)
A= _required($_)B= exists $_->{"only_tools"}C= ref $_->{"only_tools"} eq "ARRAY"D= !@{$_->{'only_tools'};}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/3
A and not(B)
A= $nothingB= not grep({_required($_) and exists $$_{"only_tools"} and ref $$_{"only_tools"} eq "ARRAY" and not @{$$_{"only_tools"};};} @$rl)
ABresult
0X0
100
111
Truth table0%0/5
A and B and C && not(D)
A= _required($_)B= exists $$_{"only_tools"}C= ref $$_{"only_tools"} eq "ARRAY"D= !@{$$_{'only_tools'};}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
417 # a check command runs on the end state and so checks it too
418 $self->_refuse( $f.': rules', 'at least one required rule on the end state (state, check, packet or login)' )
419 0 ▶ unless $nothing || grep { /\A(?:state|check|packet|login)\z/ } @required;
Branch: 2 branches
BranchTrueFalseTotal
unless $nothing or grep {/\A(?:state|check|packet|login)\z/;} @required 1 346 347
unless $nothing or grep {/\A(?:state|check|packet|login)\z/;} @required 0 0 0
Condition50%3/6
$nothing or grep {/\A(?:state|check|packet|login)\z/;} @required
l!l&&r!l&&!r
43421
$nothing or grep {/\A(?:state|check|packet|login)\z/;} @required
l!l&&r!l&&!r
000
MC/DC100%2/2
$nothing or grep {/\A(?:state|check|packet|login)\z/;} @required
$nothing grep {/\A(?:state|check|packet|login)\z/;} @required
MC/DC0%0/2
$nothing or grep {/\A(?:state|check|packet|login)\z/;} @required
$nothing grep {/\A(?:state|check|packet|login)\z/;} @required
Truth table100%3/3
A or B
A= $nothingB= grep {/\A(?:state|check|packet|login)\z/;} @required
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $nothingB= grep {/\A(?:state|check|packet|login)\z/;} @required
ABresult
1X1
011
000
420  
421 0 for my $k (qw( alternatives wrong_solutions )) {
422 0 ▶ next if $nothing && $k eq 'alternatives' && !exists $data->{$k};
Branch: 2 branches
BranchTrueFalseTotal
if $nothing and $k eq "alternatives" and not exists $data->{$k} 4 687 691
if $nothing and $k eq "alternatives" and not exists $$data{$k} 0 0 0
Condition41%5/12
$nothing and $k eq "alternatives" and not exists $data->{$k}
!ll&&!rl&&r
68704
$nothing and $k eq "alternatives"
!ll&&!rl&&r
68344
$nothing and $k eq "alternatives" and not exists $$data{$k}
!ll&&!rl&&r
000
$nothing and $k eq "alternatives"
!ll&&!rl&&r
000
MC/DC66%2/3
$nothing and $k eq "alternatives" and not exists $data->{$k}
$nothing $k eq "alternatives" not exists $data->{$k}
MC/DC0%0/3
$nothing and $k eq "alternatives" and not exists $$data{$k}
$nothing $k eq "alternatives" not exists $$data{$k}
Truth table75%3/4
A and B and not(C)
A= $nothingB= $k eq "alternatives"C= not exists $data->{$k}
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and not(C)
A= $nothingB= $k eq "alternatives"C= not exists $$data{$k}
ABCresult
0XX0
10X0
1100
1111
423 0 my $wl = $self->_list( $data->{$k}, $f.': '.$k, 1 );
424 0 for my $j ( 0 .. $#$wl ) {
425 0 my $wf = $f.': '.$k.'['.$j.']';
426 0 $self->_keys_ok( $wl->[$j], $wf, qw( title calls ) );
427 0 $self->_text( $wl->[$j]{title}, $wf.'.title' );
428 0 $self->_calls( $wl->[$j]{calls}, $wf.'.calls', \%tools );
429 }
430 }
431  
432 0 ▶ my $tags = $data->{tags} // [];
Condition50%2/4
$data->{"tags"} // []
l!l
22322
$$data{"tags"} // []
l!l
00
MC/DC100%1/1
$data->{"tags"} // []
$data->{"tags"}
MC/DC0%0/1
$$data{"tags"} // []
$$data{"tags"}
Truth table100%2/2
A
A= $data->{"tags"}
Aresult
11
00
Truth table0%0/2
A
A= $$data{"tags"}
Aresult
11
00
433 0 ▶ $self->_refuse( $f.': tags', 'not a list of texts' ) unless ref $tags eq 'ARRAY' && !grep { ref } @$tags;
Branch: 2 branches
BranchTrueFalseTotal
unless ref $tags eq "ARRAY" and not grep({ref $_;} @$tags) 0 344 344
unless ref $tags eq "ARRAY" and not grep({ref $_;} @$tags) 0 0 0
Condition16%1/6
ref $tags eq "ARRAY" and not grep({ref $_;} @$tags)
!ll&&!rl&&r
00344
ref $tags eq "ARRAY" and not grep({ref $_;} @$tags)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $tags eq "ARRAY" and not grep({ref $_;} @$tags)
ref $tags eq "ARRAY" not grep({ref $_;} @$tags)
MC/DC0%0/2
ref $tags eq "ARRAY" and not grep({ref $_;} @$tags)
ref $tags eq "ARRAY" not grep({ref $_;} @$tags)
Truth table33%1/3
A and not(B)
A= ref $tags eq "ARRAY"B= not grep({ref $_;} @$tags)
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= ref $tags eq "ARRAY"B= not grep({ref $_;} @$tags)
ABresult
0X0
100
111
434 0 my $difficulty = $data->{difficulty};
435 $self->_refuse( $f.': difficulty', 'leicht, mittel or schwer' )
436 0 ▶ if defined $difficulty && !grep { $difficulty eq $_ } qw( leicht mittel schwer );
Branch: 2 branches
BranchTrueFalseTotal
if defined $difficulty and not grep({$difficulty eq $_;} "leicht", "mittel", "schwer") 1 343 344
if defined $difficulty and not grep({$difficulty eq $_;} "leicht", "mittel", "schwer") 0 0 0
Condition50%3/6
defined $difficulty and not grep({$difficulty eq $_;} "leicht", "mittel", "schwer")
!ll&&!rl&&r
286571
defined $difficulty and not grep({$difficulty eq $_;} "leicht", "mittel", "schwer")
!ll&&!rl&&r
000
MC/DC100%2/2
defined $difficulty and not grep({$difficulty eq $_;} "leicht", "mittel", "schwer")
defined $difficulty not grep({$difficulty eq $_;} "leicht", "mittel", "schwer")
MC/DC0%0/2
defined $difficulty and not grep({$difficulty eq $_;} "leicht", "mittel", "schwer")
defined $difficulty not grep({$difficulty eq $_;} "leicht", "mittel", "schwer")
Truth table100%3/3
A and not(B)
A= defined $difficultyB= not grep({$difficulty eq $_;} "leicht", "mittel", "schwer")
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= defined $difficultyB= not grep({$difficulty eq $_;} "leicht", "mittel", "schwer")
ABresult
0X0
100
111
437  
438 0 ▶ my $defaults = $o{defaults} || {};
Condition25%1/4
$o{'defaults'} || {}
l!l
3430
$o{'defaults'} || {}
l!l
00
MC/DC0%0/1
$o{'defaults'} || {}
$o{'defaults'}
MC/DC0%0/1
$o{'defaults'} || {}
$o{'defaults'}
Truth table50%1/2
A
A= $o{'defaults'}
Aresult
11
00
Truth table0%0/2
A
A= $o{'defaults'}
Aresult
11
00
439 0 my %range = ( temperature => [ 0, 2 ], max_tokens => [ 1, 200_000 ], max_turns => [ 1, 50 ] );
440 0 for my $k ( sort keys %range ) {
441 0 ▶ next unless exists $data->{$k} || exists $defaults->{$k};
Branch: 2 branches
BranchTrueFalseTotal
unless exists $data->{$k} or exists $defaults->{$k} 839 189 1028
unless exists $$data{$k} or exists $$defaults{$k} 0 0 0
Condition50%3/6
exists $data->{$k} or exists $defaults->{$k}
l!l&&r!l&&!r
6183839
exists $$data{$k} or exists $$defaults{$k}
l!l&&r!l&&!r
000
MC/DC100%2/2
exists $data->{$k} or exists $defaults->{$k}
exists $data->{$k} exists $defaults->{$k}
MC/DC0%0/2
exists $$data{$k} or exists $$defaults{$k}
exists $$data{$k} exists $$defaults{$k}
Truth table100%3/3
A or B
A= exists $data->{$k}B= exists $defaults->{$k}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= exists $$data{$k}B= exists $$defaults{$k}
ABresult
1X1
011
000
442 0 ▶ $self->_num( exists $data->{$k} ? $data->{$k} : $defaults->{$k}, $f.': '.$k, @{ $range{$k} } );
Branch: 2 branches
BranchTrueFalseTotal
exists $data->{$k} ? : 6 183 189
exists $$data{$k} ? : 0 0 0
443 }
444 0 ▶ $self->_num( $data->{weight}, $f.': weight', 0 ) if exists $data->{weight};
Branch: 2 branches
BranchTrueFalseTotal
if exists $data->{"weight"} 19 322 341
if exists $$data{"weight"} 0 0 0
445 0 ▶ $self->_refuse( $f.': weight', 'a positive number' ) if exists $data->{weight} && $data->{weight} <= 0;
Branch: 2 branches
BranchTrueFalseTotal
if exists $data->{"weight"} and $data->{"weight"} <= 0 1 340 341
if exists $$data{"weight"} and $$data{"weight"} <= 0 0 0 0
Condition50%3/6
exists $data->{"weight"} and $data->{"weight"} <= 0
!ll&&!rl&&r
322181
exists $$data{"weight"} and $$data{"weight"} <= 0
!ll&&!rl&&r
000
MC/DC100%2/2
exists $data->{"weight"} and $data->{"weight"} <= 0
exists $data->{"weight"} $data->{"weight"} <= 0
MC/DC0%0/2
exists $$data{"weight"} and $$data{"weight"} <= 0
exists $$data{"weight"} $$data{"weight"} <= 0
Truth table100%3/3
A and B
A= exists $data->{"weight"}B= $data->{"weight"} <= 0
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= exists $$data{"weight"}B= $$data{"weight"} <= 0
ABresult
0X0
100
111
446 0 $self->_text( $data->{title}, $f.': title' );
447 0 ▶ $self->_text( $data->{system} // $defaults->{system}, $f.': system', 1 );
Condition50%3/6
$data->{"system"} // $defaults->{"system"}
l!l&&r!l&&!r
1159180
$$data{"system"} // $$defaults{"system"}
l!l&&r!l&&!r
000
MC/DC100%2/2
$data->{"system"} // $defaults->{"system"}
$data->{"system"} $defaults->{"system"}
MC/DC0%0/2
$$data{"system"} // $$defaults{"system"}
$$data{"system"} $$defaults{"system"}
Truth table100%3/3
A // B
A= $data->{"system"}B= $defaults->{"system"}
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $$data{"system"}B= $$defaults{"system"}
ABresult
1X1
011
000
448 0 ▶ $self->_calls( $data->{solution}, $f.': solution', \%tools ) unless $nothing;
Branch: 2 branches
BranchTrueFalseTotal
unless $nothing 337 3 340
unless $nothing 0 0 0
449 0 $self->_source( $data->{source}, $f.': source' );
450  
451 return Langertha::Holmgang::Case->new(
452 0 ▶ ( map { exists $data->{$_} ? ( $_ => $data->{$_} ) : () } @CASE_KEYS ),
Branch: 2 branches
BranchTrueFalseTotal
exists $data->{$_} ? : 2819 2944 5763
exists $$data{$_} ? : 0 0 0
453 tools => \@tools,
454 defaults => $defaults,
455 simulators => $self->simulators,
456 haystack => $self->haystack,
457 initial_state => $initial,
458 prompt_messages => \@prompt,
459 image_files => \%images,
460 );
461 }
462  
463  
464 #### Images (k27)
465  
466 52 ▶sub _image_list {
Subroutine _image_list: called CC=2 SCAR=9.2
467 0 ▶ my ( $self, $v, $field ) = @_;
Subroutine _image_list: not called CC=2 SCAR=9.2
468 0 $self->_list( $v, $field, 1 );
469 0 ▶ $self->_refuse( $field, 'at most '.$IMAGES_PER_MESSAGE.' images per message' ) if @$v > $IMAGES_PER_MESSAGE;
Branch: 2 branches
BranchTrueFalseTotal
if @$v > $Langertha::Holmgang::Structure::IMAGES_PER_MESSAGE 1 50 51
if @$v > $Langertha::Holmgang::Structure::IMAGES_PER_MESSAGE 0 0 0
470 0 return map { [ $v->[$_], $field.'['.$_.']' ] } 0 .. $#$v;
471 }
472  
473 # one image of a user message: checked, measured, recorded in %$seen by its
474 # file; returns the placeholder that stands for it in the prompt messages
475 69 ▶sub _image {
Subroutine _image: called CC=2 SCAR=9.8
476 0 ▶ my ( $self, $entry, $dir, $seen ) = @_;
Subroutine _image: not called CC=2 SCAR=9.8
477 0 my ( $img, $field ) = @$entry;
478 0 $self->_keys_ok( $img, $field, qw( file untrusted ) );
479 0 $self->_flag( $img->{untrusted}, $field.'.untrusted' );
480 0 my $file = $self->_text( $img->{file}, $field.'.file' );
481 0 ▶ my $info = $seen->{$file} //= $self->image_file( $dir, $file, $field.'.file' );
Condition33%2/6
$seen->{$file} //= $self->image_file($dir, $file, $field . '.file')
l!l&&r!l&&!r
17500
$$seen{$file} //= $self->image_file($dir, $file, $field . '.file')
l!l&&r!l&&!r
000
MC/DC0%0/2
$seen->{$file} //= $self->image_file($dir, $file, $field . '.file')
$seen->{$file} $self->image_file($dir, $file, $field . '.file')
MC/DC0%0/2
$$seen{$file} //= $self->image_file($dir, $file, $field . '.file')
$$seen{$file} $self->image_file($dir, $file, $field . '.file')
Truth table66%2/3
A //= B
A= $seen->{$file}B= $self->image_file($dir, $file, $field . '.file')
ABresult
1X1
011
000
Truth table0%0/3
A //= B
A= $$seen{$file}B= $self->image_file($dir, $file, $field . '.file')
ABresult
1X1
011
000
482 0 return { image => $file, sha256 => $info->{sha256}, bytes => $info->{bytes} };
483 }
484  
485 50 ▶sub image_file {
Subroutine image_file: called CC=19 SCAR=44.8
Pod documented
486 0 ▶ my ( $self, $dir, $file, $field ) = @_;
Subroutine image_file: not called CC=19 SCAR=44.8
Pod documented
487 0 ▶ $field //= 'image';
Condition25%1/4
$field //= "image"
l!l
500
$field //= "image"
l!l
00
MC/DC0%0/1
$field //= "image"
$field
MC/DC0%0/1
$field //= "image"
$field
Truth table50%1/2
A
A= $field
Aresult
11
00
Truth table0%0/2
A
A= $field
Aresult
11
00
488 0 ▶ $self->_refuse( $field, 'an image needs the suite directory to be read from' ) unless defined $dir && length $dir;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $dir and length $dir 1 49 50
unless defined $dir and length $dir 0 0 0
Condition33%2/6
defined $dir and length $dir
!ll&&!rl&&r
1049
defined $dir and length $dir
!ll&&!rl&&r
000
MC/DC50%1/2
defined $dir and length $dir
defined $dir length $dir
MC/DC0%0/2
defined $dir and length $dir
defined $dir length $dir
Truth table66%2/3
A and B
A= defined $dirB= length $dir
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $dirB= length $dir
ABresult
0X0
100
111
489 $self->_refuse( $field, 'a path relative to the suite directory, without .. or an empty segment' )
490 0 ▶ if $file =~ m{\A/|\\} || grep { $_ eq '..' || $_ eq '' } split m{/}, $file, -1;
Branch: 2 branches
BranchTrueFalseTotal
if $file =~ m[\A/|\\] or grep {$_ eq ".." or $_ eq "";} split(m[/], $file, -1) 2 47 49
if $file =~ m[\A/|\\] or grep {$_ eq ".." or $_ eq "";} split(m[/], $file, -1) 0 0 0
Condition41%5/12
$file =~ m[\A/|\\] or grep {$_ eq ".." or $_ eq "";} split(m[/], $file, -1)
l!l&&r!l&&!r
1147
$_ eq '..' || $_ eq ''
l!l&&r!l&&!r
2092
$file =~ m[\A/|\\] or grep {$_ eq ".." or $_ eq "";} split(m[/], $file, -1)
l!l&&r!l&&!r
000
$_ eq '..' || $_ eq ''
l!l&&r!l&&!r
000
MC/DC100%2/2
$file =~ m[\A/|\\] or grep {$_ eq ".." or $_ eq "";} split(m[/], $file, -1)
$file =~ m[\A/|\\] grep {$_ eq ".." or $_ eq "";} split(m[/], $file, -1)
MC/DC50%1/2
$_ eq '..' || $_ eq ''
$_ eq '..' $_ eq ''
MC/DC0%0/2
$file =~ m[\A/|\\] or grep {$_ eq ".." or $_ eq "";} split(m[/], $file, -1)
$file =~ m[\A/|\\] grep {$_ eq ".." or $_ eq "";} split(m[/], $file, -1)
MC/DC0%0/2
$_ eq '..' || $_ eq ''
$_ eq '..' $_ eq ''
Truth table100%3/3
A or B
A= $file =~ m[\A/|\\]B= grep {$_ eq ".." or $_ eq "";} split(m[/], $file, -1)
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $_ eq '..'B= $_ eq ''
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $file =~ m[\A/|\\]B= grep {$_ eq ".." or $_ eq "";} split(m[/], $file, -1)
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $_ eq '..'B= $_ eq ''
ABresult
1X1
011
000
491 0 my $root = eval { path($dir)->realpath };
492 0 ▶ $self->_refuse( $field, 'suite directory not readable: '.$dir ) unless $root && $root->is_dir;
Branch: 2 branches
BranchTrueFalseTotal
unless $root and $root->is_dir 0 47 47
unless $root and $root->is_dir 0 0 0
Condition16%1/6
$root and $root->is_dir
!ll&&!rl&&r
0047
$root and $root->is_dir
!ll&&!rl&&r
000
MC/DC0%0/2
$root and $root->is_dir
$root $root->is_dir
MC/DC0%0/2
$root and $root->is_dir
$root $root->is_dir
Truth table33%1/3
A and B
A= $rootB= $root->is_dir
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $rootB= $root->is_dir
ABresult
0X0
100
111
493 0 my $p = path( $root, $file );
494 0 ▶ $self->_refuse( $field, 'no such file in the suite' ) unless -e $p;
Branch: 2 branches
BranchTrueFalseTotal
unless -e $p 1 46 47
unless -e $p 0 0 0
495 0 my $real = eval { $p->realpath };
496 0 ▶ $self->_refuse( $field, 'outside the suite directory' ) unless $real && $root->subsumes($real);
Branch: 2 branches
BranchTrueFalseTotal
unless $real and $root->subsumes($real) 1 45 46
unless $real and $root->subsumes($real) 0 0 0
Condition33%2/6
$real and $root->subsumes($real)
!ll&&!rl&&r
0145
$real and $root->subsumes($real)
!ll&&!rl&&r
000
MC/DC50%1/2
$real and $root->subsumes($real)
$real $root->subsumes($real)
MC/DC0%0/2
$real and $root->subsumes($real)
$real $root->subsumes($real)
Truth table66%2/3
A and B
A= $realB= $root->subsumes($real)
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $realB= $root->subsumes($real)
ABresult
0X0
100
111
497 0 ▶ $self->_refuse( $field, 'not a plain file' ) unless -f $real;
Branch: 2 branches
BranchTrueFalseTotal
unless -f $real 1 44 45
unless -f $real 0 0 0
498 0 my $size = -s _;
499 0 ▶ $self->_refuse( $field, 'larger than '.$IMAGE_MAX_BYTES.' bytes ('.$size.')' ) if $size > $IMAGE_MAX_BYTES;
Branch: 2 branches
BranchTrueFalseTotal
if $size > $Langertha::Holmgang::Structure::IMAGE_MAX_BYTES 1 43 44
if $size > $Langertha::Holmgang::Structure::IMAGE_MAX_BYTES 0 0 0
500 0 my $bytes = eval { $real->slurp_raw };
501 0 ▶ $self->_refuse( $field, 'not readable' ) unless defined $bytes;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $bytes 0 43 43
unless defined $bytes 0 0 0
502 0 ▶ $self->_refuse( $field, 'larger than '.$IMAGE_MAX_BYTES.' bytes ('.length($bytes).')' ) if length $bytes > $IMAGE_MAX_BYTES;
Branch: 2 branches
BranchTrueFalseTotal
if length $bytes > $Langertha::Holmgang::Structure::IMAGE_MAX_BYTES 0 43 43
if length $bytes > $Langertha::Holmgang::Structure::IMAGE_MAX_BYTES 0 0 0
503 0 my ( $type, $w, $h ) = image_measure($bytes);
504 0 ▶ $self->_refuse( $field, 'not a PNG or JPEG image (by its first bytes)' ) unless $type;
Branch: 2 branches
BranchTrueFalseTotal
unless $type 2 41 43
unless $type 0 0 0
505 0 ▶ $self->_refuse( $field, 'a '.$type.' whose width and height cannot be read' ) unless $w && $h;
Branch: 2 branches
BranchTrueFalseTotal
unless $w and $h 1 40 41
unless $w and $h 0 0 0
Condition33%2/6
$w and $h
!ll&&!rl&&r
1040
$w and $h
!ll&&!rl&&r
000
MC/DC50%1/2
$w and $h
$w $h
MC/DC0%0/2
$w and $h
$w $h
Truth table66%2/3
A and B
A= $wB= $h
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $wB= $h
ABresult
0X0
100
111
506 return {
507 0 file => $file,
508 path => "$real",
509 media_type => $type,
510 width => $w,
511 height => $h,
512 bytes => length $bytes,
513 sha256 => Digest::SHA::sha256_hex($bytes),
514 };
515 }
516  
517  
518 # ( media type, width, height ) of PNG or JPEG bytes by their magic; the media
519 # type alone when the size cannot be read, the empty list for anything else
520 48 ▶sub image_measure {
Subroutine image_measure: called CC=19 SCAR=47.2
Pod documented
521 0 ▶ my ( $bytes ) = @_;
Subroutine image_measure: not called CC=19 SCAR=47.2
Pod documented
522 0 ▶ if ( substr( $bytes, 0, 8 ) eq "\x89PNG\r\n\x1a\n" ) {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($bytes, 0, 8) eq "\211PNG\r\n\32\n") 42 6 48
if (substr($bytes, 0, 8) eq "\211PNG\r\n\32\n") 0 0 0
523 0 ▶ return ('image/png') unless length $bytes >= 24 && substr( $bytes, 12, 4 ) eq 'IHDR';
Branch: 2 branches
BranchTrueFalseTotal
unless length $bytes >= 24 and substr($bytes, 12, 4) eq "IHDR" 1 41 42
unless length $bytes >= 24 and substr($bytes, 12, 4) eq "IHDR" 0 0 0
Condition33%2/6
length $bytes >= 24 and substr($bytes, 12, 4) eq "IHDR"
!ll&&!rl&&r
1041
length $bytes >= 24 and substr($bytes, 12, 4) eq "IHDR"
!ll&&!rl&&r
000
MC/DC50%1/2
length $bytes >= 24 and substr($bytes, 12, 4) eq "IHDR"
length $bytes >= 24 substr($bytes, 12, 4) eq "IHDR"
MC/DC0%0/2
length $bytes >= 24 and substr($bytes, 12, 4) eq "IHDR"
length $bytes >= 24 substr($bytes, 12, 4) eq "IHDR"
Truth table66%2/3
A and B
A= length $bytes >= 24B= substr($bytes, 12, 4) eq "IHDR"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= length $bytes >= 24B= substr($bytes, 12, 4) eq "IHDR"
ABresult
0X0
100
111
524 0 return ( 'image/png', unpack 'NN', substr( $bytes, 16, 8 ) );
525 }
526 0 ▶ if ( substr( $bytes, 0, 3 ) eq "\xFF\xD8\xFF" ) {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($bytes, 0, 3) eq "\377\330\377") 3 3 6
if (substr($bytes, 0, 3) eq "\377\330\377") 0 0 0
527 0 my $at = 2;
528 0 my $n = length $bytes;
529 0 ▶ while ( $at + 4 <= $n ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($at + 4 <= $n) 4 1 5
if ($at + 4 <= $n) 0 0 0
530 0 ▶ return ('image/jpeg') unless substr( $bytes, $at, 1 ) eq "\xFF";
Branch: 2 branches
BranchTrueFalseTotal
unless substr($bytes, $at, 1) eq "\377" 0 4 4
unless substr($bytes, $at, 1) eq "\377" 0 0 0
531 0 my $marker = ord substr( $bytes, $at + 1, 1 );
532 0 ▶ if ( $marker == 0xFF ) { $at++; next } # fill byte
Branch: 2 branches
BranchTrueFalseTotal
if ($marker == 255) 0 4 4
if ($marker == 255) 0 0 0
533 0 ▶ if ( $marker == 0x01 || ( $marker >= 0xD0 && $marker <= 0xD8 ) ) { $at += 2; next } # no length
Branch: 2 branches
BranchTrueFalseTotal
if ($marker == 1 or $marker >= 208 and $marker <= 216) 0 4 4
if ($marker == 1 or $marker >= 208 and $marker <= 216) 0 0 0
Condition25%3/12
$marker == 1 or $marker >= 208 and $marker <= 216
l!l&&r!l&&!r
004
$marker >= 208 and $marker <= 216
!ll&&!rl&&r
220
$marker == 1 or $marker >= 208 and $marker <= 216
l!l&&r!l&&!r
000
$marker >= 208 and $marker <= 216
!ll&&!rl&&r
000
MC/DC0%0/3
$marker == 1 or $marker >= 208 and $marker <= 216
$marker == 1 $marker >= 208 $marker <= 216
MC/DC0%0/3
$marker == 1 or $marker >= 208 and $marker <= 216
$marker == 1 $marker >= 208 $marker <= 216
Truth table50%2/4
A or B and C
A= $marker == 1B= $marker >= 208C= $marker <= 216
ABCresult
1XX1
0111
00X0
0100
Truth table0%0/4
A or B and C
A= $marker == 1B= $marker >= 208C= $marker <= 216
ABCresult
1XX1
0111
00X0
0100
534 0 ▶ last if $marker == 0xD9 || $marker == 0xDA; # end, scan data
Branch: 2 branches
BranchTrueFalseTotal
if $marker == 217 or $marker == 218 0 4 4
if $marker == 217 or $marker == 218 0 0 0
Condition16%1/6
$marker == 217 or $marker == 218
l!l&&r!l&&!r
004
$marker == 217 or $marker == 218
l!l&&r!l&&!r
000
MC/DC0%0/2
$marker == 217 or $marker == 218
$marker == 217 $marker == 218
MC/DC0%0/2
$marker == 217 or $marker == 218
$marker == 217 $marker == 218
Truth table33%1/3
A or B
A= $marker == 217B= $marker == 218
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $marker == 217B= $marker == 218
ABresult
1X1
011
000
535 0 my $len = unpack 'n', substr( $bytes, $at + 2, 2 );
536 0 ▶ if ( $marker >= 0xC0 && $marker <= 0xCF && $marker != 0xC4 && $marker != 0xC8 && $marker != 0xCC ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($marker >= 192 and $marker <= 207 and $marker != 196 and $marker != 200 and $marker != 204) 2 2 4
if ($marker >= 192 and $marker <= 207 and $marker != 196 and $marker != 200 and $marker != 204) 0 0 0
Condition33%8/24
$marker >= 192 and $marker <= 207 and $marker != 196 and $marker != 200 and $marker != 204
!ll&&!rl&&r
202
$marker >= 192 and $marker <= 207 and $marker != 196 and $marker != 200
!ll&&!rl&&r
202
$marker >= 192 and $marker <= 207 and $marker != 196
!ll&&!rl&&r
202
$marker >= 192 and $marker <= 207
!ll&&!rl&&r
022
$marker >= 192 and $marker <= 207 and $marker != 196 and $marker != 200 and $marker != 204
!ll&&!rl&&r
000
$marker >= 192 and $marker <= 207 and $marker != 196 and $marker != 200
!ll&&!rl&&r
000
$marker >= 192 and $marker <= 207 and $marker != 196
!ll&&!rl&&r
000
$marker >= 192 and $marker <= 207
!ll&&!rl&&r
000
MC/DC20%1/5
$marker >= 192 and $marker <= 207 and $marker != 196 and $marker != 200 and $marker != 204
$marker >= 192 $marker <= 207 $marker != 196 $marker != 200 $marker != 204
MC/DC0%0/5
$marker >= 192 and $marker <= 207 and $marker != 196 and $marker != 200 and $marker != 204
$marker >= 192 $marker <= 207 $marker != 196 $marker != 200 $marker != 204
Truth table33%2/6
A and B and C and D and E
A= $marker >= 192B= $marker <= 207C= $marker != 196D= $marker != 200E= $marker != 204
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
Truth table0%0/6
A and B and C and D and E
A= $marker >= 192B= $marker <= 207C= $marker != 196D= $marker != 200E= $marker != 204
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
537 0 ▶ last unless $at + 9 <= $n;
Branch: 2 branches
BranchTrueFalseTotal
unless $at + 9 <= $n 0 2 2
unless $at + 9 <= $n 0 0 0
538 0 my ( $h, $w ) = unpack 'nn', substr( $bytes, $at + 5, 4 );
539 0 return ( 'image/jpeg', $w, $h );
540 }
541 0 $at += 2 + $len;
542 }
543 0 return ('image/jpeg');
544 }
545 0 return;
546 }
547  
548  
549 732 ▶sub _required { my ( $r ) = @_; return !exists $r->{required} || $r->{required} ? 1 : 0 }
Subroutine _required: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
!exists $r->{'required'} || $r->{'required'} ? : 727 5 732
Condition66%2/3
not exists $r->{"required"} or $r->{"required"}
l!l&&r!l&&!r
72705
MC/DC50%1/2
not exists $r->{"required"} or $r->{"required"}
not exists $r->{"required"} $r->{"required"}
Truth table66%2/3
not(A) or B
A= not exists $r->{"required"}B= $r->{"required"}
ABresult
1X1
011
000
550  
551 # an observation: answer to a diagnostic command, may depend on the state, never changes it
552 8 ▶sub _observe {
Subroutine _observe: called CC=5 SCAR=16.8
553 8 my ( $self, $h, $field ) = @_;
554 8 $self->_keys_ok( $h, $field, qw( match when output error ) );
555 7 ▶ $self->_refuse( $field.'.match', 'host and command as patterns' ) unless ref $h->{match} eq 'HASH' && $h->{match}{command};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $h->{"match"} eq "HASH" and $h->{"match"}{"command"} 1 6 7
Condition66%2/3
ref $h->{"match"} eq "HASH" and $h->{"match"}{"command"}
!ll&&!rl&&r
016
MC/DC50%1/2
ref $h->{"match"} eq "HASH" and $h->{"match"}{"command"}
ref $h->{"match"} eq "HASH" $h->{"match"}{"command"}
Truth table66%2/3
A and B
A= ref $h->{"match"} eq "HASH"B= $h->{"match"}{"command"}
ABresult
0X0
100
111
556 6 ▶ $self->_refuse( $field.'.output', 'text expected (may be empty)' ) if !defined $h->{output} || ref $h->{output};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $h->{"output"} or ref $h->{"output"} 0 6 6
Condition33%1/3
not defined $h->{"output"} or ref $h->{"output"}
l!l&&r!l&&!r
006
MC/DC0%0/2
not defined $h->{"output"} or ref $h->{"output"}
not defined $h->{"output"} ref $h->{"output"}
Truth table33%1/3
not(A) or B
A= not defined $h->{"output"}B= ref $h->{"output"}
ABresult
1X1
011
000
557 6 $self->_handler( $h, $field, qw( match when output error ) );
558 6 return $h;
559 }
560  
561 # the state: devices (hashes with type) need a known simulator; generated file contents
562 # resolved, then prepared — the case's initial state
563 388 ▶sub _state {
Subroutine _state: called CC=17 SCAR=31.5
564 388 my ( $self, $state, $field ) = @_;
565 388 ▶ $self->_refuse( $field, 'hash (the state of the world) missing' ) unless ref $state eq 'HASH' && %$state;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $state eq "HASH" and %$state 0 388 388
Condition33%1/3
ref $state eq "HASH" and %$state
!ll&&!rl&&r
00388
MC/DC0%0/2
ref $state eq "HASH" and %$state
ref $state eq "HASH" %$state
Truth table33%1/3
A and B
A= ref $state eq "HASH"B= %$state
ABresult
0X0
100
111
566 388 my %types = map { $_ => 1 } $self->simulators->types;
567 388 for my $k ( sort keys %$state ) {
568 439 ▶ next unless ref $state->{$k} eq 'HASH' && exists $state->{$k}{type};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $state->{$k} eq "HASH" and exists $state->{$k}{"type"} 360 79 439
Condition100%3/3
ref $state->{$k} eq "HASH" and exists $state->{$k}{"type"}
!ll&&!rl&&r
11324779
MC/DC100%2/2
ref $state->{$k} eq "HASH" and exists $state->{$k}{"type"}
ref $state->{$k} eq "HASH" exists $state->{$k}{"type"}
Truth table100%3/3
A and B
A= ref $state->{$k} eq "HASH"B= exists $state->{$k}{"type"}
ABresult
0X0
100
111
569 79 ▶ $self->_refuse( $field.'.'.$k.'.type', 'device type '.join( ', ', sort keys %types ) ) unless $types{ $state->{$k}{type} // '' };
Branch: 1 branch
BranchTrueFalseTotal
unless $types{$state->{$k}{"type"} // ""} 3 76 79
Condition50%1/2
$state->{$k}{"type"} // ""
l!l
790
MC/DC0%0/1
$state->{$k}{"type"} // ""
$state->{$k}{"type"}
Truth table50%1/2
A
A= $state->{$k}{"type"}
Aresult
11
00
570 }
571 385 $self->_plain( $state->{$_}, $field.'.'.$_ ) for sort keys %$state;
572 379 my $s = Langertha::Holmgang::World->clone($state);
573 379 for my $dev ( sort keys %$s ) {
574 424 ▶ my $files = ref $s->{$dev} eq 'HASH' ? $s->{$dev}{files} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $s->{$dev} eq 'HASH' ? : 317 107 424
575 424 ▶ next unless ref $files eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $files eq "HASH" 384 40 424
576 40 for my $p ( sort keys %$files ) {
577 40 my $e = $files->{$p};
578 40 ▶ next unless ref $e eq 'HASH' && ref $e->{content};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $e eq "HASH" and ref $e->{"content"} 40 0 40
Condition33%1/3
ref $e eq "HASH" and ref $e->{"content"}
!ll&&!rl&&r
4000
MC/DC0%0/2
ref $e eq "HASH" and ref $e->{"content"}
ref $e eq "HASH" ref $e->{"content"}
Truth table33%1/3
A and B
A= ref $e eq "HASH"B= ref $e->{"content"}
ABresult
0X0
100
111
579 0 $e->{content} = $self->haystack->resolve( $e->{content}, $field.'.'.$dev.'.files.'.$p.'.content' );
580 }
581 }
582 379 ▶ eval { $self->simulators->prepare($s); 1 } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->simulators->prepare($s); 1 } } or do { my $err = $@; die $err if "Langertha::Holmgang::Error"->caught($err); $self->_refuse($field, "$err" =~ s/\s+\z//r) } 379 0 379
583 0 my $err = $@;
584 0 ▶ die $err if Langertha::Holmgang::Error->caught($err);
Branch: 1 branch
BranchTrueFalseTotal
if "Langertha::Holmgang::Error"->caught($err) 0 0 0
585 0 $self->_refuse( $field, "$err" =~ s/\s+\z//r );
586 };
587 379 return $s;
588 }
589  
590 # plain data only (k59): what the world's copy and the YAML export take
591 1596 ▶sub _plain {
Subroutine _plain: called CC=9 SCAR=22.0
592 1596 my ( $self, $v, $field ) = @_;
593 1596 my $r = ref $v;
594 1596 ▶ return unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 1068 528 1596
595 528 ▶ return if blessed $v && $v->isa('JSON::PP::Boolean');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($v) and $v->isa("JSON::PP::Boolean") 1 527 528
Condition100%3/3
builtin::blessed($v) and $v->isa("JSON::PP::Boolean")
!ll&&!rl&&r
52611
MC/DC100%2/2
builtin::blessed($v) and $v->isa("JSON::PP::Boolean")
builtin::blessed($v) $v->isa("JSON::PP::Boolean")
Truth table100%3/3
A and B
A= builtin::blessed($v)B= $v->isa("JSON::PP::Boolean")
ABresult
0X0
100
111
596 527 ▶ if ( $r eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r eq "HASH") 449 78 527
597 449 $self->_plain( $v->{$_}, $field.'.'.$_ ) for sort keys %$v;
598 443 return;
599 }
600 78 ▶ if ( $r eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r eq "ARRAY") 72 6 78
601 72 $self->_plain( $v->[$_], $field.'['.$_.']' ) for 0 .. $#$v;
602 71 return;
603 }
604 6 ▶ $self->_refuse( $field, 'not data: '.( $r eq 'CODE' ? 'a code reference' : 'a '.$r.' reference' )
Branch: 1 branch
BranchTrueFalseTotal
$r eq 'CODE' ? : 4 2 6
605 .' (the state holds texts, numbers, booleans, hashes and lists)' );
606 }
607  
608 1483 ▶sub _call {
Subroutine _call: called CC=5 SCAR=16.1
609 1483 my ( $self, $c, $field, $tools, $with_args ) = @_;
610 1483 $self->_keys_ok( $c, $field, qw( tool args ) );
611 1483 my $tool = $self->_text( $c->{tool}, $field.'.tool' );
612 1483 ▶ $self->_refuse( $field.'.tool', "the case offers no tool '".$tool."'" ) unless $tools->{$tool};
Branch: 1 branch
BranchTrueFalseTotal
unless $tools->{$tool} 1 1482 1483
613 1482 ▶ my $args = $c->{args} // {};
Condition100%2/2
$c->{"args"} // {}
l!l
14811
MC/DC100%1/1
$c->{"args"} // {}
$c->{"args"}
Truth table100%2/2
A
A= $c->{"args"}
Aresult
11
00
614 1482 ▶ $self->_refuse( $field.'.args', 'not a hash' ) unless ref $args eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args eq "HASH" 0 1482 1482
615 1482 ▶ $self->_arg_patterns( $args, $field.'.args' ) unless $with_args;
Branch: 1 branch
BranchTrueFalseTotal
unless $with_args 22 1460 1482
616 1482 return $c;
617 }
618  
619 1080 ▶sub _calls {
Subroutine _calls: called CC=2 SCAR=6.9
620 1080 my ( $self, $l, $field, $tools ) = @_;
621 1080 $self->_list( $l, $field, 1 );
622 1080 $self->_call( $l->[$_], $field.'['.$_.']', $tools, 1 ) for 0 .. $#$l;
623 1079 return $l;
624 }
625  
626 # one rule; returns its kind
627 755 ▶sub _rule {
Subroutine _rule: called CC=41 SCAR=41.3
628 755 my ( $self, $r, $field, $tools, $state ) = @_;
629 755 ▶ $self->_refuse( $field, 'not a hash' ) unless ref $r eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $r eq "HASH" 0 755 755
630 755 my @kind = grep { exists $r->{$_} } @RULE_KINDS;
631 755 ▶ $self->_refuse( $field, 'exactly one kind: '.join( ', ', @RULE_KINDS ) ) unless @kind == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @kind == 1 1 754 755
632 754 my $kind = $kind[0];
633 754 $self->_text( $r->{title}, $field.'.title' );
634 754 my %rest = %$r;
635 754 delete @rest{qw( title required )};
636 754 ▶ if ( $kind eq 'state' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($kind eq 'state') { } 400 354 754
elsif ($kind eq 'check') { } 9 345 354
elsif ($kind eq 'login') { } 4 341 345
elsif ($kind eq 'packet') { } 7 334 341
637 400 my $path = delete $rest{state};
638 400 $self->_matchers( { %rest, path => $path }, $field );
639 }
640 elsif ( $kind eq 'check' ) {
641 9 $self->_check_rule( \%rest, $field, $state );
642 }
643 elsif ( $kind eq 'login' ) {
644 4 $self->_keys_ok( \%rest, $field, qw( login result ) );
645 4 my $l = $r->{login};
646 4 $self->_keys_ok( $l, $field.'.login', qw( host user from key port iif daddr auth ) );
647 3 $self->_text( $l->{$_}, $field.'.login.'.$_ ) for qw( host user from );
648 3 ▶ for my $k (qw( key iif daddr )) { $self->_text( $l->{$k}, $field.'.login.'.$k ) if defined $l->{$k} }
Branch: 1 branch
BranchTrueFalseTotal
if defined $l->{$k} 0 9 9
649 3 ▶ if ( defined $l->{port} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $l->{"port"}) 1 2 3
650 $self->_refuse( $field.'.login.port', 'port 1-65535' )
651 1 ▶ unless !ref $l->{port} && $l->{port} =~ /\A\d+\z/ && $l->{port} >= 1 && $l->{port} <= 65535;
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $l->{"port"} and $l->{"port"} =~ /\A\d+\z/ and $l->{"port"} >= 1 and $l->{"port"} <= 65535 1 0 1
Condition33%3/9
not ref $l->{"port"} and $l->{"port"} =~ /\A\d+\z/ and $l->{"port"} >= 1 and $l->{"port"} <= 65535
!ll&&!rl&&r
010
not ref $l->{"port"} and $l->{"port"} =~ /\A\d+\z/ and $l->{"port"} >= 1
!ll&&!rl&&r
001
not ref $l->{"port"} and $l->{"port"} =~ /\A\d+\z/
!ll&&!rl&&r
001
MC/DC0%0/4
not ref $l->{"port"} and $l->{"port"} =~ /\A\d+\z/ and $l->{"port"} >= 1 and $l->{"port"} <= 65535
not ref $l->{"port"} $l->{"port"} =~ /\A\d+\z/ $l->{"port"} >= 1 $l->{"port"} <= 65535
Truth table20%1/5
not(A) and B and C and D
A= not ref $l->{"port"}B= $l->{"port"} =~ /\A\d+\z/C= $l->{"port"} >= 1D= $l->{"port"} <= 65535
ABCDresult
0XXX0
10XX0
110X0
11100
11111
652 }
653 2 ▶ my $auth = $l->{auth} // ( defined $l->{key} ? 'publickey' : '' );
Branch: 1 branch
BranchTrueFalseTotal
defined $l->{'key'} ? : 0 1 1
Condition100%2/2
$l->{"auth"} // (defined $l->{"key"} ? "publickey" : "")
l!l
11
MC/DC100%1/1
$l->{"auth"} // (defined $l->{"key"} ? "publickey" : "")
$l->{"auth"}
Truth table100%2/2
A
A= $l->{"auth"}
Aresult
11
00
654 $self->_refuse( $field.'.login.auth', 'publickey (with key) or password' )
655 2 ▶ unless $auth eq 'password' || ( $auth eq 'publickey' && defined $l->{key} );
Branch: 1 branch
BranchTrueFalseTotal
unless $auth eq "password" or $auth eq "publickey" and defined $l->{"key"} 1 1 2
Condition50%3/6
$auth eq "password" or $auth eq "publickey" and defined $l->{"key"}
l!l&&r!l&&!r
101
$auth eq "publickey" and defined $l->{"key"}
!ll&&!rl&&r
100
MC/DC33%1/3
$auth eq "password" or $auth eq "publickey" and defined $l->{"key"}
$auth eq "password" $auth eq "publickey" defined $l->{"key"}
Truth table50%2/4
A or B and C
A= $auth eq "password"B= $auth eq "publickey"C= defined $l->{"key"}
ABCresult
1XX1
0111
00X0
0100
656 1 ▶ my $v = $r->{result} // '';
Condition50%1/2
$r->{"result"} // ""
l!l
10
MC/DC0%0/1
$r->{"result"} // ""
$r->{"result"}
Truth table50%1/2
A
A= $r->{"result"}
Aresult
11
00
657 1 ▶ $self->_refuse( $field.'.result', 'allowed or denied' ) unless !ref $v && ( $v eq 'allowed' || $v eq 'denied' );
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $v and $v eq "allowed" || $v eq "denied" 1 0 1
Condition33%2/6
not ref $v and $v eq "allowed" || $v eq "denied"
!ll&&!rl&&r
010
$v eq "allowed" or $v eq "denied"
l!l&&r!l&&!r
001
MC/DC0%0/3
not ref $v and $v eq "allowed" || $v eq "denied"
not ref $v $v eq "allowed" $v eq "denied"
Truth table25%1/4
not(A) and B or C
A= not ref $vB= $v eq "allowed"C= $v eq "denied"
ABCresult
0XX0
1000
11X1
1011
658 }
659 elsif ( $kind eq 'packet' ) {
660 7 $self->_keys_ok( \%rest, $field, qw( packet verdict boot ) );
661 7 $self->_packet( $r->{packet}, $field.'.packet' );
662 3 ▶ my $v = $r->{verdict} // '';
Condition50%1/2
$r->{"verdict"} // ""
l!l
30
MC/DC0%0/1
$r->{"verdict"} // ""
$r->{"verdict"}
Truth table50%1/2
A
A= $r->{"verdict"}
Aresult
11
00
663 3 ▶ $self->_refuse( $field.'.verdict', 'accept or drop' ) unless !ref $v && ( $v eq 'accept' || $v eq 'drop' );
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $v and $v eq "accept" || $v eq "drop" 1 2 3
Condition66%4/6
not ref $v and $v eq "accept" || $v eq "drop"
!ll&&!rl&&r
012
$v eq "accept" or $v eq "drop"
l!l&&r!l&&!r
201
MC/DC33%1/3
not ref $v and $v eq "accept" || $v eq "drop"
not ref $v $v eq "accept" $v eq "drop"
Truth table50%2/4
not(A) and B or C
A= not ref $vB= $v eq "accept"C= $v eq "drop"
ABCresult
0XX0
1000
11X1
1011
664 2 ▶ if ( my $b = $r->{boot} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $b = $r->{"boot"}) 1 1 2
665 1 ▶ $self->_refuse( $field.'.boot', 'true or an absolute path' ) unless !ref $b || "$b" eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $b or "$b" eq 1 1 0 1
Condition33%1/3
not ref $b or "$b" eq 1
l!l&&r!l&&!r
001
MC/DC0%0/2
not ref $b or "$b" eq 1
not ref $b "$b" eq 1
Truth table33%1/3
not(A) or B
A= not ref $bB= "$b" eq 1
ABresult
1X1
011
000
666 }
667 }
668 else {
669 334 $self->_keys_ok( \%rest, $field, $kind );
670 334 ▶ if ( $kind eq 'unchanged_except' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($kind eq 'unchanged_except') { } 298 36 334
elsif ($kind eq 'only_tools') { } 14 22 36
elsif ($kind eq 'calls') { } 3 19 22
671 298 my $p = $self->_list( $r->{unchanged_except}, $field.'.unchanged_except' );
672 298 $self->_path( $p->[$_], $field.'.unchanged_except['.$_.']' ) for 0 .. $#$p;
673 }
674 elsif ( $kind eq 'only_tools' ) {
675 14 my $l = $self->_list( $r->{only_tools}, $field.'.only_tools' );
676 13 for my $i ( 0 .. $#$l ) {
677 10 my $t = $l->[$i];
678 $self->_refuse( $field.'.only_tools['.$i.']', "the case offers no tool '".( $t // '' )."'" )
679 10 ▶ unless defined $t && !ref $t && $tools->{$t};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t and not ref $t and $tools->{$t} 1 9 10
Condition50%4/8
defined $t and not ref $t and $tools->{$t}
!ll&&!rl&&r
019
defined $t and not ref $t
!ll&&!rl&&r
0010
$t // ""
l!l
10
MC/DC33%1/3
defined $t and not ref $t and $tools->{$t}
defined $t not ref $t $tools->{$t}
MC/DC0%0/1
$t // ""
$t
Truth table50%2/4
A and not(B) and C
A= defined $tB= not ref $tC= $tools->{$t}
ABCresult
0XX0
10X0
1100
1111
Truth table50%1/2
A
A= $t
Aresult
11
00
680 }
681 }
682 elsif ( $kind eq 'calls' ) {
683 3 my $l = $self->_list( $r->{calls}, $field.'.calls', 1 );
684 3 $self->_call( $l->[$_], $field.'.calls['.$_.']', $tools ) for 0 .. $#$l;
685 }
686 else {
687 19 $self->_call( $r->{not_called}, $field.'.not_called', $tools );
688 }
689 }
690 727 return $kind;
691 }
692  
693 # rule check: a command { host, command } on a copy of the end state, expect { exit, output, lines }
694 9 ▶sub _check_rule {
Subroutine _check_rule: called CC=10 SCAR=23.2
695 9 my ( $self, $r, $field, $state ) = @_;
696 9 $self->_keys_ok( $r, $field, qw( check expect ) );
697 9 my $c = $r->{check};
698 9 ▶ $self->_refuse( $field.'.check', 'hash { host, command } expected' ) unless ref $c eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $c eq "HASH" 0 9 9
699 9 $self->_keys_ok( $c, $field.'.check', qw( host command ) );
700 9 my $host = $self->_text( $c->{host}, $field.'.check.host' );
701 9 ▶ $self->_refuse( $field.'.check.host', "no device '".$host."' in the state" ) unless ref( ( $state || {} )->{$host} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref +($state || {})->{$host} eq "HASH" 1 8 9
Condition50%1/2
$state || {}
l!l
90
MC/DC0%0/1
$state || {}
$state
Truth table50%1/2
A
A= $state
Aresult
11
00
702 8 my $e = $r->{expect};
703 8 ▶ $self->_refuse( $field.'.expect', 'hash { exit, output, lines } missing' ) unless ref $e eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $e eq "HASH" 1 7 8
704 7 $self->_keys_ok( $e, $field.'.expect', qw( exit output lines ) );
705 7 ▶ $self->_refuse( $field.'.expect', 'at least one expectation: exit, output or lines' ) unless grep { exists $e->{$_} } qw( exit output lines );
Branch: 1 branch
BranchTrueFalseTotal
unless grep {exists $e->{$_};} "exit", "output", "lines" 1 6 7
706 6 ▶ $self->_num( $e->{exit}, $field.'.expect.exit', 0, 255 ) if exists $e->{exit};
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"exit"} 6 0 6
707 5 for my $k (qw( output lines )) {
708 10 ▶ next unless exists $e->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $e->{$k} 5 5 10
709 5 ▶ $self->_refuse( $field.'.expect.'.$k, 'hash of expectations expected' ) unless ref $e->{$k} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $e->{$k} eq "HASH" 0 5 5
710 5 $self->_matchers( $e->{$k}, $field.'.expect.'.$k, 1 );
711 }
712 5 $self->_text( $c->{command}, $field.'.check.command' );
713 5 return;
714 }
715  
716 # the packet of a rule packet: fields and values checked
717 7 ▶sub _packet {
Subroutine _packet: called CC=26 SCAR=38.9
718 7 my ( $self, $p, $field ) = @_;
719 7 $self->_keys_ok( $p, $field, qw( host hook iif oif saddr daddr proto sport dport icmp_type icmp_code ct ct_status ) );
720 7 $self->_text( $p->{host}, $field.'.host' );
721 7 ▶ $self->_refuse( $field.'.hook', join( '|', sort keys %HOOK ) ) unless !ref $p->{hook} && $HOOK{ $p->{hook} // '' };
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $p->{"hook"} and $HOOK{$p->{"hook"} // ""} 1 6 7
Condition60%3/5
not ref $p->{"hook"} and $HOOK{$p->{"hook"} // ""}
!ll&&!rl&&r
016
$p->{"hook"} // ""
l!l
70
MC/DC50%1/2
not ref $p->{"hook"} and $HOOK{$p->{"hook"} // ""}
not ref $p->{"hook"} $HOOK{$p->{"hook"} // ""}
MC/DC0%0/1
$p->{"hook"} // ""
$p->{"hook"}
Truth table66%2/3
not(A) and B
A= not ref $p->{"hook"}B= $HOOK{$p->{"hook"} // ""}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $p->{"hook"}
Aresult
11
00
722 6 my %fam;
723 6 for my $k (qw( saddr daddr )) {
724 12 my $a = $self->_text( $p->{$k}, $field.'.'.$k );
725 12 ▶ $self->_refuse( $field.'.'.$k, 'IPv4 or IPv6 address' ) unless $a =~ /\A\d+\.\d+\.\d+\.\d+\z|\A[0-9a-f:]*:[0-9a-f:]*\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $a =~ /\A\d+\.\d+\.\d+\.\d+\z|\A[0-9a-f:]*:[0-9a-f:]*\z/i 0 12 12
726 12 ▶ $fam{$k} = $a =~ /:/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$a =~ /:/ ? : 1 11 12
727 }
728 6 ▶ $self->_refuse( $field.'.daddr', 'same family as saddr' ) unless $fam{saddr} == $fam{daddr};
Branch: 1 branch
BranchTrueFalseTotal
unless $fam{"saddr"} == $fam{"daddr"} 1 5 6
729 5 ▶ $self->_refuse( $field.'.proto', join( '|', sort keys %L4 ) ) unless !ref $p->{proto} && $L4{ $p->{proto} // '' };
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $p->{"proto"} and $L4{$p->{"proto"} // ""} 0 5 5
Condition40%2/5
not ref $p->{"proto"} and $L4{$p->{"proto"} // ""}
!ll&&!rl&&r
005
$p->{"proto"} // ""
l!l
50
MC/DC0%0/2
not ref $p->{"proto"} and $L4{$p->{"proto"} // ""}
not ref $p->{"proto"} $L4{$p->{"proto"} // ""}
MC/DC0%0/1
$p->{"proto"} // ""
$p->{"proto"}
Truth table33%1/3
not(A) and B
A= not ref $p->{"proto"}B= $L4{$p->{"proto"} // ""}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $p->{"proto"}
Aresult
11
00
730 5 ▶ my $l4 = $p->{proto} eq 'tcp' || $p->{proto} eq 'udp';
Condition66%2/3
$p->{'proto'} eq 'tcp' || $p->{'proto'} eq 'udp'
l!l&&r!l&&!r
401
MC/DC50%1/2
$p->{'proto'} eq 'tcp' || $p->{'proto'} eq 'udp'
$p->{'proto'} eq 'tcp' $p->{'proto'} eq 'udp'
Truth table66%2/3
A || B
A= $p->{'proto'} eq 'tcp'B= $p->{'proto'} eq 'udp'
ABresult
1X1
011
000
731 5 for my $k (qw( sport dport )) {
732 10 ▶ next unless defined $p->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p->{$k} 6 4 10
733 4 ▶ $self->_refuse( $field.'.'.$k, 'port 1-65535' ) unless !ref $p->{$k} && $p->{$k} =~ /\A\d+\z/ && $p->{$k} >= 1 && $p->{$k} <= 65535;
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $p->{$k} and $p->{$k} =~ /\A\d+\z/ and $p->{$k} >= 1 and $p->{$k} <= 65535 0 4 4
Condition33%3/9
not ref $p->{$k} and $p->{$k} =~ /\A\d+\z/ and $p->{$k} >= 1 and $p->{$k} <= 65535
!ll&&!rl&&r
004
not ref $p->{$k} and $p->{$k} =~ /\A\d+\z/ and $p->{$k} >= 1
!ll&&!rl&&r
004
not ref $p->{$k} and $p->{$k} =~ /\A\d+\z/
!ll&&!rl&&r
004
MC/DC0%0/4
not ref $p->{$k} and $p->{$k} =~ /\A\d+\z/ and $p->{$k} >= 1 and $p->{$k} <= 65535
not ref $p->{$k} $p->{$k} =~ /\A\d+\z/ $p->{$k} >= 1 $p->{$k} <= 65535
Truth table20%1/5
not(A) and B and C and D
A= not ref $p->{$k}B= $p->{$k} =~ /\A\d+\z/C= $p->{$k} >= 1D= $p->{$k} <= 65535
ABCDresult
0XXX0
10XX0
110X0
11100
11111
734 4 ▶ $self->_refuse( $field.'.'.$k, 'only with tcp/udp' ) unless $l4;
Branch: 1 branch
BranchTrueFalseTotal
unless $l4 1 3 4
735 }
736 4 ▶ $self->_refuse( $field.'.dport', 'missing (tcp/udp)' ) if $l4 && !defined $p->{dport};
Branch: 1 branch
BranchTrueFalseTotal
if $l4 and not defined $p->{"dport"} 1 3 4
Condition66%2/3
$l4 and not defined $p->{"dport"}
!ll&&!rl&&r
031
MC/DC50%1/2
$l4 and not defined $p->{"dport"}
$l4 not defined $p->{"dport"}
Truth table66%2/3
A and not(B)
A= $l4B= not defined $p->{"dport"}
ABresult
0X0
100
111
737 3 ▶ for my $k (qw( iif oif icmp_type icmp_code ct_status )) { $self->_text( $p->{$k}, $field.'.'.$k ) if defined $p->{$k} }
Branch: 1 branch
BranchTrueFalseTotal
if defined $p->{$k} 0 15 15
738 3 ▶ if ( defined $p->{ct} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p->{"ct"}) 0 3 3
739 0 ▶ $self->_refuse( $field.'.ct', 'new|established|related|invalid' ) unless !ref $p->{ct} && $p->{ct} =~ /\A(?:new|established|related|invalid)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $p->{"ct"} and $p->{"ct"} =~ /\A(?:new|established|related|invalid)\z/ 0 0 0
Condition0%0/3
not ref $p->{"ct"} and $p->{"ct"} =~ /\A(?:new|established|related|invalid)\z/
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $p->{"ct"} and $p->{"ct"} =~ /\A(?:new|established|related|invalid)\z/
not ref $p->{"ct"} $p->{"ct"} =~ /\A(?:new|established|related|invalid)\z/
Truth table0%0/3
not(A) and B
A= not ref $p->{"ct"}B= $p->{"ct"} =~ /\A(?:new|established|related|invalid)\z/
ABresult
0X0
100
111
740 }
741 3 return;
742 }
743  
744 36 __PACKAGE__->meta->make_immutable;
745  
746 __END__
« blib/lib/Langertha/Holmgang/Sim/Linux.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Backup.pm »