Test2::Tools(3perl)

πŸ’– Test2::Tools ✨

okay so bestie, welcome to the Test2::Tools manual page β€” straight out of the Perl Programmers Reference Guide, no cap. this is the whole vibe on what "Tools" even means in Test2 land. grab a snack, we're getting educated πŸŽ€


🌸 NAME 🌸

Test2::Tools β€” literally just the documentation for Tools. that's it. that's the name. πŸ’…


✨ DESCRIPTION ✨

okay so listen. Tools are packages that export test functions β€” and usually they're all about one specific aspect of testing. like, they stick to their lane. so if you've got a couple different categories of exports, you might wanna break them into separate modules instead of cramming everything into one sad little package. πŸ¦‹

Tools should export testing functions. periodt. and here's the important part: loading tools should NOT have side-effects, and it should not alter the behavior of other tools. like, mind your own business, king πŸ’€

if you do want to alter behaviors or create side-effects? then you probably wanna write a Test2::Plugin instead. wrong tool for the job, bestie, we don't do that here πŸ™ˆ


πŸŽ€ FAQ πŸŽ€

Why is it called Test2::Tools, and not Test2::Tool?

such a good question fr fr. this comes up because Tools is the only namespace in the plural. the reason is: each Plugin should be a distinct unit of functionality, but a Tools dist can (and usually should) export several tools. and a bundle is also typically described as a single unit. so like... nobody would like Test2::Bundles::Foo. literally nobody. πŸ’€

Should my tools subclass Test2::Tools?

No. nope. absolutely not. currently this class is empty. eventually they may want to add behavior, and in that case they really do not want anyone to already be subclassing it. so like, don't. iykyk ✨


🌈 HOW DO I WRITE A 'TOOLS' MODULE? 🌈

okay this is the fun part β€” it is very easy to write tools. look at this gorgeous little thing:

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 how clean that is?? every tool function grabs a context first, does its thing through the context, and then releases the context when it's done. that's the whole routine, bestie. main character energy only. πŸ‘‘

and if you wanna know everything the $ctx object can do? go read Test2::API::Context for the full documentation. it's giving "reference material" and we respect it. πŸ“š


πŸ”₯ SOURCE πŸ”₯

the source code repository for Test2-Suite lives at https://github.com/Test-More/test-more/. go wild, go look, go star it. ⭐


πŸ’œ MAINTAINERS πŸ’œ

  • Chad Granum <exodist@cpan.org>

🫢 AUTHORS 🫢

  • Chad Granum <exodist@cpan.org>

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!! πŸŽ€βœ¨ this was perl v5.44.0, dated 2026-10-17, and you've been reading Test2::Tools(3perl). mwah πŸ’…πŸ’– go write some tools.

πŸ“¦ 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