Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #24: Fix errant "skip" message from clobbered $@ in uncaught error #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/Test/Class.pm
Original file line number Diff line number Diff line change
Expand Up @@ -289,22 +289,29 @@ sub _run_method {
return $is_ok;
};

my $exception;
$skip_reason = try { $self->$method } catch { $exception = $_; undef };
my ($exception, $succeeded);
try {
$skip_reason = $self->$method;
$succeeded = 1;
}
catch {
$exception = $_;
};

$skip_reason = $method unless $skip_reason;

my $num_done = $Builder->current_test - $num_start;
my $num_expected = _total_num_tests($self, $method);
$num_expected = $num_done if $num_expected eq NO_PLAN;
if ($num_done == $num_expected) {
_exception_failure($self, $method, $exception, $tests)
if $exception;
if !$succeeded;
} elsif ($num_done > $num_expected) {
my $class = ref $self;
$Builder->diag("expected $num_expected test(s) in $class\::$method, $num_done completed\n");
} else {
until (($Builder->current_test - $num_start) >= $num_expected) {
if ($exception) {
if (!$succeeded) {
_exception_failure($self, $method, $exception, $tests);
$skip_reason = "$method died";
$exception = '';
Expand Down
33 changes: 33 additions & 0 deletions t/clobbered_EVAL_ERROR.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/perl -T

use strict;
use warnings;
use Test::More tests => 1;
use Test::Builder::Tester;

package Destroyer;

sub new { bless {} }

sub DESTROY { $@ = q<> }

package Object::Test;
use base qw(Test::Class);
use Test::More;

sub clobbered_EVAL_ERROR : Test(1) {
for ( Destroyer->new() ) {
die 'haha';
}
}

package main;

test_out(qr/.*died.*/s);
test_err(qr/.*died.*/s);

Object::Test->runtests;

END {
test_test("report uncaught exception even if it might be clobbered");
}