Check::Fork - Check fork functionality.
use Check::Fork qw(check_fork $ERROR_MESSAGE); my $ret = check_fork($config_hr, $os); print $ERROR_MESSAGE."\n";
There is need of check for fork functionality in tests. Actually we have many duplicated and not same check code in distributions. Sic!
Intent of this module is create common code for check and test all behaviours. Extra thing is error message which describe issue.
check_fork
my $ret = check_fork($config_hr, $os);
Check possibility of forking functionality on system.
Variable $config_hr is primarily for testing and default is \%Config::Config.
$config_hr
\%Config::Config
Variable $os is primarily for testing and default is $^O.
$os
$^O
Return value is 1 as possible fork() or 0 as not possible fork(). If return value is 0, set $ERROR_MESSAGE variable.
$ERROR_MESSAGE
Returns 0/1.
check_fork(): Set $ERROR_MESSAGE variable if $ret is 0: No fork() routine available. $^O: No interpreter-based threading implementation. $^O: No PERL_IMPLICIT_SYS ccflags set.
use strict; use warnings; use Check::Fork qw(check_fork $ERROR_MESSAGE); if (check_fork()) { print "We could fork.\n"; } else { print "We couldn't fork.\n"; print "Error message: $ERROR_MESSAGE\n"; } # Output on Unix with Config{'d_fork'} set: # We could fork. # Output on Unix without Config{'d_fork'} set: # We couldn't fork. # Error message: No fork() routine available. # Output on Windows without $Config{'useithreads'} set: # We couldn't fork. # Error message: MSWin32: No interpreter-based threading implementation.
use strict; use warnings; use Check::Fork qw(check_fork); use Check::Socket qw(check_socket); if (! check_fork()) { print "We couldn't fork.\n"; print "Error message: $Check::Fork::ERROR_MESSAGE\n"; } elsif (! check_socket()) { print "We couldn't use socket communication.\n"; print "Error message: $Check::Socket::ERROR_MESSAGE\n"; } else { print "We could use fork and socket communication.\n"; } # Output on Unix: # We could use fork and socket communication.
use strict; use warnings; use Check::Fork qw(check_fork); use Check::Socket qw(check_socket); use Test::More 'tests' => 1; SKIP: { skip $Check::Fork::ERROR_MESSAGE, 1 unless check_fork(); skip $Check::Socket::ERROR_MESSAGE, 1 unless check_socket(); ok(1, 'Fork and Socket test'); }; # Output on Unix: # 1..1 # ok 1 - Fork and Socket test
Config, Exporter, Readonly.
Check socket functionality.
Skip a test file unless the system supports forking
Skip a test file unless the system supports true forking
https://github.com/michal-josef-spacek/Check-Fork
Michal Josef Špaček mailto:skim@cpan.org
http://skim.cz
© 2021-2024 Michal Josef Špaček
BSD 2-Clause License
0.05
To install Check::Fork, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Check::Fork
CPAN shell
perl -MCPAN -e shell install Check::Fork
For more information on module installation, please visit the detailed CPAN module installation guide.