Test2::...Subtest(3)

πŸ“¦ version 1.302214, in opensuse-leap 16.0

okay bestie, this is the User Contributed Perl Documentation entry for Test2::...Subtest(3) β€” aka the page for Test2::Tools::AsyncSubtest, and it’s literally giving β€œasync subtests but make it fashion.” πŸ’…βœ¨

🌸 NAME 🌸

The main character is Test2::Tools::AsyncSubtest β€” tools for writing async subtests. That’s the whole gig, no cap. 🫢

πŸ¦‹ DESCRIPTION πŸ¦‹

These are tools for writing async subtests. Async subtests are subtests that can be started and stashed so they can keep receiving events while other events are also being generated. Like, they’re off doing their own thing but still showing up to the group chat. πŸ’–

✨ SYNOPSIS ✨

use Test2::Bundle::Extended;
use Test2::Tools::AsyncSubtest;

my $ast1 = async_subtest local => sub {
    ok(1, "Inside subtest");
};

my $ast2 = fork_subtest child => sub {
    ok(1, "Inside subtest in another process");
};

# You must call finish on the subtests you create. Finish will wait/join on
# any child processes and threads.
$ast1->finish;
$ast2->finish;

done_testing;

πŸ’– EXPORTS πŸ’–

Everything is exported by default. Yes, everything β€” no import gymnastics required. πŸŽ€

  • async_subtest 🧚
    • $ast = async_subtest $name
    • $ast = async_subtest $name => sub { ... }
    • $ast = async_subtest $name => \%hub_params, sub { ... }
    • Create an async subtest. Run the codeblock if it is provided.
  • fork_subtest πŸ“
    • $ast = fork_subtest $name => sub { ... }
    • $ast = fork_subtest $name => \%hub_params, sub { ... }
    • Create an async subtest. Run the codeblock in a forked process.
  • thread_subtest πŸ’€
    • $ast = thread_subtest $name => sub { ... }
    • $ast = thread_subtest $name => \%hub_params, sub { ... }
    • ** DISCOURAGED ** Threads are fragile. Thread tests are not even run unless the AUTHOR_TESTING or T2_DO_THREAD_TESTS env vars are enabled.
    • Create an async subtest. Run the codeblock in a thread.

πŸŽ€ NOTES πŸŽ€

  • Async Subtests are always buffered.
    • Always buffered. Like, that’s the note. 🫢
  • Do not use done_testing() yourself.
    • Using done_testing() inside an async subtest will not work properly, the async subtest must be finalized by calling $st->finish. Periodt. πŸ’…

πŸ”₯ SOURCE πŸ”₯

The source code repository for Test2-AsyncSubtest can be found at https://github.com/Test-More/test-more/. Go peek, bestie. πŸ‘€

πŸ‘‘ MAINTAINERS πŸ‘‘

Chad Granum <exodist@cpan.org> β€” maintained with love. 🫢

🌈 AUTHORS 🌈

Chad Granum <exodist@cpan.org> β€” author energy, iconic. ✨

Copyright Chad Granum <exodist7@gmail.com>.

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/.


mwah πŸ’– this page is from perl v5.42.0, dated 2025-07-28, and it’s the Test2::...Subtest(3) manual β€” bye bestie, go write some async subtests! πŸ¦‹βœ¨

πŸ“¦ where this page comes from