Test2::...:Subtest(3)
πΈ NAME πΈ
Test2::Tools::Subtest β tools for writing subtests. This is the user-contributed Perl doc page for it, filed under Test2::...:Subtest(3), and bestie, it's literally all about making your subtests cute and organized. π
π¦ DESCRIPTION π¦
This package exports subs that let you write subtests. There are two types of subtests, buffered and streamed β two flavors, no cap. β¨
- Streamed subtests mimic subtests from
Test::More: they render all events as soon as they are produced. Instant gratification energy. π - Buffered subtests wait until the subtest completes before rendering any results. Patient queen behavior. π
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. So if threads/processes are in the group chat, buffered is the vibe. π
β¨ 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'. 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 use statement. This is due to the way flow control works within a BEGIN block. This is not normally an issue, but can happen in rare conditions using eval, or script files as subtests. So don't come for me, it's a flow-control thing. π
π EXPORTS π
subtest_streamed
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. \%params is a hashref with any arguments you wish to pass into hub construction.
subtest_buffered
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. \%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/
Cute sign-off: this page is from perl v5.42.0 and dated 2025-07-28. Bye bestie, go write some iconic subtests! π
π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Test-Simple 1.302214-bp160.1.2 Β· Artistic-1.0 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