Browse files

Remove unnecessary Deparse calls.

And add a test for it.
  • Loading branch information...
1 parent 41a2583 commit 2517732ff5edec29370c373a8684ebf53c1f2501 @pjcj committed Mar 3, 2013
View
14 lib/Devel/Cover.pm
@@ -1044,21 +1044,26 @@ sub deparse
my $name = $op->can("name") ? $op->name : "Unknown";
- # print STDERR "$class:$name at $File:$Line\n";
+ # print STDERR "$class:$name ($$op) at $File:$Line\n";
+ # print STDERR "[$Seen{statement}{$$op}] [$Seen{other}{$$op}]\n";
+ # use Carp "cluck"; cluck("from here");
- {
+ unless ($Seen{statement}{$$op} || $Seen{other}{$$op}) {
# Collect everything under here.
local ($File, $Line) = ($File, $Line);
+ # print STDERR "Collecting $$op under $File:$Line\n";
$deparse = eval { local $^W; $Original{deparse}->($self, @_) };
$deparse =~ s/^\010+//mg if defined $deparse;
$deparse = "Deparse error: $@" if $@;
+ # print STDERR "Collected $$op under $File:$Line\n";
# print STDERR "Collect Deparse $op $$op => <$deparse>\n";
}
# Get the coverage on this op.
if ($class eq "COP" && $Coverage{statement})
{
+ # print STDERR "COP $$op, seen [$Seen{statement}{$$op}]\n";
add_statement_cover($op) unless $Seen{statement}{$$op}++;
}
elsif (!$null && $name eq "null"
@@ -1069,11 +1074,13 @@ sub deparse
# get at the file and line number, but we need to get dirty.
bless $op, "B::COP";
+ # print STDERR "null $$op, seen [$Seen{statement}{$$op}]\n";
add_statement_cover($op) unless $Seen{statement}{$$op}++;
bless $op, "B::$class";
}
elsif ($Seen{other}{$$op}++)
{
+ # print STDERR "seen [$Seen{other}{$$op}]\n";
return "" # Only report on each op once.
}
elsif ($name eq "cond_expr")
@@ -1116,12 +1123,15 @@ sub deparse
else
{
local ($File, $Line) = ($File, $Line);
+ # print STDERR "Starting plain deparse at $File:$Line\n";
$deparse = eval { local $^W; $Original{deparse}->($self, @_) };
$deparse =~ s/^\010+//mg if defined $deparse;
$deparse = "Deparse error: $@" if $@;
+ # print STDERR "Ending plain deparse at $File:$Line\n";
# print STDERR "Deparse => <$deparse>\n";
}
+ # print STDERR "Returning [$deparse]\n";
$deparse
}
View
14 test_output/cover/cond_or.5.008
@@ -4,8 +4,8 @@ Reading database from ...
------------------------------------------ ------ ------ ------ ------ ------
File stmt bran cond sub total
------------------------------------------ ------ ------ ------ ------ ------
-tests/cond_or 84.5 30.0 66.7 75.0 69.1
-Total 84.5 30.0 66.7 75.0 69.1
+tests/cond_or 83.3 30.0 64.4 60.0 67.4
+Total 83.3 30.0 64.4 60.0 67.4
------------------------------------------ ------ ------ ------ ------ ------
@@ -116,9 +116,11 @@ line err stmt bran cond sub code
87 blah
88 EOD
89 *** 11 50 cond_dor(\@x) if exists &cond_dor;
-90 }
-91
-92 # print join(", ", @x), "\n";
+90 *** 11 0 0 sub { $x[19] ||= 1 };
+ *** 0
+91 }
+92
+93 # print join(", ", @x), "\n";
Branches
@@ -163,6 +165,7 @@ line err % l !l expr
82 *** 50 0 11 $x[15] ||= *STDIO{'IO'}
83 100 10 1 $x[16] ||= bless({}, 'XXX')
86 100 10 1 $x[18] ||= "blah\n"
+90 *** 0 0 0 $x[19] ||= 1
or 3 conditions
@@ -194,5 +197,6 @@ Uncovered Subroutines
Subroutine Count Location
---------- ----- ----------------
__ANON__ 0 tests/cond_or:80
+__ANON__ 0 tests/cond_or:90
View
14 test_output/cover/cond_or.5.008001
@@ -4,8 +4,8 @@ Reading database from ...
------------------------------------------ ------ ------ ------ ------ ------
File stmt bran cond sub total
------------------------------------------ ------ ------ ------ ------ ------
-tests/cond_or 83.9 30.0 66.7 75.0 68.6
-Total 83.9 30.0 66.7 75.0 68.6
+tests/cond_or 82.8 30.0 64.4 60.0 66.9
+Total 82.8 30.0 64.4 60.0 66.9
------------------------------------------ ------ ------ ------ ------ ------
@@ -114,9 +114,11 @@ line err stmt bran cond sub code
87 blah
88 EOD
89 *** 11 50 cond_dor(\@x) if exists &cond_dor;
-90 }
-91
-92 # print join(", ", @x), "\n";
+90 *** 11 0 0 sub { $x[19] ||= 1 };
+ *** 0
+91 }
+92
+93 # print join(", ", @x), "\n";
Branches
@@ -161,6 +163,7 @@ line err % l !l expr
82 *** 50 0 11 $x[15] ||= *STDIO{'IO'}
83 100 10 1 $x[16] ||= bless({}, 'XXX')
86 100 10 1 $x[18] ||= "blah\n"
+90 *** 0 0 0 $x[19] ||= 1
or 3 conditions
@@ -192,5 +195,6 @@ Uncovered Subroutines
Subroutine Count Location
---------- ----- ----------------
__ANON__ 0 tests/cond_or:80
+__ANON__ 0 tests/cond_or:90
View
14 test_output/cover/cond_or.5.010000
@@ -4,9 +4,9 @@ Reading database from ...
------------------------------------------ ------ ------ ------ ------ ------
File stmt bran cond sub total
------------------------------------------ ------ ------ ------ ------ ------
-tests/cond_or 91.1 35.0 66.7 75.0 72.3
+tests/cond_or 89.7 35.0 64.4 60.0 70.4
tests/cond_or.pl 100.0 n/a 57.5 100.0 75.7
-Total 94.0 35.0 62.9 85.7 73.4
+Total 92.9 35.0 61.6 75.0 72.2
------------------------------------------ ------ ------ ------ ------ ------
@@ -115,9 +115,11 @@ line err stmt bran cond sub code
87 blah
88 EOD
89 *** 11 50 cond_dor(\@x) if exists &cond_dor;
-90 }
-91
-92 # print join(", ", @x), "\n";
+90 *** 11 0 0 sub { $x[19] ||= 1 };
+ *** 0
+91 }
+92
+93 # print join(", ", @x), "\n";
Branches
@@ -162,6 +164,7 @@ line err % l !l expr
82 *** 50 0 11 $x[15] ||= *STDIO{'IO'}
83 100 10 1 $x[16] ||= bless({}, 'XXX')
86 100 10 1 $x[18] ||= "blah\n"
+90 *** 0 0 0 $x[19] ||= 1
or 3 conditions
@@ -193,6 +196,7 @@ Uncovered Subroutines
Subroutine Count Location
---------- ----- ----------------
__ANON__ 0 tests/cond_or:80
+__ANON__ 0 tests/cond_or:90
tests/cond_or.pl
View
1 tests/cond_or
@@ -87,6 +87,7 @@ for my $i (0 .. 10)
blah
EOD
cond_dor(\@x) if exists &cond_dor;
+ sub { $x[19] ||= 1 };
}
# print join(", ", @x), "\n";

0 comments on commit 2517732

Please sign in to comment.