/usr/lib/perl5/Devel/Cover/Test.pm is in libdevel-cover-perl 0.77-1ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | # Copyright 2002-2011, Paul Johnson (pjcj@cpan.org)
# This software is free. It is licensed under the same terms as Perl itself.
# The latest version of this software should be available from my homepage:
# http://www.pjcj.net
package Devel::Cover::Test;
use strict;
use warnings;
our $VERSION = "0.77";
use Carp;
use File::Spec;
use Test;
use Devel::Cover::Inc 0.77;
my $Test;
sub new
{
my $class = shift;
my $test = shift;
croak "No test specified" unless $test;
my %params = @_;
my $criteria = delete $params{criteria} ||
"statement branch condition subroutine";
my $self =
{
test => $test,
criteria => $criteria,
skip => "",
uncoverable_file => "",
select => "",
ignore => "",
run_test_at_end => 1,
%params
};
$Test = bless $self, $class;
$self->get_params
}
sub get_params
{
my $self = shift;
my $test = $self->test_file;
if (open T, $test)
{
while (<T>)
{
$self->{$1} = $2 if /__COVER__\s+(\w+)\s+(.*)/;
}
close T or die "Cannot close $test: $!";
}
$self->{select} ||= "-select $self->{test}";
$self->{test_parameters} = "$self->{select}"
. " -ignore blib Devel/Cover $self->{ignore}"
. " -merge 0 -coverage $self->{criteria} "
. ($self->{test_parameters} || "");
$self->{criteria} =~ s/-\w+//g;
$self->{cover_db} = "$Devel::Cover::Inc::Base/t/e2e/cover_db_$self->{test}/";
mkdir $self->{cover_db};
$self->{cover_parameters} = join(" ", map "-coverage $_",
split " ", $self->{criteria})
. " -report text " . $self->{cover_db};
$self->{cover_parameters} .= " -uncoverable_file $self->{uncoverable_file}"
if $self->{uncoverable_file};
$self->{skip} = $self->{skip_reason}
if exists $self->{skip_test} && eval "{$self->{skip_test}}";
$self
}
sub test { $Test }
sub shell_quote
{
my ($item) = @_;
# properly quote the item
$^O eq "MSWin32" ? (/ / and $_ = qq("$_")) : s/ /\\ /g for $item;
$item
};
sub perl
{
my $self = shift;
my $perl = shell_quote $Devel::Cover::Inc::Perl;
my $base = $Devel::Cover::Inc::Base;
$perl .= " " . shell_quote "-I$base/$_" for "", "blib/lib", "blib/arch";
$perl
}
sub test_command
{
my $self = shift;
my $c = $self->perl;
unless ($ENV{DEVEL_COVER_NO_COVERAGE})
{
$c .= " -MDevel::Cover=" .
join(",", '-db', $self->{cover_db}, split ' ', $self->{test_parameters})
}
$c .= " " . shell_quote $self->test_file;
$c .= " " . $self->test_file_parameters;
$c
}
sub cover_command
{
my $self = shift;
my $b = shell_quote $Devel::Cover::Inc::Base;
my $c = $self->perl . " $b/cover $self->{cover_parameters}";
$c
}
sub test_file
{
my $self = shift;
"$Devel::Cover::Inc::Base/tests/$self->{test}"
}
sub test_file_parameters
{
my $self = shift;
exists $self->{test_file_parameters} ? $self->{test_file_parameters} : ""
}
sub cover_gold
{
my $self = shift;
my $test = $self->{golden_test} || $self->{test};
my $td = "$Devel::Cover::Inc::Base/test_output/cover";
opendir D, $td or die "Can't opendir $td: $!";
my @versions = sort { $a <=> $b }
map { /^$test\.(5\.\d+)$/ ? $1 : () }
readdir D;
closedir D or die "Can't closedir $td: $!";
my $v = "5.0";
for (@versions)
{
last if $_ > $];
$v = $_;
}
# die "Can't find golden results for $test" if $v eq "5.0";
$v = $ENV{DEVEL_COVER_GOLDEN_VERSION}
if exists $ENV{DEVEL_COVER_GOLDEN_VERSION};
"$td/$test.$v"
}
sub run_command
{
my $self = shift;
my ($command) = @_;
my $debug = $ENV{DEVEL_COVER_DEBUG} || 0;
print STDERR "Running test [$command]\n" if $debug;
open T, "$command 2>&1 |" or die "Cannot run $command: $!";
while (<T>)
{
print STDERR if $debug;
}
close T or die "Cannot close $command: $!";
1
}
sub run_test
{
my $self = shift;
$self->{run_test_at_end} = 0;
my $debug = $ENV{DEVEL_COVER_DEBUG} || 0;
my $gold = $self->cover_gold;
open I, $gold or die "Cannot open $gold: $!";
my @cover = <I>;
close I or die "Cannot close $gold: $!";
$self->{cover} = \@cover;
# print STDERR "gold from $gold\n", @cover if $debug;
eval "use Test::Differences";
my $differences = $INC{"Test/Differences.pm"};
plan tests => ($differences || $self->{skip})
? 1
: exists $self->{tests}
? $self->{tests}->(scalar @cover)
: scalar @cover;
if ($self->{skip})
{
skip($self->{skip}, 1);
return;
}
local $ENV{PERL5OPT};
$self->{run_test}
? $self->{run_test}->($self)
: $self->run_command($self->test_command);
$self->run_cover unless $self->{no_report};
$self->{end}->() if $self->{end};
}
sub run_cover
{
my $self = shift;
my $debug = $ENV{DEVEL_COVER_DEBUG} || 0;
eval "use Test::Differences";
my $differences = $INC{"Test/Differences.pm"};
my $cover_com = $self->cover_command;
print STDERR "Running cover [$cover_com]\n" if $debug;
my @at;
my @ac;
my $change_line = sub
{
my ($get_line) = @_;
local *_;
LOOP:
while (1)
{
$_ = scalar $get_line->();
$_ = "" unless defined $_;
print STDERR $_ if $debug;
redo if /^Devel::Cover: merging run/;
redo if /^Set up gcc environment/; # for MinGW
if (/Can't opendir\(.+\): No such file or directory/)
{
# parallel tests
scalar $get_line->();
redo;
}
s/^(Reading database from ).*/$1/;
s|(__ANON__\[) .* (/tests/ \w+ : \d+ \])|$1$2|x;
s/(Subroutine) +(Location)/$1 $2/;
s/-+/-/;
# s/.* Devel-Cover - \d+ \. \d+ \/*(\S+)\s*/$1/x;
s/^ \.\.\. .* - \d+ \. \d+ \/*(\S+)\s*/$1/x;
s/.* Devel \/ Cover \/*(\S+)\s*/$1/x;
s/^(Devel::Cover: merging run).*/$1/;
s/^(Run: ).*/$1/;
s/^(OS: ).*/$1/;
s/^(Perl version: ).*/$1/;
s/^(Start: ).*/$1/;
s/^(Finish: ).*/$1/;
s/copyright .*//ix;
no warnings "exiting";
eval $self->{changes} if exists $self->{changes};
return $_;
}
};
open T, "$cover_com 2>&1 |" or die "Cannot run $cover_com: $!";
while (!eof T)
{
my $t = $change_line->(sub { <T> });
my $c = $change_line->(sub { shift @{$self->{cover}} });
# print STDERR "[$t]\n[$c]\n" if $t ne $c;
# chomp(my $tn = $t); chomp(my $cn = $c);
# print STDERR "c-[$tn] $.\ng=[$cn]\n";
if ($differences)
{
push @at, $t;
push @ac, $c;
}
else
{
$ENV{DEVEL_COVER_NO_COVERAGE} ? ok 1 : ok $t, $c;
last if $ENV{DEVEL_COVER_NO_COVERAGE} && !@{$self->{cover}};
}
}
if ($differences)
{
no warnings "redefine";
local *Test::_quote = sub { "@_" };
$ENV{DEVEL_COVER_NO_COVERAGE} ? ok 1 : eq_or_diff(\@at, \@ac, "output");
}
elsif ($ENV{DEVEL_COVER_NO_COVERAGE})
{
ok 1 for @{$self->{cover}};
}
close T or die "Cannot close $cover_com: $!";
}
sub create_gold
{
my $self = shift;
$self->{run_test_at_end} = 0;
# Pod::Coverage not available on all versions, but it must be there on
# 5.6.1 and 5.8.0
return if $self->{criteria} =~ /\bpod\b/ &&
$] != 5.006001 &&
$] != 5.008000;
my $debug = $ENV{DEVEL_COVER_DEBUG} || 0;
my $gold = $self->cover_gold;
my $new_gold = $gold;
$new_gold =~ s/(5\.\d+)$/$]/;
my $gv = $1;
my $ng = "";
unless (-e $new_gold)
{
open my $g, ">$new_gold" or die "Can't open $new_gold: $!";
}
$self->{run_test}
? $self->{run_test}->($self)
: $self->run_command($self->test_command);
my $cover_com = $self->cover_command;
print STDERR "Running cover [$cover_com]\n" if $debug;
open G, ">$new_gold" or die "Cannot open $new_gold: $!";
open T, "$cover_com 2>&1 |" or die "Cannot run $cover_com: $!";
while (my $l = <T>)
{
next if $l =~ /^Devel::Cover: merging run/;
$l =~ s/^($_: ).*$/$1.../
for "Run", "Perl version", "OS", "Start", "Finish";
$l =~ s/^(Reading database from ).*$/$1.../;
print STDERR $l if $debug;
print G $l;
$ng .= $l;
}
close T or die "Cannot close $cover_com: $!";
close G or die "Cannot close $new_gold: $!";
print STDERR "gv is $gv and this is $]\n" if $debug;
print STDERR "gold is $gold and new_gold is $new_gold\n" if $debug;
unless ($gv eq "5.0" || $gv eq $])
{
open G, "$gold" or die "Cannot open $gold: $!";
my $g = do { local $/; <G> };
close G or die "Cannot close $gold: $!";
print STDERR "checking $new_gold against $gold\n" if $debug;
# print "--[$ng]--\n";
# print "--[$g]--\n";
if ($ng eq $g)
{
print "Output from $new_gold matches $gold\n";
unlink $new_gold;
}
}
$self->{end}->() if $self->{end};
}
END
{
my $self = $Test;
$self->run_test if $self->{run_test_at_end};
}
1;
|