Test2::...:Threads(3)

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

πŸ’… 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::Threads uses 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 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