Test2::...:Threads(3)
π NAME π
Okay bestie, welcome to the Test2::...:Threads(3)</p> page β that's the User Contributed Perl Documentation manual name, and the module living inside it is Test2::Require::Threads β and what it does is skip a test file unless the system supports threading. That's it. That's the whole gig. Iconic, honestly. π§΅β¨
πΈ DESCRIPTION πΈ
So like β it is fairly common to write tests that need to use threads. Not all systems support threads, which is honestly so rude of them. π This library does the hard work of checking if threading is supported on the current system, so you don't have to.
If threading is not supported, then this will skip all tests and exit true. No drama, no failures, just a graceful little exit-stage-left. π
β¨ SYNOPSIS β¨
use Test2::Require::Threads;
... Code that uses threads ...
That's literally it. Drop that use line at the top and then go off with your thread code, queen. π
π¦ EXPLANATION π¦
Checking if the current system supports threading is not simple β like, at all. So here's an example of how to do it, because seeing the actual logic really eats:
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;
}
Lowkey look at all those checks. Duplicating this non-trivial code in all the tests that need to use threads is error-prone β it is easy to forget bits, or get it wrong. Like, one missed line and your whole test suite is giving chaos. π
And on top of these checks, you also need to tell the harness that no tests should run and why. Which is a whole extra conversation you do not want to be having in every single test file. Hence: this module. π«Ά
π₯ SEE ALSO π₯
Test2::Require::Forkβ Skip the test file if the system does not support forking. Sibling energy fr fr.Test2βTest2::Require::Threadsuses Test2 under the hood. The main character it's all built on. π
π SOURCE π
The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. Go lurk, it's fine, we all do it. π
π 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/
Ngl the legal bits matter too bestie β same terms as Perl itself, no cap, read the license link. π
Okay that's the whole page, you ate that. π
β¨ This was perl v5.42.0, dated 2025-07-28, and it's the Test2::...:Threads(3) page signing off β mwah, go write some threaded tests π§π
π¦ 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