blib/lib/Langertha/Holmgang/Lint.pm

filter: Statementstmt 55.6% 113 / 203 Branchbran 42.8% 24 / 56 Conditioncond 37.5% 21 / 56 MC/DCmcdc 28.1% 9 / 32 Subroutinesub 69.5% 16 / 23 Podpod 100% 2 / 2 totaltotal 49.7% 185 / 372 CC 79 SCAR 42.9
CC
79
Cov
50%
lint
129.9
lint
129.9
_filters
27.5
CRAP 72.6
« blib/lib/Langertha/Holmgang/Sim/Linux/SshAccess.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Monitoring.pm »
1 package Langertha::Holmgang::Lint;
2 # ABSTRACT: The self-check every case passes on every load
3  
4 35 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 35 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 35 ▶use Langertha::Holmgang::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 35 ▶use Langertha::Holmgang::Expectation qw( filter_value );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 35 ▶use Langertha::Holmgang::Grader;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 35 ▶use Langertha::Holmgang::Template ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 35 ▶use Langertha::Holmgang::World ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 35 our $VERSION = '0.001';
15  
16  
17 35 has grader => (
18 is => 'ro',
19 lazy => 1,
20 builder => '_build_grader',
21 );
22 4 ▶sub _build_grader { Langertha::Holmgang::Grader->new }
Subroutine _build_grader: called CC=1 SCAR=0.0
23  
24  
25 35 has mock_runs => (
26 is => 'ro',
27 predicate => 'has_mock_runs',
28 );
29  
30  
31 21 ▶sub _refuse {
Subroutine _refuse: called CC=1 SCAR=1.2
32 0 ▶ my ( $self, $field, $reason ) = @_;
Subroutine _refuse: not called CC=1 SCAR=1.2
33 0 Langertha::Holmgang::Error->throw( $field, $reason );
34 }
35  
36 336 ▶sub lint {
Subroutine lint: called CC=26 SCAR=48.7
Pod documented
37 0 ▶ my ( $self, $case, $f ) = @_;
Subroutine lint: not called CC=26 SCAR=48.7
Pod documented
38 0 ▶ $f //= $case->id;
Condition16%1/6
$f //= $case->id
l!l&&r!l&&!r
33600
$f //= $case->id
l!l&&r!l&&!r
000
MC/DC0%0/2
$f //= $case->id
$f $case->id
MC/DC0%0/2
$f //= $case->id
$f $case->id
Truth table33%1/3
A //= B
A= $fB= $case->id
ABresult
1X1
011
000
Truth table0%0/3
A //= B
A= $fB= $case->id
ABresult
1X1
011
000
39 0 my $g = $self->grader;
40  
41 # 0. argument filters, where the world applies them (a where pattern takes {name} only)
42 0 for my $t ( @{ $case->tools } ) {
43 0 ▶ my $hs = $t->{handlers} || [];
Condition50%2/4
$t->{'handlers'} || []
l!l
324312
$t->{'handlers'} || []
l!l
00
MC/DC100%1/1
$t->{'handlers'} || []
$t->{'handlers'}
MC/DC0%0/1
$t->{'handlers'} || []
$t->{'handlers'}
Truth table100%2/2
A
A= $t->{'handlers'}
Aresult
11
00
Truth table0%0/2
A
A= $t->{'handlers'}
Aresult
11
00
44 0 for my $j ( 0 .. $#$hs ) {
45 0 my $hf = $f.': tools.'.$t->{name}.'.handlers['.$j.']';
46 0 $self->_when_filters( $hs->[$j]{when}, $hf );
47 0 ▶ my $ap = $hs->[$j]{apply} || [];
Condition50%2/4
$hs->[$j]{'apply'} || []
l!l
31710
$hs->[$j]{'apply'} || []
l!l
00
MC/DC100%1/1
$hs->[$j]{'apply'} || []
$hs->[$j]{'apply'}
MC/DC0%0/1
$hs->[$j]{'apply'} || []
$hs->[$j]{'apply'}
Truth table100%2/2
A
A= $hs->[$j]{'apply'}
Aresult
11
00
Truth table0%0/2
A
A= $hs->[$j]{'apply'}
Aresult
11
00
48 0 for my $k ( 0 .. $#$ap ) {
49 0 my $op = $ap->[$k];
50 0 $self->_filters( $op->{$_}, $hf.'.apply['.$k.'].'.$_ ) for grep { exists $op->{$_} } @Langertha::Holmgang::World::OPS, qw( value at from to );
51 }
52 }
53 }
54 0 ▶ my $obs = $case->observe || [];
Condition50%2/4
$case->observe || []
l!l
5325
$case->observe || []
l!l
00
MC/DC100%1/1
$case->observe || []
$case->observe
MC/DC0%0/1
$case->observe || []
$case->observe
Truth table100%2/2
A
A= $case->observe
Aresult
11
00
Truth table0%0/2
A
A= $case->observe
Aresult
11
00
55 0 $self->_when_filters( $obs->[$_]{when}, $f.': observe['.$_.']' ) for 0 .. $#$obs;
56  
57 # 1. templates
58 0 for my $t ( @{ $case->tools } ) {
59 0 ▶ my $hs = $t->{handlers} || [];
Condition50%2/4
$t->{'handlers'} || []
l!l
316310
$t->{'handlers'} || []
l!l
00
MC/DC100%1/1
$t->{'handlers'} || []
$t->{'handlers'}
MC/DC0%0/1
$t->{'handlers'} || []
$t->{'handlers'}
Truth table100%2/2
A
A= $t->{'handlers'}
Aresult
11
00
Truth table0%0/2
A
A= $t->{'handlers'}
Aresult
11
00
60 0 for my $j ( 0 .. $#$hs ) {
61 0 $self->_renders( $case, $hs->[$j]{output}, $f.': tools.'.$t->{name}.'.handlers['.$j.'].output' );
62 }
63 }
64 0 $self->_renders( $case, $obs->[$_]{output}, $f.': observe['.$_.'].output' ) for 0 .. $#$obs;
65  
66 4 ▶ my $failed = sub {
Subroutine __ANON__: called CC=2 SCAR=10.0
67 0 ▶ my ( $r ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=10.0
68 0 ▶ return join '; ', map { '"'.$_->{title}.'": '.$_->{reason} } grep { $_->{required} && !$_->{passed} } @{ $r->{rules} };
Condition33%2/6
$_->{'required'} && !$_->{'passed'}
!ll&&!rl&&r
034
$_->{'required'} && !$_->{'passed'}
!ll&&!rl&&r
000
MC/DC50%1/2
$_->{'required'} && !$_->{'passed'}
$_->{'required'} !$_->{'passed'}
MC/DC0%0/2
$_->{'required'} && !$_->{'passed'}
$_->{'required'} !$_->{'passed'}
Truth table66%2/3
A && not(B)
A= $_->{'required'}B= !$_->{'passed'}
ABresult
0X0
100
111
Truth table0%0/3
A && not(B)
A= $_->{'required'}B= !$_->{'passed'}
ABresult
0X0
100
111
69 0 };
70 # 5. a check command runs without a gap after every path
71 1346 ▶ my $check_gap = sub {
Subroutine __ANON__: called CC=2 SCAR=9.2
72 0 ▶ my ( $r, $field ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=9.2
73 0 ▶ my ( $rule ) = grep { defined $_->{sim_gap} } @{ $r->{rules} } or return;
Branch: 2 branches
BranchTrueFalseTotal
my($rule) = grep({defined $_->{"sim_gap"};} @{$$r{"rules"};}) or return 1 1345 1346
my($rule) = grep({defined $_->{"sim_gap"};} @{$$r{"rules"};}) or return 0 0 0
74 0 $self->_refuse( $f.': '.$field, 'check command "'.$rule->{title}.'" hits a gap of the simulation: '.$rule->{sim_gap} );
75 0 };
76  
77 # 2. doing nothing
78 0 my $noop = $g->grade( $case, { state => $case->initial_state, calls => [] } );
79 0 $check_gap->( $noop, 'rules' );
80 $self->_refuse( $f.': rules', 'doing nothing passes already — the rules check no change' )
81 0 ▶ if $noop->{status} eq 'passed' && !$case->no_tool;
Branch: 2 branches
BranchTrueFalseTotal
if $noop->{"status"} eq "passed" and not $case->no_tool 1 327 328
if $noop->{"status"} eq "passed" and not $case->no_tool 0 0 0
Condition50%3/6
$noop->{"status"} eq "passed" and not $case->no_tool
!ll&&!rl&&r
32431
$noop->{"status"} eq "passed" and not $case->no_tool
!ll&&!rl&&r
000
MC/DC100%2/2
$noop->{"status"} eq "passed" and not $case->no_tool
$noop->{"status"} eq "passed" not $case->no_tool
MC/DC0%0/2
$noop->{"status"} eq "passed" and not $case->no_tool
$noop->{"status"} eq "passed" not $case->no_tool
Truth table100%3/3
A and not(B)
A= $noop->{"status"} eq "passed"B= not $case->no_tool
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $noop->{"status"} eq "passed"B= not $case->no_tool
ABresult
0X0
100
111
82  
83 # 3. the right paths
84 0 ▶ my @alt = @{ $case->alternatives || [] };
Condition50%2/4
$case->alternatives || []
l!l
3243
$case->alternatives || []
l!l
00
MC/DC100%1/1
$case->alternatives || []
$case->alternatives
MC/DC0%0/1
$case->alternatives || []
$case->alternatives
Truth table100%2/2
A
A= $case->alternatives
Aresult
11
00
Truth table0%0/2
A
A= $case->alternatives
Aresult
11
00
85 my @right = (
86 [ solution => 'the reference solution', $case->solution ],
87 0 map { [ 'alternatives['.$_.']', 'alternative "'.$alt[$_]{title}.'"', $alt[$_]{calls} ] } 0 .. $#alt,
88 );
89 0 for my $r ( @right ) {
90 0 my ( $field, $name, $calls ) = @$r;
91 0 my $sol = $g->replay( $case, $calls );
92 0 ▶ if ( @{ $sol->{failed_calls} } ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@{$sol->{"failed_calls"};}) 1 649 650
if (@{$sol->{"failed_calls"};}) 0 0 0
93 0 my $n = $sol->{failed_calls}[0];
94 0 ▶ $self->_refuse( $f.': '.$field.'['.$n.']', 'call fails: '.( $sol->{outputs}[$n] // '' ) );
Condition25%1/4
$sol->{"outputs"}[$n] // ""
l!l
10
$sol->{"outputs"}[$n] // ""
l!l
00
MC/DC0%0/1
$sol->{"outputs"}[$n] // ""
$sol->{"outputs"}[$n]
MC/DC0%0/1
$sol->{"outputs"}[$n] // ""
$sol->{"outputs"}[$n]
Truth table50%1/2
A
A= $sol->{"outputs"}[$n]
Aresult
11
00
Truth table0%0/2
A
A= $sol->{"outputs"}[$n]
Aresult
11
00
95 }
96 0 ▶ if ( @{ $sol->{sim_gaps} } ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@{$sol->{"sim_gaps"};}) 0 649 649
if (@{$sol->{"sim_gaps"};}) 0 0 0
97 0 $self->_refuse( $f.': '.$field.'['.$sol->{sim_gaps}[0]{call}.']', 'gap of the simulation: '.$sol->{sim_gaps}[0]{gap} );
98 }
99 0 $check_gap->( $sol, $field );
100 0 ▶ $self->_refuse( $f.': '.$field, $name.' does not pass: '.$failed->($sol) ) unless $sol->{status} eq 'passed';
Branch: 2 branches
BranchTrueFalseTotal
unless $sol->{"status"} eq "passed" 4 644 648
unless $sol->{"status"} eq "passed" 0 0 0
101 }
102  
103 # 4. the wrong solutions
104 0 ▶ my $wrong = $case->wrong_solutions || [];
Condition25%1/4
$case->wrong_solutions || []
l!l
3210
$case->wrong_solutions || []
l!l
00
MC/DC0%0/1
$case->wrong_solutions || []
$case->wrong_solutions
MC/DC0%0/1
$case->wrong_solutions || []
$case->wrong_solutions
Truth table50%1/2
A
A= $case->wrong_solutions
Aresult
11
00
Truth table0%0/2
A
A= $case->wrong_solutions
Aresult
11
00
105 0 for my $j ( 0 .. $#$wrong ) {
106 0 my $w = $wrong->[$j];
107 0 my $r = $g->replay( $case, $w->{calls} );
108 0 ▶ $self->_refuse( $f.': wrong_solutions['.$j.']', 'wrong solution "'.$w->{title}.'" passes' ) if $r->{status} eq 'passed';
Branch: 2 branches
BranchTrueFalseTotal
if $r->{"status"} eq "passed" 6 369 375
if $r->{"status"} eq "passed" 0 0 0
109 0 $check_gap->( $r, 'wrong_solutions['.$j.']' );
110 }
111  
112 0 ▶ $self->mock_runs->( $self, $case, $f ) if $self->has_mock_runs;
Branch: 2 branches
BranchTrueFalseTotal
if $self->has_mock_runs 312 3 315
if $self->has_mock_runs 0 0 0
113 0 return 1;
114 }
115  
116  
117 333 ▶sub _when_filters {
Subroutine _when_filters: called CC=3 SCAR=14.2
118 0 ▶ my ( $self, $when, $field ) = @_;
Subroutine _when_filters: not called CC=3 SCAR=14.2
119 0 ▶ $when ||= [];
Condition50%2/4
$when ||= []
l!l
12321
$when ||= []
l!l
00
MC/DC100%1/1
$when ||= []
$when
MC/DC0%0/1
$when ||= []
$when
Truth table100%2/2
A
A= $when
Aresult
11
00
Truth table0%0/2
A
A= $when
Aresult
11
00
120 0 $self->_filters( $when->[$_]{path}, $field.'.when['.$_.'].path' ) for 0 .. $#$when;
121 0 return;
122 }
123  
124 # the {name|filter} the world's value and interp_text replace; a filter is known when
125 # filter_value takes it
126 656 ▶sub _filters {
Subroutine _filters: called CC=9 SCAR=33.1
127 0 ▶ my ( $self, $v, $field ) = @_;
Subroutine _filters: not called CC=9 SCAR=33.1
128 0 ▶ if ( ref $v eq 'HASH' ) { $self->_filters( $v->{$_}, $field.'.'.$_ ) for sort keys %$v; return }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $v eq "HASH") 5 651 656
if (ref $v eq "HASH") 0 0 0
129 0 ▶ if ( ref $v eq 'ARRAY' ) { $self->_filters( $v->[$_], $field.'['.$_.']' ) for 0 .. $#$v; return }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $v eq "ARRAY") 0 651 651
if (ref $v eq "ARRAY") 0 0 0
130 0 ▶ return if !defined $v || ref $v;
Branch: 2 branches
BranchTrueFalseTotal
if not defined $v or ref $v 0 651 651
if not defined $v or ref $v 0 0 0
Condition16%1/6
not defined $v or ref $v
l!l&&r!l&&!r
00651
not defined $v or ref $v
l!l&&r!l&&!r
000
MC/DC0%0/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 table33%1/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
131 0 ▶ while ( $v =~ /\{[A-Za-z_][A-Za-z0-9_]*\|([a-z]+)\}/g ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v =~ /\{[A-Za-z_][A-Za-z0-9_]*\|([a-z]+)\}/g) 62 644 706
if ($v =~ /\{[A-Za-z_][A-Za-z0-9_]*\|([a-z]+)\}/g) 0 0 0
132 0 my $name = $1;
133 0 ▶ eval { filter_value( 'x', $name ); 1 }
Branch: 2 branches
BranchTrueFalseTotal
eval { do { filter_value("x", $name); 1 } } or $self->_refuse($field, q[unknown filter '] . $name . q[' (known: split, int, lc)]) 55 7 62
eval { do { filter_value("x", $name); 1 } } or $self->_refuse($field, q[unknown filter '] . $name . q[' (known: split, int, lc)]) 0 0 0
134 or $self->_refuse( $field, "unknown filter '".$name."' (known: split, int, lc)" );
135 }
136 0 return;
137 }
138  
139 324 ▶sub _renders {
Subroutine _renders: called CC=3 SCAR=15.0
140 0 ▶ my ( $self, $case, $tmpl, $field ) = @_;
Subroutine _renders: not called CC=3 SCAR=15.0
141 0 ▶ return unless defined $tmpl;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $tmpl 0 324 324
unless defined $tmpl 0 0 0
142 0 ▶ eval { Langertha::Holmgang::Template::render( $tmpl, $case->initial_state, {}, $self->grader->simulators ); 1 }
Branch: 2 branches
BranchTrueFalseTotal
eval { do { Langertha::Holmgang::Template::render($tmpl, $case->initial_state, scalar {}, $self->grader->simulators); 1 } } or $self->_refuse($field, 'output template (Kolon) broken: ' . $@ =~ s/\s+\z//r) 323 1 324
eval { do { Langertha::Holmgang::Template::render($tmpl, $case->initial_state, scalar {}, $self->grader->simulators); 1 } } or $self->_refuse($field, 'output template (Kolon) broken: ' . $@ =~ s/\s+\z//r) 0 0 0
143 or $self->_refuse( $field, 'output template (Kolon) broken: '.( $@ =~ s/\s+\z//r ) );
144 0 return;
145 }
146  
147 35 __PACKAGE__->meta->make_immutable;
148  
149 __END__
« blib/lib/Langertha/Holmgang/Sim/Linux/SshAccess.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Monitoring.pm »