Skip to content

Commit

Permalink
Manage Devel::Cover coverage reporting errors.
Browse files Browse the repository at this point in the history
Devel::Cover errors in _report() would end the process.  That wouldn't
normally matter since Devel::Cover tries very hard to be the last thing to be
run anyway.

But it is important just before an exec().  When Devel::Cover sees an exec()
call it first calls report() then calls the exec().  In this case it is
important that any errors in report() do not prevent the exec() from running.

We go belt and braces here: put an eval {} around the _report() and try to
nicely report the problem, and add G_EVAL to call_pv().

Also add a test for this.

This problem was found by Daisuke Maki.  He also diagnosed it, provided the
test case and suggested the solution.
  • Loading branch information
pjcj committed Oct 14, 2011
1 parent d2de994 commit 1716d03
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cover.xs
Expand Up @@ -412,7 +412,7 @@ static void call_report(pTHX)
{
dSP;
PUSHMARK(SP);
call_pv("Devel::Cover::report", G_VOID|G_DISCARD);
call_pv("Devel::Cover::report", G_VOID|G_DISCARD|G_EVAL);
SPAGAIN;
}

Expand Down
19 changes: 18 additions & 1 deletion lib/Devel/Cover.pm
Expand Up @@ -661,7 +661,24 @@ my %Seen;

sub report
{
_report();
local $@;
eval
{
_report();
};
if ($@)
{
print STDERR <<"EOM" unless $Silent;
Devel::Cover: Oops, it looks like something went wrong writing the coverage.
It's possible that more bad things may happen but we'll try to
carry on anyway as if nothing happened. At a minimum you'll
probably find that you are missing coverage. If you're
interrested, the problem was:
$@
EOM
}
return unless $Self_cover;
$Self_cover_run = 1;
_report();
Expand Down
59 changes: 59 additions & 0 deletions test_output/cover/exec_die.5.006001
@@ -0,0 +1,59 @@
Reading database from ...


------------------------------------------ ------ ------ ------ ------ ------
File stmt bran cond sub total
------------------------------------------ ------ ------ ------ ------ ------
tests/exec_die 50.0 50.0 n/a 0.0 44.4
Total 50.0 50.0 n/a 0.0 44.4
------------------------------------------ ------ ------ ------ ------ ------


Run: ...
Perl version: ...
OS: ...
Start: ...
Finish: ...

tests/exec_die

line err stmt bran cond sub code
1 #!/usr/bin/perl
2
3 # Copyright 2007-2011, Paul Johnson (pjcj@cpan.org)
4
5 # This software is free. It is licensed under the same terms as Perl itself.
6
7 # The latest version of this software should be available from my homepage:
8 # http://www.pjcj.net
9
10 1 my $pid = fork;
11
12 *** 1 50 if ($pid)
13 {
14 1 wait;
15 }
16 else
17 {
18 *** 0 0 local *Devel::Cover::_report = sub { die "Badness happened!" };
*** 0
19 *** 0 exec "echo We want to be able to see this.";
20 }


Branches
--------

line err % true false branch
----- --- ------ ------ ------ ------
12 *** 50 1 0 if ($pid) { }


Uncovered Subroutines
---------------------

Subroutine Count Location
---------- ----- -----------------
__ANON__ 0 tests/exec_die:18


20 changes: 20 additions & 0 deletions tests/exec_die
@@ -0,0 +1,20 @@
#!/usr/bin/perl

# Copyright 2007-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

my $pid = fork;

if ($pid)
{
wait;
}
else
{
local *Devel::Cover::_report = sub { die "Badness happened!" };
exec "echo We want to be able to see this.";
}

0 comments on commit 1716d03

Please sign in to comment.