Skip to content
Browse files

C<my $x = $y || return> is a condition.

As are other constant right hand sides, or those which transfer control.
  • Loading branch information...
1 parent 4d4cf6b commit 32b8e4aaa8f2d805d20af5e0698aad205db049bb @pjcj committed
View
20 lib/Devel/Cover.pm
@@ -78,10 +78,8 @@ my %Coverage_options; # Options for overage criteria.
my %Run; # Data collected from the run.
my $Const_right = qr/^(?:const|s?refgen|gelem|die|undef|bless|anon(?:list|hash)|
- scalar)$/x; # constant ops
-
-my $Noret_right = qr/^(?:return|last|next|redo|goto\s+\w+|die)$/x;
- # ops which don't return
+ scalar|return|last|next|redo|goto)$/x;
+ # constant ops
use vars '$File', # Last filename we saw. (localised)
'$Line', # Last line number we saw. (localised)
@@ -819,8 +817,10 @@ sub add_condition_cover
# use Carp "cluck"; cluck("from here");
my $type = $op->name;
+ # print STDERR "type: [$type]\n";
$type =~ s/assign$//;
$type = "or" if $type eq "dor";
+ # print STDERR "type: [$type]\n";
my $c = $Coverage->{condition}{$key};
@@ -1036,16 +1036,8 @@ sub logop
$right = $self->deparse_binop_right($op, $right, $highprec);
}
# print STDERR "left [$left], right [$right]\n";
- if ($right =~ $Noret_right)
- {
- add_branch_cover($op, $lowop, "$blockname ($left)", $file, $line)
- unless $Seen{branch}{$$op}++;
- }
- else
- {
- add_condition_cover($op, $highop, $left, $right)
- unless $Seen{condition}{$$op}++;
- }
+ add_condition_cover($op, $highop, $left, $right)
+ unless $Seen{condition}{$$op}++;
return $self->maybe_parens("$left $highop $right", $cx, $highprec)
}
else
View
37 test_output/cover/cond_branch.5.006001
@@ -4,8 +4,8 @@ Reading database from ...
------------------------------------------ ------ ------ ------ ------ ------
File stmt bran cond sub total
------------------------------------------ ------ ------ ------ ------ ------
-tests/cond_branch 85.3 82.1 19.1 100.0 73.0
-Total 85.3 82.1 19.1 100.0 73.0
+tests/cond_branch 85.3 79.3 32.9 100.0 73.0
+Total 85.3 79.3 32.9 100.0 73.0
------------------------------------------ ------ ------ ------ ------ ------
@@ -325,13 +325,13 @@ line err stmt bran cond sub code
276
277 sub
278 {
-279 4 100 4 my $x = shift || return;
+279 4 100 4 my $x = shift || return;
280 2 $x[45]++;
281 },
282
283 sub
284 {
-285 4 100 4 my $x = shift && return;
+285 4 100 4 my $x = shift && return;
286 2 $x[46]++;
287 },
288
@@ -341,7 +341,7 @@ line err stmt bran cond sub code
292 4 for my $y (1 .. 2)
4
293 {
-294 6 100 my $z = $x || last;
+294 6 100 my $z = $x || last;
295 4 $x[47]++;
296 }
297 },
@@ -352,7 +352,7 @@ line err stmt bran cond sub code
302 4 for my $y (1 .. 2)
8
303 {
-304 8 100 my $z = $x || next;
+304 8 100 my $z = $x || next;
305 4 $x[48]++;
306 }
307 },
@@ -363,7 +363,7 @@ line err stmt bran cond sub code
312 4 for my $y (1 .. 2)
8
313 {
-314 10 100 my $z = $x++ || redo;
+314 10 100 my $z = $x++ || redo;
315 8 $x[49]++;
316 }
317 },
@@ -374,7 +374,7 @@ line err stmt bran cond sub code
322 4 for my $y (1 .. 2)
4
323 {
-324 6 100 my $z = $x || goto GR;
+324 6 100 my $z = $x || goto GR;
325 4 $x[50]++;
326 }
327 GR:
@@ -386,7 +386,7 @@ line err stmt bran cond sub code
333 4 for my $y (1 .. 2)
8
334 {
-335 8 100 eval { my $z = $x || die };
+335 8 100 eval { my $z = $x || die };
8
336 8 $x[51]++;
337 }
@@ -483,13 +483,6 @@ line err % true false branch
249 100 1 2 if $z > 1
260 100 2 2 unless shift @_
266 100 2 2 if shift @_
-279 100 2 2 unless (shift @_)
-285 100 2 2 if (shift @_)
-294 100 2 4 unless ($x)
-304 100 4 4 unless ($x)
-314 100 2 8 unless ($x++)
-324 100 2 4 unless ($x)
-335 100 4 4 unless ($x)
357 *** 50 0 1 if ($a and $b) { }
*** 50 0 1 elsif (not $a and not $b) { }
*** 50 1 0 elsif ($b or 0) { }
@@ -500,6 +493,12 @@ line err % true false branch
Conditions
----------
+and 2 conditions
+
+line err % l !l expr
+----- --- ------ ------ ------ ----
+285 100 2 2 shift @_ && return
+
and 3 conditions
line err % !l l&&!r l&&r expr
@@ -516,6 +515,12 @@ or 2 conditions
line err % l !l expr
----- --- ------ ------ ------ ----
+279 100 2 2 shift @_ || return
+294 100 4 2 $x || last
+304 100 4 4 $x || next
+314 100 8 2 $x++ || redo
+324 100 4 2 $x || goto GR
+335 100 4 4 $x || die
357 *** 50 1 0 $b or 0
or 3 conditions
View
37 test_output/cover/cond_branch.5.008
@@ -4,8 +4,8 @@ Reading database from ...
------------------------------------------ ------ ------ ------ ------ ------
File stmt bran cond sub total
------------------------------------------ ------ ------ ------ ------ ------
-tests/cond_branch 87.4 82.1 19.1 100.0 75.8
-Total 87.4 82.1 19.1 100.0 75.8
+tests/cond_branch 87.4 79.3 32.9 100.0 75.8
+Total 87.4 79.3 32.9 100.0 75.8
------------------------------------------ ------ ------ ------ ------ ------
@@ -347,13 +347,13 @@ line err stmt bran cond sub code
276
277 sub
278 {
-279 4 100 4 my $x = shift || return;
+279 4 100 4 my $x = shift || return;
280 2 $x[45]++;
281 },
282
283 sub
284 {
-285 4 100 4 my $x = shift && return;
+285 4 100 4 my $x = shift && return;
286 2 $x[46]++;
287 },
288
@@ -363,7 +363,7 @@ line err stmt bran cond sub code
292 4 for my $y (1 .. 2)
4
293 {
-294 6 100 my $z = $x || last;
+294 6 100 my $z = $x || last;
295 4 $x[47]++;
296 }
297 },
@@ -374,7 +374,7 @@ line err stmt bran cond sub code
302 4 for my $y (1 .. 2)
8
303 {
-304 8 100 my $z = $x || next;
+304 8 100 my $z = $x || next;
305 4 $x[48]++;
306 }
307 },
@@ -385,7 +385,7 @@ line err stmt bran cond sub code
312 4 for my $y (1 .. 2)
8
313 {
-314 10 100 my $z = $x++ || redo;
+314 10 100 my $z = $x++ || redo;
315 8 $x[49]++;
316 }
317 },
@@ -396,7 +396,7 @@ line err stmt bran cond sub code
322 4 for my $y (1 .. 2)
4
323 {
-324 6 100 my $z = $x || goto GR;
+324 6 100 my $z = $x || goto GR;
325 4 $x[50]++;
326 }
327 GR:
@@ -408,7 +408,7 @@ line err stmt bran cond sub code
333 4 for my $y (1 .. 2)
8
334 {
-335 8 100 eval { my $z = $x || die };
+335 8 100 eval { my $z = $x || die };
8
336 8 $x[51]++;
337 }
@@ -505,13 +505,6 @@ line err % true false branch
249 100 1 2 if $z > 1
260 100 2 2 unless shift @_
266 100 2 2 if shift @_
-279 100 2 2 unless (shift @_)
-285 100 2 2 if (shift @_)
-294 100 2 4 unless ($x)
-304 100 4 4 unless ($x)
-314 100 2 8 unless ($x++)
-324 100 2 4 unless ($x)
-335 100 4 4 unless ($x)
357 *** 50 0 1 if ($a and $b) { }
*** 50 0 1 elsif (not $a and not $b) { }
*** 50 1 0 elsif ($b or 0) { }
@@ -522,6 +515,12 @@ line err % true false branch
Conditions
----------
+and 2 conditions
+
+line err % l !l expr
+----- --- ------ ------ ------ ----
+285 100 2 2 shift @_ && return
+
and 3 conditions
line err % !l l&&!r l&&r expr
@@ -538,6 +537,12 @@ or 2 conditions
line err % l !l expr
----- --- ------ ------ ------ ----
+279 100 2 2 shift @_ || return
+294 100 4 2 $x || last
+304 100 4 4 $x || next
+314 100 8 2 $x++ || redo
+324 100 4 2 $x || goto GR
+335 100 4 4 $x || die
357 *** 50 1 0 $b or 0
or 3 conditions
View
37 test_output/cover/cond_branch.5.008001
@@ -4,8 +4,8 @@ Reading database from ...
------------------------------------------ ------ ------ ------ ------ ------
File stmt bran cond sub total
------------------------------------------ ------ ------ ------ ------ ------
-tests/cond_branch 90.3 82.1 19.1 100.0 76.2
-Total 90.3 82.1 19.1 100.0 76.2
+tests/cond_branch 90.3 79.3 32.9 100.0 76.2
+Total 90.3 79.3 32.9 100.0 76.2
------------------------------------------ ------ ------ ------ ------ ------
@@ -321,13 +321,13 @@ line err stmt bran cond sub code
276
277 sub
278 {
-279 4 100 4 my $x = shift || return;
+279 4 100 4 my $x = shift || return;
280 2 $x[45]++;
281 },
282
283 sub
284 {
-285 4 100 4 my $x = shift && return;
+285 4 100 4 my $x = shift && return;
286 2 $x[46]++;
287 },
288
@@ -336,7 +336,7 @@ line err stmt bran cond sub code
291 4 4 my $x = shift;
292 4 for my $y (1 .. 2)
293 {
-294 6 100 my $z = $x || last;
+294 6 100 my $z = $x || last;
295 4 $x[47]++;
296 }
297 },
@@ -346,7 +346,7 @@ line err stmt bran cond sub code
301 4 4 my $x = shift;
302 4 for my $y (1 .. 2)
303 {
-304 8 100 my $z = $x || next;
+304 8 100 my $z = $x || next;
305 4 $x[48]++;
306 }
307 },
@@ -356,7 +356,7 @@ line err stmt bran cond sub code
311 4 4 my $x = shift;
312 4 for my $y (1 .. 2)
313 {
-314 10 100 my $z = $x++ || redo;
+314 10 100 my $z = $x++ || redo;
315 8 $x[49]++;
316 }
317 },
@@ -366,7 +366,7 @@ line err stmt bran cond sub code
321 4 4 my $x = shift;
322 4 for my $y (1 .. 2)
323 {
-324 6 100 my $z = $x || goto GR;
+324 6 100 my $z = $x || goto GR;
325 4 $x[50]++;
326 }
327 GR:
@@ -377,7 +377,7 @@ line err stmt bran cond sub code
332 4 4 my $x = shift;
333 4 for my $y (1 .. 2)
334 {
-335 8 100 eval { my $z = $x || die };
+335 8 100 eval { my $z = $x || die };
8
336 8 $x[51]++;
337 }
@@ -471,13 +471,6 @@ line err % true false branch
249 100 1 2 if $z > 1
260 100 2 2 unless shift @_
266 100 2 2 if shift @_
-279 100 2 2 unless (shift @_)
-285 100 2 2 if (shift @_)
-294 100 2 4 unless ($x)
-304 100 4 4 unless ($x)
-314 100 2 8 unless ($x++)
-324 100 2 4 unless ($x)
-335 100 4 4 unless ($x)
357 *** 50 0 1 if ($a and $b) { }
*** 50 0 1 elsif (not $a and not $b) { }
*** 50 1 0 elsif ($b or 0) { }
@@ -488,6 +481,12 @@ line err % true false branch
Conditions
----------
+and 2 conditions
+
+line err % l !l expr
+----- --- ------ ------ ------ ----
+285 100 2 2 shift @_ && return
+
and 3 conditions
line err % !l l&&!r l&&r expr
@@ -504,6 +503,12 @@ or 2 conditions
line err % l !l expr
----- --- ------ ------ ------ ----
+279 100 2 2 shift @_ || return
+294 100 4 2 $x || last
+304 100 4 4 $x || next
+314 100 8 2 $x++ || redo
+324 100 4 2 $x || goto GR
+335 100 4 4 $x || die
357 *** 50 1 0 $b or 0
or 3 conditions
View
37 test_output/cover/cond_branch.5.012000
@@ -4,8 +4,8 @@ Reading database from ...
------------------------------------------ ------ ------ ------ ------ ------
File stmt bran cond sub total
------------------------------------------ ------ ------ ------ ------ ------
-tests/cond_branch 90.3 82.1 19.1 100.0 76.2
-Total 90.3 82.1 19.1 100.0 76.2
+tests/cond_branch 90.3 79.3 32.9 100.0 76.2
+Total 90.3 79.3 32.9 100.0 76.2
------------------------------------------ ------ ------ ------ ------ ------
@@ -321,13 +321,13 @@ line err stmt bran cond sub code
276
277 sub
278 {
-279 4 100 4 my $x = shift || return;
+279 4 100 4 my $x = shift || return;
280 2 $x[45]++;
281 },
282
283 sub
284 {
-285 4 100 4 my $x = shift && return;
+285 4 100 4 my $x = shift && return;
286 2 $x[46]++;
287 },
288
@@ -336,7 +336,7 @@ line err stmt bran cond sub code
291 4 4 my $x = shift;
292 4 for my $y (1 .. 2)
293 {
-294 6 100 my $z = $x || last;
+294 6 100 my $z = $x || last;
295 4 $x[47]++;
296 }
297 },
@@ -346,7 +346,7 @@ line err stmt bran cond sub code
301 4 4 my $x = shift;
302 4 for my $y (1 .. 2)
303 {
-304 8 100 my $z = $x || next;
+304 8 100 my $z = $x || next;
305 4 $x[48]++;
306 }
307 },
@@ -356,7 +356,7 @@ line err stmt bran cond sub code
311 4 4 my $x = shift;
312 4 for my $y (1 .. 2)
313 {
-314 10 100 my $z = $x++ || redo;
+314 10 100 my $z = $x++ || redo;
315 8 $x[49]++;
316 }
317 },
@@ -366,7 +366,7 @@ line err stmt bran cond sub code
321 4 4 my $x = shift;
322 4 for my $y (1 .. 2)
323 {
-324 6 100 my $z = $x || goto GR;
+324 6 100 my $z = $x || goto GR;
325 4 $x[50]++;
326 }
327 GR:
@@ -377,7 +377,7 @@ line err stmt bran cond sub code
332 4 4 my $x = shift;
333 4 for my $y (1 .. 2)
334 {
-335 8 100 eval { my $z = $x || die };
+335 8 100 eval { my $z = $x || die };
8
336 8 $x[51]++;
337 }
@@ -471,13 +471,6 @@ line err % true false branch
249 100 1 2 if $z > 1
260 100 2 2 unless shift @_
266 100 2 2 if shift @_
-279 100 2 2 unless (shift @_)
-285 100 2 2 if (shift @_)
-294 100 2 4 unless ($x)
-304 100 4 4 unless ($x)
-314 100 2 8 unless ($x++)
-324 100 2 4 unless ($x)
-335 100 4 4 unless ($x)
357 *** 50 0 1 if ($a and $b) { }
*** 50 0 1 elsif (not $a || $b) { }
*** 50 1 0 elsif ($b or 0) { }
@@ -488,6 +481,12 @@ line err % true false branch
Conditions
----------
+and 2 conditions
+
+line err % l !l expr
+----- --- ------ ------ ------ ----
+285 100 2 2 shift @_ && return
+
and 3 conditions
line err % !l l&&!r l&&r expr
@@ -503,6 +502,12 @@ or 2 conditions
line err % l !l expr
----- --- ------ ------ ------ ----
+279 100 2 2 shift @_ || return
+294 100 4 2 $x || last
+304 100 4 4 $x || next
+314 100 8 2 $x++ || redo
+324 100 4 2 $x || goto GR
+335 100 4 4 $x || die
357 *** 50 1 0 $b or 0
or 3 conditions

0 comments on commit 32b8e4a

Please sign in to comment.
Something went wrong with that request. Please try again.