script/html-anchor-audit

filter: Statementstmt 97.1% 69 / 71 Branchbran 86.6% 26 / 30 Conditioncond 85.0% 17 / 20 MC/DCmcdc 66.6% 6 / 9 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 91.2% 125 / 137 CC 1 SCAR 0.0
CC
1
Cov
93%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/HTML/Anchor/Audit.pm ↑ Summary
1 #!/usr/bin/env perl
2 11 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Encode qw(encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Getopt::Long qw(GetOptions);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use JSON::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use HTML::Anchor::Audit qw(audit_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 11 binmode STDOUT, ':raw';
11 11 binmode STDERR, ':raw';
12 11 my ($json, $help, $version, $max_bytes, $max_issues) = (0, 0, 0, 2097152, 500);
13 11 Getopt::Long::Configure('no_auto_abbrev', 'no_ignore_case');
14 11 my $ok = GetOptions('json' => \$json, 'help' => \$help, 'version' => \$version,
15 'max-bytes=i' => \$max_bytes, 'max-issues=i' => \$max_issues);
16 11 ▶if (!$ok || (!$help && !$version && !@ARGV) || $max_bytes < 1 || $max_issues < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ok && ($help || $version || @ARGV) or $max_bytes < 1 or $max_issues < 1) 2 9 11
Condition86%13/15
not $ok && ($help || $version || @ARGV) or $max_bytes < 1 or $max_issues < 1
l!l&&r!l&&!r
209
not $ok && ($help || $version || @ARGV) or $max_bytes < 1
l!l&&r!l&&!r
209
$ok && ($help || $version || @ARGV)
!ll&&!rl&&r
119
$help or $version or @ARGV
l!l&&r!l&&!r
271
$help or $version
l!l&&r!l&&!r
118
MC/DC66%4/6
not $ok && ($help || $version || @ARGV) or $max_bytes < 1 or $max_issues < 1
$ok $help $version @ARGV $max_bytes < 1 $max_issues < 1
Truth table45%5/11
not(A && B or C or D) or E or F
A= $okB= $helpC= $versionD= @ARGVE= $max_bytes < 1F= $max_issues < 1
ABCDEFresult
0XXXXX1
1000XX1
11XX1X1
101X1X1
10011X1
11XX011
101X011
1001011
11XX000
101X000
1001000
17 2 print STDERR "Usage: html-anchor-audit [--json] [--max-bytes N] [--max-issues N] FILE...\n";
18 2 exit 2;
19 }
20 9 ▶if ($help) {
Branch: 1 branch
BranchTrueFalseTotal
if ($help) 1 8 9
21 1 print "Usage: html-anchor-audit [--json] [--max-bytes N] [--max-issues N] FILE...\n",
22 "Offline check of UTF-8 HTML fragment links; input files are never modified.\n",
23 "Exit: 0 clean, 1 diagnostics, 2 input or usage error.\n";
24 1 exit 0;
25 }
26 8 ▶if ($version) { print "HTML::Anchor::Audit $HTML::Anchor::Audit::VERSION\n"; exit 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($version) 1 7 8
27 7 my (@files, $exit);
28 7 $exit = 0;
29 7 for my $file (@ARGV) {
30 9 my $entry = { file => $file };
31 eval {
32 9 ▶ die "URLs are not accepted\n" if $file =~ m{\A[A-Za-z][A-Za-z0-9+.-]*://};
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ m[\A[A-Za-z][A-Za-z0-9+.-]*://]u 1 8 9
33 8 ▶ die "Input must be a regular local file\n" if !-f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 1 7 8
34 7 ▶ open my $fh, '<:raw', $file or die "Cannot open file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $file or die "Cannot open file: $!\n" 7 0 7
35 7 my $bytes = '';
36 7 my $read = read($fh, $bytes, $max_bytes + 1);
37 7 ▶ die "Cannot read file: $!\n" if !defined($read);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $read 0 7 7
38 7 ▶ close $fh or die "Cannot close file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Cannot close file: $!\n" 7 0 7
39 7 ▶ die "Input exceeds max_bytes ($max_bytes)\n" if length($bytes) > $max_bytes;
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes > $max_bytes 1 6 7
40 6 $entry->{report} = audit_utf8($bytes, max_bytes => $max_bytes, max_issues => $max_issues);
41 5 ▶ $exit = 1 if $exit < 1 && $entry->{report}{statistics}{issue_count};
Branch: 1 branch
BranchTrueFalseTotal
if $exit < 1 and $entry->{"report"}{"statistics"}{"issue_count"} 2 3 5
Condition100%3/3
$exit < 1 and $entry->{"report"}{"statistics"}{"issue_count"}
!ll&&!rl&&r
122
MC/DC100%2/2
$exit < 1 and $entry->{"report"}{"statistics"}{"issue_count"}
$exit < 1 $entry->{"report"}{"statistics"}{"issue_count"}
Truth table100%3/3
A and B
A= $exit < 1B= $entry->{"report"}{"statistics"}{"issue_count"}
ABresult
0X0
100
111
42 5 1;
43 9 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { die "URLs are not accepted\n" if $file =~ m[\A[A-Za-z][A-Za-z0-9+.-]*://]u; die "Input must be a regular local file\n" unless -f $file; open my $fh, "<:raw", $file or die "Cannot open file: $!\n"; my $bytes = ""; my $read = read($fh, $bytes, $max_bytes + 1); die "Cannot read file: $!\n" unless defined $read; close $fh or die "Cannot close file: $!\n"; die "Input exceeds max_bytes ($max_bytes)\n" if length $bytes > $max_bytes; $entry->{"report"} = audit_utf8($bytes, "max_bytes", $max_bytes, "max_issues", $max_issues); $exit = 1 if $exit < 1 and $entry->{"report"}{"statistics"}{"issue_count"}; 1 } } or do { my $error = $@ || "Unknown input error"; $error =~ s/\s+at \S+ line \d+\.?\s*\z//u; $error =~ s/\s+\z//u; $entry->{"error"} = $error; $exit = 2 } 5 4 9
44 4 ▶ my $error = $@ || 'Unknown input error';
Condition50%1/2
$@ || 'Unknown input error'
l!l
40
MC/DC0%0/1
$@ || 'Unknown input error'
$@
Truth table50%1/2
A
A= $@
Aresult
11
00
45 4 $error =~ s/\s+at \S+ line \d+\.?\s*\z//;
46 4 $error =~ s/\s+\z//;
47 4 $entry->{error} = $error;
48 4 $exit = 2;
49 };
50 9 push @files, $entry;
51 9 ▶ next if $json;
Branch: 1 branch
BranchTrueFalseTotal
if $json 7 2 9
52 0 ▶ if ($entry->{error}) { print STDERR encode('UTF-8', "$file: $entry->{error}\n"); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->{"error"}) 0 2 2
53 2 for my $issue (@{ $entry->{report}{issues} }) {
54 1 my $label = $issue->{value};
55 1 $label =~ s/[\x00-\x1F\x7F]/?/g;
56 1 print encode('UTF-8', "$file:$issue->{line}:$issue->{column}: $issue->{code}: $label\n");
57 }
58 2 my $s = $entry->{report}{statistics};
59 2 print encode('UTF-8', "$file: $s->{issue_count} issue(s), $s->{checked_reference_count} checked, $s->{ignored_reference_count} ignored\n");
60 2 ▶ print "Diagnostic list truncated; use --max-issues to raise the limit.\n" if $s->{truncated};
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"truncated"} 1 1 2
61 }
62 7 ▶if ($json) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json) 5 2 7
63 5 print JSON::PP->new->utf8->canonical->pretty->encode({ version => $HTML::Anchor::Audit::VERSION, files => \@files });
64 }
65 7 exit $exit;
« blib/lib/HTML/Anchor/Audit.pm ↑ Summary