Test2::Tools(3)

πŸ“¦ version 1.302214, in opensuse-leap 16.0

πŸ’– NAME πŸ’–

Okay bestie, welcome to Test2::Tools(3) β€” straight from the User Contributed Perl Documentation corner. This is Test2::Tools β€” the documentation for Tools. That’s the whole vibe. ✨

πŸ› οΈ DESCRIPTION πŸ› οΈ

Tools are packages that export test functions, typically all related to one specific aspect of testing. If you’ve got a couple different categories of exports, you may want to break them into separate modules. Slay, organize your exports. πŸ’…

Tools should export testing functions. Loading tools should not have side-effects or alter the behavior of other tools. If you want to alter behaviors or create side-effects, you probably want to write a Test2::Plugin. Noted β€” no sneaky side quests. 🫢

❓ FAQ ❓

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

This question arises since Tools is the only namespace in the plural. It’s because 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. Nobody would like Test2::Bundles::Foo. Like, nobody. πŸ’€

🚫 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. So don’t do it, bestie. πŸ™ˆ

✨ 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. Iconic behavior, honestly. πŸ‘‘

πŸ“¦ SOURCE πŸ“¦

The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. Go look, bestie. πŸ¦‹

πŸ‘‘ MAINTAINERS πŸ‘‘

Chad Granum <exodist@cpan.org> β€” maintaining and slaying. Periodt. πŸ’œ

πŸ’œ AUTHORS πŸ’œ

Chad Granum <exodist@cpan.org> β€” also here in AUTHORS. We love a consistent icon. 🌸

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/.


Mwah πŸ’‹ β€” this page is from perl v5.42.0, dated 2025-07-28, and it’s the Test2::Tools(3) manual. Byeee ✨

πŸ“¦ where this page comes from