Skip to content
Draft
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
5 changes: 5 additions & 0 deletions lib/Test2/Plugin/ExitSummary.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ sub summary {

$ctx->diag("Did not follow plan: expected $plan, ran $count.")
if $plan && $plan =~ m/^[0-9]+$/ && defined $count && $count != $plan;

if ($failed) {
my $s = $failed == 1 ? '' : 's';
$ctx->diag("Looks like you failed $failed test$s of $count.");
}
}

1;
Expand Down
45 changes: 45 additions & 0 deletions t/modules/Plugin/ExitSummary.t
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,49 @@ like(
"Bad exit code"
);

$exit = 0;
$new = 0;
like(
intercept {
plan 2;
ok(1);
ok(0);
my $ctx = context(level => -1);
$summary->($ctx, $exit, \$new);
$ctx->release;
},
array {
event Plan => { max => 2 };
event Ok => { pass => 1 };
event Ok => { pass => 0 };
event Diag => {}; # "Failed test" diagnostic from ok(0)
event Diag => {message => 'Looks like you failed 1 test of 2.'};
end
},
"Failed test count reported"
);

like(
intercept {
plan 3;
ok(0);
ok(0);
ok(1);
my $ctx = context(level => -1);
$summary->($ctx, $exit, \$new);
$ctx->release;
},
array {
event Plan => { max => 3 };
event Ok => { pass => 0 };
event Diag => {}; # "Failed test" diagnostic from first ok(0)
event Ok => { pass => 0 };
event Diag => {}; # "Failed test" diagnostic from second ok(0)
event Ok => { pass => 1 };
event Diag => {message => 'Looks like you failed 2 tests of 3.'};
end
},
"Failed test count reported (plural)"
);

done_testing();