Test2:...::Fork(3perl)
π NAME π
Test2::Require::Fork β bestie, this one just skips your whole test file unless your system can actually fork. That's it, that's the job. β¨
(Also hi, you're reading Test2:...::Fork(3perl), section 3 of the perl manual, the Perl Programmers Reference Guide situation π«Ά)
πΈ DESCRIPTION πΈ
okay so listen. Writing tests that need to fork is like, super common. But not every system can fork! Some of them are out here living their no-fork lifestyle and that's valid of them, no shade. π
So instead of you having to figure that out yourself, this library does the detective work and checks whether forking is even a thing on the current system. And if forking is not supported? It skips all the tests and exits true. Clean. Iconic. No drama. π
β¨ SYNOPSIS β¨
use Test2::Require::Fork;
... Code that forks ...
that's literally it bestie, drop the use at the top and go fork your little heart out π₯
π§ EXPLANATION π§
ngl, figuring out whether the current system supports forking is not a simple vibe check. Here's the whole saga, in code form:
use Config;
sub CAN_FORK {
return 1 if $Config{d_fork};
# Some platforms use ithreads to mimic forking
return 0 unless $^O eq 'MSWin32' || $^O eq 'NetWare';
return 0 unless $Config{useithreads};
return 0 unless $Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/;
# Threads are not reliable before 5.008001
return 0 unless $] >= 5.008001;
# Devel::Cover currently breaks with threads
return 0 if $INC{'Devel/Cover.pm'};
return 1;
}
so yeah. Look at all that. π And now imagine copy-pasting that non-trivial mess into every single test that needs to fork. It's giving error-prone, lowkey. It's so easy to forget a bit, or get a bit wrong, and then your tests are just doing nonsense and you don't even know why.
And that's not even the whole story β on top of all these checks, you also have to tell the harness that no tests should run, plus the reason why. Every. Single. Time. Exhausting. This module ate and left no crumbs so you don't have to. π
π SEE ALSO π
Test2::Require::RealForkβ basically this module's sibling, except it will skip on any perl that only has fork emulation. Like, if it's not the real thing, it's not interested, periodt.Test2::Require::Threadsβ skip the test file if the system doesn't support threads. same energy, different feature. π
π SOURCE π
The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. go peek, it's cute π¦
π 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/
and that's a wrap bestie!! π«Ά this beautiful little page comes to you from perl v5.44.0, dated 2026-10-17, straight out of the Perl Programmers Reference Guide β mwah, no notes πβ¨πΈ
π¦ 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