Test2:...Tester(3perl)

✨ Test2::Tools::Tester β€” the Test2:...Tester(3perl) era ✨

okay bestie, welcome to the page for Test2::Tools::Tester πŸ’… this lives in the Perl Programmers Reference Guide and it's literally the toolkit you reach for when you're testing... other testing tools. meta?? yes. iconic?? also yes πŸŽ€


🌸 NAME 🌸

Test2::Tools::Tester β€” Tools to help you test other testing tools. πŸ’–


πŸ¦‹ DESCRIPTION πŸ¦‹

So basically this is a lil collection of tools that are useful when you're testing other test tools. that's the whole vibe. no cap. ✨


πŸ’… SYNOPSIS πŸ’…

use Test2::Tools::Tester qw/event_groups filter_events facets/;

use Test2::Tools::Basic qw/plan pass ok/;
use Test2::Tools::Compare qw/is like/;

my $events = intercept {
    plan 11;

    pass('pass');
    ok(1, 'pass');

    is(1, 1, "pass");
    like(1, 1, "pass");
};

# Grab events generated by tools in Test2::Tools::Basic
my $basic = filter $events => 'Test2::Tools::Basic';

# Grab events generated by tools in Test2::Tools::Basic;
my $compare = filter $events => 'Test2::Tools::Compare';

# Grab events generated by tools named 'ok'.
my $oks = filter $events => qr/.*::ok$/;

my $grouped = group_events $events;
# Breaks events into this structure:
{
    '__NA__' => [ ... ],
    'Test2::Tools::Basic' => {
        '__ALL__' => [ $events->[0], $events->[1], $events->[2] ],
        plan => [ $events->[0] ],
        pass => [ $events->[1] ],
        ok => [ $events->[2] ],
    },
    Test2::Tools::Compare => { ... },
}

# Get an arrayref of all the assert facets from the list of events.
my $assert_facets = facets assert => $events;
# [
#   bless({ details => 'pass', pass => 1}, 'Test2::EventFacet::Assert'),
#   bless({ details => 'pass', pass => 1}, 'Test2::EventFacet::Assert'),
# ]

# Same, but for info facets
my $info_facets = facets info => $events;

🫢 EXPORTS 🫢

k so, plot twist: no subs are exported by default. πŸ™ˆ you gotta ask for them, bestie. main character energy only.

πŸ“ $array_ref = filter $events => $PACKAGE

πŸ“ $array_ref = filter $events => $PACKAGE1, $PACKAGE2

πŸ“ $array_ref = filter $events => qr/match/

πŸ“ $array_ref = filter $events => qr/match/, $PACKAGE

This one takes an arrayref of events as the first argument. and then β€” listen β€” every additional argument has to be either a package name or a regex. Any event that got generated by a tool in any of those packages, or by a tool that matches any of those regexes, gets handed back to you in an arrayref. slay. ✨

πŸŽ€ $grouped = group_events($events)

This function iterates all the events in the argument arrayref and splits them into groups. the resulting data structure is, literally:

{ PACKAGE => { SUBNAME => [ $EVENT1, $EVENT2, ... }}

If the package of an event is not known, it gets put into an arrayref under the '__NA__' key at the root of the structure. and if a sub name is not known, it will typically go under the '__ANON__' key in under the package name. yes, that's the actual key name. πŸ’€

On top of that there's an '__ALL__' key under each package which stores all of the events sorted into that group. everything. the whole squad. πŸ‘‘

A more complete example:

{
    '__NA__' => [ $event->[3] ],
    'Test2::Tools::Basic' => {
        '__ALL__' => [ $events->[0], $events->[1], $events->[2] ],
        plan => [ $events->[0] ],
        pass => [ $events->[1] ],
        ok => [ $events->[2] ],
    },
}

🌈 $arrayref = facets TYPE => $events

This function will compile a list of all facets of the specified type that are found in the arrayref of events. here's the tea: if the facet has a "Test2::EventFacet::TYPE" package available, then the facet will be constructed into an instance of that class β€” otherwise it is left as a hashref. and Facet Order is preserved. periodt. πŸ’…

my $assert_facets = facets assert => $events;
# [
#   bless({ details => 'pass', pass => 1}, 'Test2::EventFacet::Assert'),
#   bless({ details => 'pass', pass => 1}, 'Test2::EventFacet::Assert'),
# ]

πŸ”₯ SOURCE πŸ”₯

The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. go lurk, go contribute, go be nosy. 🧚


πŸ‘‘ 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, filed under Test2:...Tester(3perl). love that for us. go write some tests about tests. 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