| 1 | package Devel::XSCover::Gcov; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 43 | ▶ | use 5.020; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 43 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 43 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 43 | ▶ | use Cwd (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 43 | ▶ | use File::Find (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 43 | ▶ | use File::Path (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 43 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 43 | ▶ | use IPC::Open3 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 43 | ▶ | use Symbol (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 43 | ▶ | use Devel::XSCover::Flow (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 43 | our $VERSION = '0.09'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 83 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 83 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 20 | 83 | my $self = bless { | |||||||||||||||||||||||||||
| 21 | dir => '.', | ||||||||||||||||||||||||||||
| 22 | gcov => ['gcov'], | ||||||||||||||||||||||||||||
| 23 | ignore => [], | ||||||||||||||||||||||||||||
| 24 | generated => [], | ||||||||||||||||||||||||||||
| 25 | xsubs => {}, | ||||||||||||||||||||||||||||
| 26 | inverse => {}, | ||||||||||||||||||||||||||||
| 27 | skip => [qw(blib cover_db .git)], | ||||||||||||||||||||||||||||
| 28 | save => undef, | ||||||||||||||||||||||||||||
| 29 | conditions => 0, | ||||||||||||||||||||||||||||
| 30 | flow => '', | ||||||||||||||||||||||||||||
| 31 | dry => 0, | ||||||||||||||||||||||||||||
| 32 | silent => 0, | ||||||||||||||||||||||||||||
| 33 | }, $class; | ||||||||||||||||||||||||||||
| 34 | 83 | $self->{$_} = $args{$_} for keys %args; | |||||||||||||||||||||||||||
| 35 | 83 | return $self; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 43 | ▶ | sub find_gcda { | ||||||||||||||||||||||||||
|
Subroutine
find_gcda: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 43 | my ($self) = @_; | |||||||||||||||||||||||||||
| 40 | 43 | my %skip = map { $_ => 1 } @{ $self->{skip} }; | |||||||||||||||||||||||||||
| 41 | 43 | my $top = _slashes($self->{dir}); | |||||||||||||||||||||||||||
| 42 | 43 | my @found; | |||||||||||||||||||||||||||
| 43 | File::Find::find({ | ||||||||||||||||||||||||||||
| 44 | no_chdir => 1, | ||||||||||||||||||||||||||||
| 45 | 581 | ▶ | wanted => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 46 | 581 | ▶ | if (-d $_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 150 | my $base = (File::Spec->splitdir($_))[-1]; | |||||||||||||||||||||||||||
| 48 | 150 | ▶ | $File::Find::prune = 1 if $skip{$base} && _slashes($_) ne $top; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$skip{$base} and _slashes($_) ne $top
MC/DC100%2/2
$skip{$base} and _slashes($_) ne $top
$skip{$base}
_slashes($_) ne $top
Truth table100%3/3
A and B
A= $skip{$base}B= _slashes($_) ne $top
| |||||||||||||||||||||||||||||
| 49 | 150 | return; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 431 | ▶ | push @found, _slashes(File::Spec->abs2rel($_, $self->{dir})) if /\.gcda\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | }, | ||||||||||||||||||||||||||||
| 53 | 43 | }, $self->{dir}); | |||||||||||||||||||||||||||
| 54 | 43 | return sort @found; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 25 | ▶ | sub run_gcov { | ||||||||||||||||||||||||||
|
Subroutine
run_gcov: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 25 | my ($self, $gcda) = @_; | |||||||||||||||||||||||||||
| 59 | 25 | (my $stem = $gcda) =~ s/\.gcda\z//; | |||||||||||||||||||||||||||
| 60 | 25 | my $name = (File::Spec->splitpath($stem))[2]; | |||||||||||||||||||||||||||
| 61 | 25 | ▶ | my @cmd = (@{ $self->{gcov} }, '-abct', ($self->{conditions} ? '--conditions' : ()), '-o', $gcda, $name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 25 | $self->_say("xs_cover: running @cmd"); | |||||||||||||||||||||||||||
| 63 | 25 | ▶ | return '' if $self->{dry}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 20 | my $here = Cwd::getcwd(); | |||||||||||||||||||||||||||
| 65 | 20 | ▶ | chdir $self->{dir} or die "xs_cover: cannot chdir to $self->{dir}: $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 19 | my $text = $self->_capture(@cmd); | |||||||||||||||||||||||||||
| 67 | 19 | chdir $here; | |||||||||||||||||||||||||||
| 68 | 19 | ▶ | die "xs_cover: @cmd produced nothing in $self->{dir}\n" unless defined $text && length $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $text and length $text
MC/DC100%2/2
defined $text and length $text
defined $text
length $text
Truth table100%3/3
A and B
A= defined $textB= length $text
| |||||||||||||||||||||||||||||
| 69 | 16 | ▶ | if ($self->{save}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 14 | File::Path::make_path($self->{save}); | |||||||||||||||||||||||||||
| 71 | 14 | (my $flat = $stem) =~ s{[/\\]}{#}g; | |||||||||||||||||||||||||||
| 72 | 14 | my $path = File::Spec->catfile($self->{save}, "$flat.gcov.txt"); | |||||||||||||||||||||||||||
| 73 | 14 | ▶ | open my $fh, '>', $path or die "xs_cover: cannot write $path: $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 13 | print $fh $text; | |||||||||||||||||||||||||||
| 75 | 13 | close $fh; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 15 | return $text; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 25 | ▶ | sub run_flow { | ||||||||||||||||||||||||||
|
Subroutine
run_flow: called CC=12 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 25 | my ($self, $gcda) = @_; | |||||||||||||||||||||||||||
| 82 | 25 | ▶ | my $kind = $self->{flow} or return ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 12 | (my $stem = $gcda) =~ s/\.gcda\z//; | |||||||||||||||||||||||||||
| 84 | 12 | my $name = (File::Spec->splitpath($stem))[2]; | |||||||||||||||||||||||||||
| 85 | my @cmd = $kind eq 'llvm' | ||||||||||||||||||||||||||||
| 86 | 7 | ? (@{ $self->{gcov} }, '--dump', '-n', '-o', $gcda, $name) | |||||||||||||||||||||||||||
| 87 | 12 | ▶ | : (@{ $self->{gcov} }, '-abct', '--json-format', ($self->{conditions} ? '--conditions' : ()), '-o', $gcda, $name); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 88 | 12 | $self->_say("xs_cover: running @cmd"); | |||||||||||||||||||||||||||
| 89 | 12 | ▶ | return '' if $self->{dry}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 10 | my $here = Cwd::getcwd(); | |||||||||||||||||||||||||||
| 91 | 10 | ▶ | chdir $self->{dir} or die "xs_cover: cannot chdir to $self->{dir}: $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 9 | ▶ | my $text = $kind eq 'llvm' ? $self->_capture_stderr(@cmd) : $self->_capture(@cmd); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 9 | chdir $here; | |||||||||||||||||||||||||||
| 94 | 9 | ▶ | unless (defined $text && length $text) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $text and length $text
MC/DC100%2/2
defined $text and length $text
defined $text
length $text
Truth table100%3/3
A and B
A= defined $textB= length $text
| |||||||||||||||||||||||||||||
| 95 | 3 | warn "xs_cover: @cmd produced no flow graph in $self->{dir}, branches come from gcov's blocks alone\n"; | |||||||||||||||||||||||||||
| 96 | 3 | return ''; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 6 | ▶ | if ($self->{save}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 3 | File::Path::make_path($self->{save}); | |||||||||||||||||||||||||||
| 100 | 3 | (my $flat = $stem) =~ s{[/\\]}{#}g; | |||||||||||||||||||||||||||
| 101 | 3 | ▶ | my $path = File::Spec->catfile($self->{save}, "$flat.flow." . ($kind eq 'llvm' ? 'txt' : 'json')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 3 | ▶ | open my $fh, '>', $path or die "xs_cover: cannot write $path: $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 2 | print $fh $text; | |||||||||||||||||||||||||||
| 104 | 2 | close $fh; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 5 | return $text; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 18 | ▶ | sub attach_decisions { | ||||||||||||||||||||||||||
|
Subroutine
attach_decisions: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 110 | 18 | my ($self, $parsed, $text) = @_; | |||||||||||||||||||||||||||
| 111 | 18 | ▶ | return 0 unless defined $text && length $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $text and length $text
MC/DC100%2/2
defined $text and length $text
defined $text
length $text
Truth table100%3/3
A and B
A= defined $textB= length $text
| |||||||||||||||||||||||||||||
| 112 | 4 | my $flow = Devel::XSCover::Flow->new(dir => $self->{dir}, silent => $self->{silent}); | |||||||||||||||||||||||||||
| 113 | 4 | ▶ | my $graph = $self->{flow} eq 'llvm' ? $flow->parse_llvm($text, $parsed, $self->{xsubs}) : $flow->parse_gcc($text); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 4 | my $decisions = $flow->decisions($graph, $self->{inverse}); | |||||||||||||||||||||||||||
| 115 | 4 | my $n = 0; | |||||||||||||||||||||||||||
| 116 | 4 | for my $file (keys %$decisions) { | |||||||||||||||||||||||||||
| 117 | 8 | ▶ | next unless $parsed->{$file}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 7 | $parsed->{$file}{decisions} = $decisions->{$file}; | |||||||||||||||||||||||||||
| 119 | 7 | $n++; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 4 | return $n; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 48 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=27 SCAR=33.0
Pod
documented
| |||||||||||||||||||||||||||||
| 125 | 48 | my ($self, $text) = @_; | |||||||||||||||||||||||||||
| 126 | 48 | my %files; | |||||||||||||||||||||||||||
| 127 | 48 | my ($file, $pending, $block, $last_line, $decision); | |||||||||||||||||||||||||||
| 128 | 48 | for my $line (split /\n/, $text) { | |||||||||||||||||||||||||||
| 129 | 113873 | ▶ | if ($line =~ /^\s*-:\s*0:Source:(.*?)\s*$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 155 | $file = $1; | |||||||||||||||||||||||||||
| 131 | 155 | ▶ | $files{$file} //= { lines => {}, functions => [], blocks => [], conditions => [] }; | ||||||||||||||||||||||||||
|
Condition100%2/2
$files{$file} //= {"lines", {}, "functions", [], "blocks", [], "conditions", []}
MC/DC100%1/1
$files{$file} //= {"lines", {}, "functions", [], "blocks", [], "conditions", []}
$files{$file}
Truth table100%2/2
A
A= $files{$file}
| |||||||||||||||||||||||||||||
| 132 | 155 | ($pending, $block, $last_line, $decision) = (undef, undef, undef, undef); | |||||||||||||||||||||||||||
| 133 | 155 | next; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | 113718 | ▶ | next unless defined $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 113714 | ▶ | next if $line =~ /^\s*-:\s*0:/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 113263 | ▶ | if ($line =~ /^function\s+(\S+)\s+called\s+(\d+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 332 | $pending = { name => $1, count => $2 }; | |||||||||||||||||||||||||||
| 139 | 332 | next; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | 112931 | ▶ | if ($line =~ /^\s*\S+:\s*(\d+)-block\s+\d+/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 2948 | $block = { line => $1, arms => [] }; | |||||||||||||||||||||||||||
| 143 | 2948 | push @{ $files{$file}{blocks} }, $block; | |||||||||||||||||||||||||||
| 144 | 2948 | next; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | 109983 | ▶ | if ($line =~ /^branch\s+\d+\s+(?:taken\s+(\d+)%?|never executed)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 1606 | ▶ | my $count = $1 // 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$1 // 0
MC/DC100%1/1
$1 // 0
$1
Truth table100%2/2
A
A= $1
| |||||||||||||||||||||||||||||
| 148 | 1606 | ▶ | unless ($block) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 54 | ▶ | $block = { line => $last_line // 0, arms => [] }; | ||||||||||||||||||||||||||
|
Condition100%2/2
$last_line // 0
MC/DC100%1/1
$last_line // 0
$last_line
Truth table100%2/2
A
A= $last_line
| |||||||||||||||||||||||||||||
| 150 | 54 | push @{ $files{$file}{blocks} }, $block; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | 1606 | push @{ $block->{arms} }, $count; | |||||||||||||||||||||||||||
| 153 | 1606 | next; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | 108377 | ▶ | if ($line =~ /^condition outcomes covered (\d+)\/(\d+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 111 | ▶ | $decision = { line => $last_line // 0, covered => $1, total => $2, missing => {} }; | ||||||||||||||||||||||||||
|
Condition100%2/2
$last_line // 0
MC/DC100%1/1
$last_line // 0
$last_line
Truth table100%2/2
A
A= $last_line
| |||||||||||||||||||||||||||||
| 157 | 111 | push @{ $files{$file}{conditions} }, $decision; | |||||||||||||||||||||||||||
| 158 | 111 | next; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | 108266 | ▶ | if ($line =~ /^condition\s+(\d+) not covered \(([^)]+)\)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 102 | $decision->{missing}{$1}{$_} = 1 for split ' ', $2; | |||||||||||||||||||||||||||
| 162 | 102 | next; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | 108164 | ▶ | next if $line =~ /^(?:call|unconditional)\s/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 107998 | ▶ | if ($line =~ /^\s*([^:\s]+):\s*(\d+):/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 107997 | my ($count, $number) = ($1, $2); | |||||||||||||||||||||||||||
| 167 | 107997 | $last_line = $number; | |||||||||||||||||||||||||||
| 168 | 107997 | $block = undef; | |||||||||||||||||||||||||||
| 169 | 107997 | ▶ | if ($pending) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 332 | $pending->{line} = $number; | |||||||||||||||||||||||||||
| 171 | 332 | push @{ $files{$file}{functions} }, $pending; | |||||||||||||||||||||||||||
| 172 | 332 | $pending = undef; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | 107997 | ▶ | next if $count eq '-'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 3224 | ▶ | $count = 0 if $count eq '#####' || $count eq '====='; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$count eq "#####" or $count eq "====="
MC/DC100%2/2
$count eq "#####" or $count eq "====="
$count eq "#####"
$count eq "====="
Truth table100%3/3
A or B
A= $count eq "#####"B= $count eq "====="
| |||||||||||||||||||||||||||||
| 176 | 3224 | $count =~ s/\*\z//; | |||||||||||||||||||||||||||
| 177 | 3224 | ▶ | next unless $count =~ /^\d+\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 3223 | $files{$file}{lines}{$number} = $count; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | 48 | for my $f (values %files) { | |||||||||||||||||||||||||||
| 182 | 154 | $f->{blocks} = [ grep { @{ $_->{arms} } } @{ $f->{blocks} } ]; | |||||||||||||||||||||||||||
| 183 | 154 | for my $d (@{ $f->{conditions} }) { | |||||||||||||||||||||||||||
| 184 | 111 | my $missing = delete $d->{missing}; | |||||||||||||||||||||||||||
| 185 | 111 | ▶ | $d->{terms} = [ map { { true => $missing->{$_}{true} ? 0 : 1, false => $missing->{$_}{false} ? 0 : 1 } } 0 .. int($d->{total} / 2) - 1 ]; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | 48 | return \%files; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 35 | ▶ | sub filter { | ||||||||||||||||||||||||||
|
Subroutine
filter: called CC=13 SCAR=25.6
Pod
documented
| |||||||||||||||||||||||||||||
| 192 | 35 | my ($self, $files, $gcda) = @_; | |||||||||||||||||||||||||||
| 193 | 35 | my $root = Cwd::abs_path($self->{dir}); | |||||||||||||||||||||||||||
| 194 | 35 | ▶ | $root = File::Spec->rel2abs($self->{dir}) unless defined $root; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | 35 | $root = _slashes($root); | |||||||||||||||||||||||||||
| 196 | 35 | my %generated = map { $_ => 1 } @{ $self->{generated} }; | |||||||||||||||||||||||||||
| 197 | 35 | my @ignore = map { qr/$_/ } @{ $self->{ignore} }; | |||||||||||||||||||||||||||
| 198 | 35 | ▶ | my ($vol, $beside) = defined $gcda ? File::Spec->splitpath($gcda) : ('', ''); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | 35 | my (%kept, %aside); | |||||||||||||||||||||||||||
| 200 | 35 | for my $name (sort keys %$files) { | |||||||||||||||||||||||||||
| 201 | 123 | my $rel = $name; | |||||||||||||||||||||||||||
| 202 | 123 | ▶ | if (File::Spec->file_name_is_absolute($rel)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 203 | 37 | my $abs = Cwd::abs_path($rel); | |||||||||||||||||||||||||||
| 204 | 37 | ▶ | $abs = $rel unless defined $abs; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | 37 | $abs = _slashes($abs); | |||||||||||||||||||||||||||
| 206 | 37 | ▶ | next unless index($abs, "$root/") == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 4 | $rel = File::Spec->abs2rel($abs, $root); | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | ▶ | elsif (length $beside && !-f File::Spec->catfile($self->{dir}, $rel)) { | |||||||||||||||||||||||||||
|
Condition100%3/3
length $beside and not -f "File::Spec"->catfile($self->{"dir"}, $rel)
MC/DC100%2/2
length $beside and not -f "File::Spec"->catfile($self->{"dir"}, $rel)
length $beside
not -f "File::Spec"->catfile($self->{"dir"}, $rel)
Truth table100%3/3
A and not(B)
A= length $besideB= not -f "File::Spec"->catfile($self->{"dir"}, $rel)
| |||||||||||||||||||||||||||||
| 210 | 3 | my $near = File::Spec->catpath($vol, $beside, $rel); | |||||||||||||||||||||||||||
| 211 | 3 | ▶ | $rel = $near if -f File::Spec->catfile($self->{dir}, $near); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | 90 | $rel =~ s{^\./+}{}; | |||||||||||||||||||||||||||
| 214 | 90 | $rel = _slashes(File::Spec->canonpath($rel)); | |||||||||||||||||||||||||||
| 215 | 90 | ▶ | next if (File::Spec->splitpath($rel))[2] eq 'ppport.h'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 86 | ▶ | if ($generated{$rel}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | 12 | $aside{$rel} = $files->{$name}; | |||||||||||||||||||||||||||
| 218 | 12 | next; | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | 74 | ▶ | next if grep { $rel =~ $_ } @ignore; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 72 | $kept{$rel} = $files->{$name}; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | 35 | return (\%kept, \%aside); | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 13 | ▶ | sub read { | ||||||||||||||||||||||||||
|
Subroutine
read: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 227 | 13 | my ($self) = @_; | |||||||||||||||||||||||||||
| 228 | 13 | my @objects; | |||||||||||||||||||||||||||
| 229 | 13 | for my $gcda ($self->find_gcda) { | |||||||||||||||||||||||||||
| 230 | 15 | my $text = $self->run_gcov($gcda); | |||||||||||||||||||||||||||
| 231 | 15 | ▶ | next unless length $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | 13 | my $parsed = $self->parse($text); | |||||||||||||||||||||||||||
| 233 | 13 | $self->attach_decisions($parsed, $self->run_flow($gcda)); | |||||||||||||||||||||||||||
| 234 | 13 | my ($files, $generated) = $self->filter($parsed, $gcda); | |||||||||||||||||||||||||||
| 235 | 13 | push @objects, { object => $gcda, files => $files, generated => $generated }; | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | 13 | ▶ | $self->_say(sprintf 'xs_cover: read %d object%s', scalar @objects, @objects == 1 ? '' : 's'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 13 | return @objects; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 22 | ▶ | sub _capture { | ||||||||||||||||||||||||||
|
Subroutine
_capture: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 242 | 22 | my ($self, @cmd) = @_; | |||||||||||||||||||||||||||
| 243 | 22 | return $self->_run_capture(0, @cmd); | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 4 | ▶ | sub _capture_stderr { | ||||||||||||||||||||||||||
|
Subroutine
_capture_stderr: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 247 | 4 | my ($self, @cmd) = @_; | |||||||||||||||||||||||||||
| 248 | 4 | return $self->_run_capture(1, @cmd); | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 26 | ▶ | sub _run_capture { | ||||||||||||||||||||||||||
|
Subroutine
_run_capture: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 252 | 26 | my ($self, $stderr, @cmd) = @_; | |||||||||||||||||||||||||||
| 253 | 26 | local *NULL; | |||||||||||||||||||||||||||
| 254 | 26 | open NULL, '>', File::Spec->devnull; | |||||||||||||||||||||||||||
| 255 | 26 | my ($in, $out, $err) = (undef, Symbol::gensym(), Symbol::gensym()); | |||||||||||||||||||||||||||
| 256 | 26 | ▶ | my $pid = eval { IPC::Open3::open3($in, $stderr ? '>&NULL' : $out, $stderr ? $err : '>&NULL', @cmd) }; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 257 | 26 | ▶ | return undef unless $pid; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | 24 | close $in; | |||||||||||||||||||||||||||
| 259 | 24 | ▶ | my $fh = $stderr ? $err : $out; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | 24 | my $text = do { local $/; <$fh> }; | |||||||||||||||||||||||||||
| 261 | 24 | close $fh; | |||||||||||||||||||||||||||
| 262 | 24 | waitpid $pid, 0; | |||||||||||||||||||||||||||
| 263 | 24 | return $text; | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 260 | ▶ | sub _slashes { | ||||||||||||||||||||||||||
|
Subroutine
_slashes: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 267 | 260 | my ($path) = @_; | |||||||||||||||||||||||||||
| 268 | 260 | ▶ | $path =~ s{\\}{/}g if $^O eq 'MSWin32'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | 260 | return $path; | |||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 50 | ▶ | sub _say { | ||||||||||||||||||||||||||
|
Subroutine
_say: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 273 | 50 | my ($self, $line) = @_; | |||||||||||||||||||||||||||
| 274 | 50 | ▶ | print "$line\n" unless $self->{silent}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 43 | 1; | |||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | __END__ | ||||||||||||||||||||||||||||