Test::S...:CanFork(3)

πŸ“¦
version 1.302027 Β· 2 versions
, in fedora 43

πŸ’– Test::Stream::Plugin::CanFork πŸ’–

okay bestie, so this is Test::Stream::Plugin::CanFork, part of the Test::Stream era of Perl testing (rip, she's retired now, more on that in a sec), and it lives in the User Contributed Perl Documentation section of your man pages. πŸŽ€


✨ NAME ✨

Test::Stream::Plugin::CanFork β€” skip a test file unless the system supports forking 🍴


πŸ’€ DEPRECATED πŸ’€

not me having to deliver this news but… this whole distribution is deprecated in favor of Test2, Test2::Suite, and Test2::Workflow. it's giving "we don't do that here anymore" πŸ™ˆ

if you wanna make the switch, there's a conversion guide waiting for you over in Test::Stream::Manual::ToTest2. go read it, i'll wait πŸ’…


🌸 DESCRIPTION 🌸

so here's the vibe: it's super common to write tests that need to fork. but like… not every system can even do that?? 😭 so instead of every single test file out here reinventing the fork-check wheel, this library does the hard work for you β€” it checks whether forking is supported on the current system. and if forking is not supported? it skips all the tests and exits true. iconic behavior honestly. πŸ‘‘


✨ SYNOPSIS ✨

the basic girlie setup:

    use Test::Stream::Plugin::CanFork;

    ... Code that forks ...

or, if you need the real deal:

    use Test::Stream::Plugin::CanFork real => 1;

    ... Code that requires true fork support (not emulated) ...

πŸ¦‹ EXPLANATION πŸ¦‹

okay so checking whether a system supports forking is genuinely not simple. like, the way that this is a whole ordeal?? here's literally how you'd have to do it by hand:

    use Config;

    sub CAN_FORK {
        return 1 if $Config{d_fork};

        # Some platforms use ithreads to mimick 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;
    }

copy-pasting this non-trivial little monster into every single test that needs to fork is dumb. fr fr. it's so easy to forget a bit, or get it wrong entirely, and then your tests are lying to you 😭

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 thing. exhausting. this plugin handles it so you don't have to. 🫢


πŸ‘‘ SEE ALSO πŸ‘‘

  • Test::Stream::Plugin::CanThread β€” skips the test file if the system doesn't support threads. 🧡
  • Test::Stream β€” Test::Stream::Plugin::CanFork uses Test::Stream under the hood. iykyk πŸ’œ

🌈 SOURCE 🌈

the source code repo for Test::Stream is right here, bestie:

http://github.com/Test-More/Test-Stream/


πŸŽ€ MAINTAINERS πŸŽ€

Chad Granum <exodist@cpan.org>


⭐ AUTHORS ⭐

Chad Granum <exodist@cpan.org>


Copyright 2015 Chad Granum <exodist7@gmail.com>.

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 the whole page, babe ✨ this one shipped as part of perl v5.42.0, dated 2025-07-25, straight from the User Contributed Perl Documentation β€” stay forkable, stay fabulous πŸ’–πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from