TEST2::TOOLS::SUBTEST(3pm)
β¨ NAME β¨
Test2::Tools::Subtest β tools for writing subtests, bestie π
This is the Test2::Tools::Subtest page from the Perl Programmers Reference Guide, and it is literally all about making subtests happen. Periodt.
π¦ DESCRIPTION π¦
This package exports subs that let you write subtests. No cap, that is the whole vibe.
There are two types of subtests: buffered and streamed. Streamed subtests mimic subtests from Test::More in that they render all events as soon as they are produced. Buffered subtests wait until the subtest completes before rendering any results.
The main difference is that streamed subtests are unreadable when combined with concurrency. Buffered subtests look fine with any number of concurrent threads and processes. Slay for buffered, honestly.
πΈ SYNOPSIS πΈ
BUFFERED
use Test2::Tools::Subtest qw/subtest_buffered/;
subtest_buffered my_test => sub {
ok(1, "subtest event A");
ok(1, "subtest event B");
};
This will produce output like this:
ok 1 - my_test {
ok 1 - subtest event A
ok 2 - subtest event B
1..2
}
STREAMED
Quick reminder bestie: the default option is 'buffered'. If you want streamed subtests, the way Test::Builder does it, use this:
use Test2::Tools::Subtest qw/subtest_streamed/;
subtest_streamed my_test => sub {
ok(1, "subtest event A");
ok(1, "subtest event B");
};
This will produce output like this:
# Subtest: my_test
ok 1 - subtest event A
ok 2 - subtest event B
1..2
ok 1 - Subtest: my_test
β οΈ IMPORTANT NOTE β οΈ
You can usebail_outorskip_allin a subtest, but not in aBEGINblock orusestatement. This is due to the way flow control works within aBEGINblock. This is not normally an issue, but can happen in rare conditions usingeval, or script files as subtests.
Like, it is usually fine, but do not come for me when the rare condition hits. π
π EXPORTS π
subtest_streamed
subtest_streamed $name => $sub
subtest_streamed($name, $sub, @args)
subtest_streamed $name => \%params, $sub
subtest_streamed($name, \%params, $sub, @args)
Run subtest coderef, stream events as they happen. It is giving live commentary energy β¨
\%params is a hashref with any arguments you wish to pass into hub construction.
subtest_buffered
subtest_buffered $name => $sub
subtest_buffered($name, $sub, @args)
subtest_buffered $name => \%params, $sub
subtest_buffered($name, \%params, $sub, @args)
Run subtest coderef, render events all at once when subtest is complete. Very βsave it all for the revealβ behavior π
\%params is a hashref with any arguments you wish to pass into hub construction.
π SOURCE π
The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/.
π 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/
This edition is perl v5.42.3, dated 2026-11-03 β bye bestie, go write some iconic subtests! ππ«Ά
π¦ 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