From 9ac2fb38216af3b665a12b8f2411ce50b172a5a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C5=8Dan?= Date: Fri, 13 Mar 2026 09:51:04 -0600 Subject: [PATCH] fix: add failed test count diagnostic to ExitSummary plugin ExitSummary was missing the "Looks like you failed X test(s) of Y" diagnostic that Test::Builder provides. Users migrating from Test::More to Test2::Bundle::More expected this output. Closes #1056 --- lib/Test2/Plugin/ExitSummary.pm | 5 ++++ t/modules/Plugin/ExitSummary.t | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/lib/Test2/Plugin/ExitSummary.pm b/lib/Test2/Plugin/ExitSummary.pm index 6639a70d3..a62d75514 100644 --- a/lib/Test2/Plugin/ExitSummary.pm +++ b/lib/Test2/Plugin/ExitSummary.pm @@ -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; diff --git a/t/modules/Plugin/ExitSummary.t b/t/modules/Plugin/ExitSummary.t index 3f51420df..e6ce12265 100644 --- a/t/modules/Plugin/ExitSummary.t +++ b/t/modules/Plugin/ExitSummary.t @@ -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();