blib/lib/POE/Test/Loops/z_merijn_sigchld_system.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 60 CC 1 SCAR 6.9
CC
1
Cov
0%
POE::Kernel::ASSERT_DEFAULT
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/perl -w
2 # vim: ts=2 sw=2 expandtab filetype=perl
3  
4  
5 # System shouldn't fail in this case.
6  
7 use strict;
8  
9 sub POE::Kernel::ASSERT_DEFAULT () { 1 }
10  
11 BEGIN {
12 package
13 POE::Kernel;
14 use constant TRACE_DEFAULT => exists($INC{'Devel/Cover.pm'});
15 }
16  
17 use POE;
18  
19 use constant TESTS => 4;
20 use Test::More tests => TESTS;
21  
22 my $command = "/bin/true";
23  
24 SKIP: {
25 my @commands = grep { -x } qw(/bin/true /usr/bin/true);
26 skip( "Couldn't find a 'true' to run under system()", TESTS ) unless (
27 @commands
28 );
29  
30 my $command = shift @commands;
31 diag( "Using '$command' as our thing to run under system()" );
32  
33 my $caught_child = 0;
34  
35 POE::Session->create(
36 inline_states => {
37 _start => sub {
38 my $sig_chld;
39  
40 $sig_chld = $SIG{CHLD};
41 $sig_chld = "(undef)" unless defined $sig_chld;
42 $! = undef;
43  
44 is(
45 system( $command ), 0,
46 "System returns properly chld($sig_chld) err($!)"
47 );
48  
49 # system() may return -1 when $SIG{CHLD} is in effect.
50 # https://rt.perl.org/rt3/Ticket/Display.html?id=105700
51 #
52 # The machinations to avoid this in POE would incur an ongoing
53 # performance penalty for everyone:
54 #
55 # 1. Save the contents of $SIG{CHLD}.
56 #
57 # 2. Set $SIG{CHLD} = 'DEFAULT' before dispatching every
58 # event, unless it's already 'DEFAULT'.
59 #
60 # 3. If $SIG{CHLD} is deliberately to 'DEFAULT' as a result of
61 # actions inside a callback, set a flag indicating that the
62 # value saved in step #1 should not be restored.
63 #
64 # 4. At the end of every event, restore $SIG{CHLD} to the
65 # saved value, unless the flag not to restore it is set.
66 #
67 # Less convenient but much more optimal is for application and
68 # module developers to localize $SIG{CHLD} = 'DEFAULT' before
69 # calling system() or causing a module to call system().
70  
71 $_[KERNEL]->sig( 'CHLD', 'chld' );
72 $sig_chld = $SIG{CHLD};
73 $sig_chld = "(undef)" unless defined $sig_chld;
74 $! = undef;
75  
76 is(
77 system( $command ), 0,
78 "System returns properly chld($sig_chld) err($!)"
79 );
80  
81 # Turn off the handler, and try again.
82  
83 $_[KERNEL]->sig( 'CHLD' );
84 $sig_chld = $SIG{CHLD};
85 $sig_chld = "(undef)" unless defined $sig_chld;
86 $! = undef;
87  
88 is(
89 system( $command ), 0,
90 "System returns properly chld($sig_chld) err($!)"
91 );
92 },
93 chld => sub {
94 diag( "Caught child" );
95 $caught_child++;
96 },
97 _stop => sub { }, # Pacify assertions.
98 }
99 );
100  
101 is( $caught_child, 0, "no child procs caught" );
102 }
103  
104 POE::Kernel->run();
105  
106 1;