Skip to content

Commit

Permalink
Do not 'inherit' amnesty set via $TODO
Browse files Browse the repository at this point in the history
Removed the logic that would accidentally ALWAYS set amnesty from local
$TODO to be inherited. This logic is unnecessary as Test::Builder
manages the $TODO state/stack itself, it will never be inherited.

Fixes #817
  • Loading branch information
exodist committed Dec 11, 2018
1 parent 8570469 commit 8a6217c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lib/Test/Builder.pm
Expand Up @@ -69,13 +69,8 @@ sub _add_ts_hooks {
# Turn a diag into a todo diag
return Test::Builder::TodoDiag->new(%$e) if ref($e) eq 'Test2::Event::Diag';

if ($active_hub == $hub) {
$e->set_todo($todo) if $e->can('set_todo');
$e->add_amnesty({tag => 'TODO', details => $todo});
}
else {
$e->add_amnesty({tag => 'TODO', details => $todo, inherited => 1});
}
$e->set_todo($todo) if $e->can('set_todo');
$e->add_amnesty({tag => 'TODO', details => $todo});

# Set todo on ok's
if ($e->isa('Test2::Event::Ok')) {
Expand Down
48 changes: 48 additions & 0 deletions t/regression/817-subtest-todo.t
@@ -0,0 +1,48 @@
use Test2::API qw(run_subtest context intercept);
use Test::More;
use Test2::Tools::Tiny qw/todo/;

sub aaa {
my $ctx = context();
run_subtest(
"bad pass",
sub {
local $TODO = "third test";
ok(1, "ok");
}
);
$ctx->release;
}

sub bbb {
my $ctx = context();
run_subtest(
"bad fail",
sub {
local $TODO = "fourth test";
ok(0, "ok");
}
);

$ctx->release;
}

my $events = intercept {
Test::Builder->new->_add_ts_hooks();
aaa();
bbb();
};

is_deeply(
$events->[1]->{subevents}->[0]->{amnesty}->[0],
{ tag => 'TODO', details => "third test" },
"Amnesty was set properly for first subtest assertion",
);

is_deeply(
$events->[3]->{subevents}->[0]->{amnesty}->[0],
{ tag => 'TODO', details => "fourth test" },
"Amnesty was set properly for second subtest assertion",
);

done_testing;

0 comments on commit 8a6217c

Please sign in to comment.