TEST2::MANUAL::TOOLING::PLUGIN::TESTINGDONE(3perl)
π Test2::Manual::Tooling::Plugin::TestingDone π
okay bestie, so this page lives in the Perl Programmers Reference Guide and it's literally called Test2::Manual::Tooling::Plugin::TestingDone π
she's a whole manual-page icon, 3perl section and everything.
β¨ NAME β¨
Test2::Manual::Tooling::Plugin::TestingDone β run code when the test file is finished, or when done_testing is called. π
πΈ DESCRIPTION πΈ
So this is a way to add behavior to the end of a test file. The code runs either when done_testing() gets called, or when the test file has no more run-time code left to run. Either way, she's showing up at the finish line π
And here's the part you NEED to know, no cap: when it's triggered by done_testing(), this runs BEFORE the plan is calculated and sent. Which means it IS safe to make test assertions in this callback. yes really. go off π
π¦ COMPLETE CODE UP FRONT π¦
here's the whole thing, no build-up, we're just giving it to you:
package Test2::Plugin::MyPlugin;
use Test2::API qw{test2_add_callback_testing_done};
sub import {
my $class = shift;
test2_add_callback_testing_done(sub {
ok(!$some_global, '$some_global was not set');
print "The test file is done, or done_testing was just called\n"
});
}
1;
π LINE BY LINE π
okay let's go through it together, one thing at a time π«Ά
use Test2::API qw{test2_add_callback_testing_done};
This imports the test2_add_callback_testing_done() callback. that's it, that's the whole job β¨
test2_add_callback_testing_done(sub { ... });
This adds our callback to be called when testing is done. simple as π
ok(!$some_global, '$some_global was not set')
It is safe to make assertions in this type of callback, periodt. This code simply asserts that some global was never set over the course of the test. iconic behavior honestly π
print "The test file is done, or done_testing was just called\n"
This prints a message when the callback is run. cute little victory lap π
π₯ UNDER THE HOOD π₯
Before test2_add_callback_testing_done() existed, this kind of thing was still possible, but bestie, it was hard to get right. here's the code to do it the old way:
test2_add_callback_post_load(sub {
my $stack = test2_stack();
# Insure we have at least one hub, but we do not necessarily want the
# one this returns.
$stack->top;
# We want the root hub, not the top one.
my ($root) = Test2::API::test2_stack->all;
# Make sure the hub does not believe nothing has happened.
$root->set_active(1);
# Now we can add our follow-up code
$root->follow_up(sub {
# Your callback code here
});
});
look at all that manual hub-wrangling... the way that we used to suffer π so glad we don't anymore.
π SEE ALSO π
Test2::Manualβ Primary index of the manual. start there if you're lost, she's the main character π«
π SOURCE π
The source code repository for Test2-Manual can be found at https://github.com/Test-More/test-more/. go peek, you know you want to π»β¨
π MAINTAINERS π
- Chad Granum
<exodist@cpan.org>
π«Ά AUTHORS π«Ά
- Chad Granum
<exodist@cpan.org>
π COPYRIGHT π
Copyright Chad Granum <exodist@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
and that's the whole page, bestie!! π generated for perl v5.44.0, dated 2026-10-17, from the Test2::...ingDone(3perl) era β slay, bye π
β¨πΈ
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms