TEST2::REQUIRE::THREADS(3perl)

πŸ’– Test2::Require::Threads β€” from the Perl Programmers Reference Guide, but make it cute ✨

okay bestie, listen up, because this little page lives in the perl manual (yes, section 3perl, we're fancy) and it's about to save you from a truly tragic test run 🫢


🌸 NAME 🌸

Test2::Require::Threads β€” skip a whole test file unless the system actually supports threading πŸ’…

Like, no cap. If your machine can't do threads, this thing politely dips out.


✨ DESCRIPTION ✨

okay so, here's the situation. Writing tests that need threads? Super common. Extremely normal. Main character behavior, even. πŸŽ€

But here's the tea: not all systems support threads. Not all of them!! And honestly, this library does the hard work for you β€” it checks whether threading is supported on the current system. And if threading is not supported?

it skips all tests and exits true. πŸ¦‹

So you don't get a wall of red, you get a graceful little skip. Iconic. ✨


πŸ’« SYNOPSIS πŸ’«

use Test2::Require::Threads;

... Code that uses threads ...

that's it. that's the whole vibe. drop that use in, then go wild with your thread code πŸ”₯


🧚 EXPLANATION 🧚

ngl, checking whether the current system supports threading is not as simple as it looks. here's literally how you'd have to do it by hand:

use Config;

sub CAN_THREAD {
    # Threads are not reliable before 5.008001
    return 0 unless $] >= 5.008001;
    return 0 unless $Config{'useithreads'};

    # Devel::Cover currently breaks with threads
    return 0 if $INC{'Devel/Cover.pm'};
    return 1;
}

see that? that's three separate checks and a version gate, bestie. 😭

and the thing is β€” copying this whole non-trivial chunk of code into every single test that needs threads? that's error-prone. you forget a bit, you get it slightly wrong, and then your test suite is just lying to you. πŸ’€ lowkey cursed.

and on top of all those checks, you also have to tell the harness that no tests should run β€” and why. that's a whole extra job. Test2::Require::Threads does the entire thing for you. obsessed. 🫢


🌈 SEE ALSO 🌈

  • Test2::Require::Fork β€” skip the test file if the system does not support forking. (the sibling!! πŸ’œ)
  • Test2 β€” Test2::Require::Threads uses Test2 under the hood. that's the engine, iykyk. πŸ‘‘

πŸŽ€ SOURCE πŸŽ€

the source code repository for Test2-Suite lives right here:

https://github.com/Test-More/test-more/

go look, it's giving open source excellence ✨


πŸ’… MAINTAINERS πŸ’…

  • Chad Granum <exodist@cpan.org>

🌸 AUTHORS 🌸

  • Chad Granum <exodist@cpan.org>

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/


okay that's the whole page, bestie, you're officially certified in thread-skipping πŸ’– and as a lil goodbye kiss from the manual itself: this was perl v5.44.0, dated 2026-10-17, from the Test2:...Threads(3perl) page πŸ¦‹ slay, 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