1Test2::Require::Fork(3)User Contributed Perl DocumentatioTnest2::Require::Fork(3)
2
3
4
6 Test2::Require::Fork - Skip a test file unless the system supports
7 forking
8
10 It is fairly common to write tests that need to fork. Not all systems
11 support forking. This library does the hard work of checking if forking
12 is supported on the current system. If forking is not supported then
13 this will skip all tests and exit true.
14
16 use Test2::Require::Fork;
17
18 ... Code that forks ...
19
21 Checking if the current system supports forking is not simple. Here is
22 an example of how to do it:
23
24 use Config;
25
26 sub CAN_FORK {
27 return 1 if $Config{d_fork};
28
29 # Some platforms use ithreads to mimic forking
30 return 0 unless $^O eq 'MSWin32' || $^O eq 'NetWare';
31 return 0 unless $Config{useithreads};
32 return 0 unless $Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/;
33
34 # Threads are not reliable before 5.008001
35 return 0 unless $] >= 5.008001;
36
37 # Devel::Cover currently breaks with threads
38 return 0 if $INC{'Devel/Cover.pm'};
39 return 1;
40 }
41
42 Duplicating this non-trivial code in all tests that need to fork is
43 error-prone. It is easy to forget bits, or get it wrong. On top of
44 these checks, you also need to tell the harness that no tests should
45 run and why.
46
48 Test2::Require::CanReallyfork
49 Similar to this module, but will skip on any perl that only has
50 fork emulation.
51
52 Test2::Require::CanThread
53 Skip the test file if the system does not support threads.
54
56 The source code repository for Test2-Suite can be found at
57 https://github.com/Test-More/Test2-Suite/.
58
60 Chad Granum <exodist@cpan.org>
61
63 Chad Granum <exodist@cpan.org>
64
66 Copyright 2018 Chad Granum <exodist@cpan.org>.
67
68 This program is free software; you can redistribute it and/or modify it
69 under the same terms as Perl itself.
70
71 See http://dev.perl.org/licenses/
72
73
74
75perl v5.32.1 2021-01-27 Test2::Require::Fork(3)