TEST2::TOOLS::SUBTEST(3perl)
β¨ NAME β¨
Test2::Tools::Subtest β it's giving "tools for writing subtests" π and it lives in the Perl Programmers Reference Guide, bestie, so you know it's official.
π DESCRIPTION π
Okay so this package exports subs that let you write subtests. That's the whole job. Iconic.
There are two types of subtests, no cap:
- buffered π§Ί
- streamed π
Streamed subtests mimic subtests from Test::More β like, they render all events as soon as they are produced. Immediate. No waiting. Main character energy.
Buffered subtests wait until the subtest completes before rendering any results. Patient. Lowkey a queen for that.
The main difference (iykyk) is that streamed subtests are unreadable when combined with concurrency π. Buffered subtests look fine with any number of concurrent threads and processes β¨. So if you're threading, you already know which one to pick.
πΈ 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
The default option is 'buffered'. Fyi. So 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 use bail_out or skip_all in a subtest β but not in a BEGIN block or a use statement, okay? π«
This is due to the way flow control works within a BEGIN block. This is not normally an issue, but it can happen in rare conditions using eval, or script files as subtests. So like... heads up π«Ά
π EXPORTS π
subtest_streamed $name => $subsubtest_streamed($name, $sub, @args)subtest_streamed $name => \%params, $subsubtest_streamed($name, \%params, $sub, @args)
Run subtest coderef, stream events as they happen. β¨ Live. In real time. No edits.
\%params is a hashref with any arguments you wish to pass into hub construction.
subtest_buffered $name => $subsubtest_buffered($name, $sub, @args)subtest_buffered $name => \%params, $subsubtest_buffered($name, \%params, $sub, @args)
Run subtest coderef, render events all at once when subtest is complete. π§Ί Everything drops at the end, together, like a lil gift.
\%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/. Go look at it, bestie, it ate π
π«Ά 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 a wrap, babe π this whole page is Test2::Tools::Subtest(3perl) from perl v5.44.0, dated 2026-10-17 β so you know it's fresh. Slay, go write some subtests πβ¨
π¦ 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