blib/lib/Zuzu/Test/ZPathFacelessPortDiagnostics.pm

filter: Statementstmt 100% 46 / 46 Branchbran 64.2% 9 / 14 Conditioncond 54.5% 6 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 3 totaltotal 77.9% 67 / 86 CC 16 SCAR 17.8
CC
16
Cov
86%
summarize_failed_queries
8.3
format_summary_lines
6.5
classify_query
4.0
CRAP 5.9
« blib/lib/Zuzu/Web/PSGI/CLI.pm ↑ Summary blib/lib/Zuzu/Value/Bag.pm »
1 package Zuzu::Test::ZPathFacelessPortDiagnostics;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.007002';
7  
8 1 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our @EXPORT_OK = qw(
11 classify_query
12 summarize_failed_queries
13 format_summary_lines
14 );
15  
16 1 my @CATEGORY_RULES = (
17 {
18 tag => 'function-node-set-coercion',
19 re => qr{\b(?:count|sum|min|max|join|replace|substring|index-of|string-length|matches|format)\s*\(},
20 },
21 {
22 tag => 'position-key-context',
23 re => qr{\b(?:index|key)\s*\(|#\d+|\.\.\*|\.\.|\bis-first\s*\(|\bis-last\s*\(},
24 },
25 {
26 tag => 'xml-attributes-namespaces',
27 re => qr{\@|\burl\s*\(|\brdf:},
28 },
29 {
30 tag => 'comparison-truthiness',
31 re => qr{==|!=|\[[^\]]*\]|\btype\s*\(},
32 },
33 {
34 tag => 'numeric-tokenization',
35 re => qr{\bnumber\s*\(|\d\s*[+\-*\/]\s*\d|\d\.\d},
36 },
37 );
38  
39 12 ▶sub classify_query {
Subroutine classify_query: called CC=4 SCAR=13.9
Pod undocumented
40 12 my ( $query ) = @_;
41  
42 12 ▶ $query = '' if not defined $query;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $query 0 12 12
43  
44 12 for my $rule ( @CATEGORY_RULES ) {
45 36 ▶ if ( $query =~ $rule->{re} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($query =~ /$rule->{"re"}/) 11 25 36
46 11 return $rule->{tag};
47 }
48 }
49  
50 1 return 'other';
51 }
52  
53 1 ▶sub summarize_failed_queries {
Subroutine summarize_failed_queries: called CC=8 SCAR=21.1
Pod undocumented
54 1 my ( $queries ) = @_;
55  
56 1 ▶ $queries = [] if not defined $queries;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $queries 0 1 1
57  
58 1 my %stats;
59 1 for my $query ( @{ $queries } ) {
60 6 my $tag = classify_query( $query );
61 6 $stats{ $tag }{count}++;
62 6 ▶ if ( not defined $stats{ $tag }{examples} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $stats{$tag}{"examples"}) 5 1 6
63 5 $stats{ $tag }{examples} = [];
64 }
65 6 ▶ if ( scalar @{ $stats{ $tag }{examples} } < 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$stats{$tag}{"examples"};} < 3) 6 0 6
66 6 push @{ $stats{ $tag }{examples} }, $query;
67 }
68 }
69  
70 my @summary = map {
71 1 {
72 tag => $_,
73 count => $stats{$_}{count} || 0,
74 5 ▶ examples => $stats{$_}{examples} || [],
Condition50%2/4
$stats{$_}{'count'} || 0
l!l
50
$stats{$_}{'examples'} || []
l!l
50
MC/DC0%0/1
$stats{$_}{'count'} || 0
$stats{$_}{'count'}
MC/DC0%0/1
$stats{$_}{'examples'} || []
$stats{$_}{'examples'}
Truth table50%1/2
A
A= $stats{$_}{'count'}
Aresult
11
00
Truth table50%1/2
A
A= $stats{$_}{'examples'}
Aresult
11
00
75 }
76 } keys %stats;
77  
78 @summary = sort {
79 1 $b->{count} <=> $a->{count}
80 or $a->{tag} cmp $b->{tag}
81 8 ▶ } @summary;
Condition66%2/3
$Zuzu::Test::ZPathFacelessPortDiagnostics::b->{'count'} <=> $Zuzu::Test::ZPathFacelessPortDiagnostics::a->{'count'} || $Zuzu::Test::ZPathFacelessPortDiagnostics::a->{'tag'} cmp $Zuzu::Test::ZPathFacelessPortDiagnostics::b->{'tag'}
l!l&&r!l&&!r
350
MC/DC0%0/2
$Zuzu::Test::ZPathFacelessPortDiagnostics::b->{'count'} <=> $Zuzu::Test::ZPathFacelessPortDiagnostics::a->{'count'} || $Zuzu::Test::ZPathFacelessPortDiagnostics::a->{'tag'} cmp $Zuzu::Test::ZPathFacelessPortDiagnostics::b->{'tag'}
$Zuzu::Test::ZPathFacelessPortDiagnostics::b->{'count'} <=> $Zuzu::Test::ZPathFacelessPortDiagnostics::a->{'count'} $Zuzu::Test::ZPathFacelessPortDiagnostics::a->{'tag'} cmp $Zuzu::Test::ZPathFacelessPortDiagnostics::b->{'tag'}
Truth table66%2/3
A || B
A= $Zuzu::Test::ZPathFacelessPortDiagnostics::b->{'count'} <=> $Zuzu::Test::ZPathFacelessPortDiagnostics::a->{'count'}B= $Zuzu::Test::ZPathFacelessPortDiagnostics::a->{'tag'} cmp $Zuzu::Test::ZPathFacelessPortDiagnostics::b->{'tag'}
ABresult
1X1
011
000
82  
83 1 return \@summary;
84 }
85  
86 1 ▶sub format_summary_lines {
Subroutine format_summary_lines: called CC=6 SCAR=18.7
Pod undocumented
87 1 my ( $summary ) = @_;
88  
89 1 ▶ $summary = [] if not defined $summary;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $summary 0 1 1
90  
91 1 my @lines;
92 1 for my $row ( @{ $summary } ) {
93 5 ▶ my $sample = join '; ', @{ $row->{examples} || [] };
Condition50%1/2
$row->{'examples'} || []
l!l
50
MC/DC0%0/1
$row->{'examples'} || []
$row->{'examples'}
Truth table50%1/2
A
A= $row->{'examples'}
Aresult
11
00
94 push @lines, sprintf(
95 "%s: %d (examples: %s)",
96 $row->{tag},
97 5 ▶ $row->{count} || 0,
Branch: 1 branch
BranchTrueFalseTotal
$sample eq '' ? : 0 5 5
Condition50%1/2
$row->{'count'} || 0
l!l
50
MC/DC0%0/1
$row->{'count'} || 0
$row->{'count'}
Truth table50%1/2
A
A= $row->{'count'}
Aresult
11
00
98 $sample eq '' ? 'n/a' : $sample,
99 );
100 }
101  
102 1 return \@lines;
103 }
104  
105 1 1;
106  
107 =pod
108  
109 =head1 COPYRIGHT AND LICENCE
110  
111 B<< Zuzu::Test::ZPathFacelessPortDiagnostics >> is copyright Toby Inkster.
112  
113 It is free software; you may redistribute it and/or modify it under
114 the terms of either the Artistic License 1.0 or the GNU General Public
115 License version 2.
116  
117 =cut
« blib/lib/Zuzu/Web/PSGI/CLI.pm ↑ Summary blib/lib/Zuzu/Value/Bag.pm »