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::Threadsuses 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 β
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