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 π
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