NAME
Check::Fork - Check fork functionality.
SYNOPSIS
use Check::Fork qw(check_fork $ERROR_MESSAGE);
my $ret = check_fork($config_hr, $os);
print $ERROR_MESSAGE."\n";
DESCRIPTION
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.
SUBROUTINES
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
.
Variable $os
is primarily for testing and default is $^O
.
Return value is 1 as possible fork() or 0 as not possible fork(). If return value is 0, set $ERROR_MESSAGE
variable.
Returns 0/1.
ERRORS
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.
EXAMPLE1
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.
EXAMPLE2
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.
EXAMPLE3
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
DEPENDENCIES
SEE ALSO
- Check::Socket
-
Check socket functionality.
- Test2::Require::Fork
-
Skip a test file unless the system supports forking
- Test2::Require::RealFork
-
Skip a test file unless the system supports true forking
REPOSITORY
https://github.com/michal-josef-spacek/Check-Fork
AUTHOR
Michal Josef Špaček mailto:skim@cpan.org
LICENSE AND COPYRIGHT
© 2021-2024 Michal Josef Špaček
BSD 2-Clause License
VERSION
0.05