Test2::Tools(3pm)
β¨ NAME β¨
Okay bestie, this is the Test2::Tools(3pm) manual page β the docs for Test2::Tools, aka Documentation for Tools. That's the whole name moment, and it's iconic. π
πΈ DESCRIPTION πΈ
So like, Tools are packages that export test functions, typically all related to a specific aspect of testing. If you have a couple different categories of exports, then you may want to break them into separate modules. Slay. β¨
Tools should export testing functions. Loading tools should not have side-effects, or alter the behavior of other tools.
π Real talk: if you want to alter behaviors or create side-effects, then you probably want to write a Test2::Plugin.
π¬ FAQ π¬
Why is it called Test2::Tools, and not Test2::Tool?
This question arises since Tools is the only namespace in the plural. The reason is that each Plugin should be a distinct unit of functionality, but a Tools dist can (and usually should) export several tools. A bundle is also typically described as a single unit. And nobody would like Test2::Bundles::Foo. Periodt. π«Ά
Should my tools subclass Test2::Tools?
No. Currently this class is empty. Eventually we may want to add behavior, in which case we do not want anyone to already be subclassing it. No cap. π
π§ HOW DO I WRITE A 'TOOLS' MODULE? π§
It is very easy to write tools:
package Test2::Tools::Mine
use strict;
use warnings;
# All tools should use the context() function.
use Test2::API qw/context/;
our @EXPORTS = qw/ok plan/;
use base 'Exporter';
sub ok($;$) {
my ($bool, $name) = @_;
# All tool functions should start by grabbing a context
my $ctx = context();
# The context is the primary interface for generating events
$ctx->ok($bool, $name);
# When you are done you release the context
$ctx->release;
return $bool ? 1 : 0;
}
sub plan {
my ($max) = @_;
my $ctx = context();
$ctx->plan($max);
$ctx->release;
}
1;
See Test2::API::Context for documentation on what the $ctx object can do. That's the main-character object right there. π
π¦ SOURCE π¦
The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. Go give it a vibe check. πΈ
π 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/
Final footer vibe: source/version perl v5.42.3, date 2026-11-03, manual name Test2::Tools(3pm) β bye bestie, go write some iconic tools! π
β¨π¦
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms