--- AnyEvent/t/03_child.t 2007/11/02 19:20:36 1.2 +++ AnyEvent/t/03_child.t 2009/07/18 15:51:52 1.17 @@ -1,43 +1,81 @@ -$|=1; -BEGIN { print "1..5\n" } +use POSIX (); -use AnyEvent; - -print "ok 1\n"; - -my $pid = fork; +no warnings; -defined $pid or die "unable to fork"; +use AnyEvent; +use AnyEvent::Impl::Perl; -# work around Tk bug until it has been fixed. -my $timer = AnyEvent->timer (after => 2, cb => sub { }); +BEGIN { + # check for broken perls + if ($^O =~ /mswin32/i) { + my $ok; + local $SIG{CHLD} = sub { $ok = 1 }; + kill 'CHLD', 0; + + unless ($ok) { + print <condvar; +$| = 1; print "1..50\n"; -unless ($pid) { - print "ok 2\n"; - exit 3; -} +$AnyEvent::MAX_SIGNAL_LATENCY = 0.2; -my $w = AnyEvent->child (pid => $pid, cb => sub { - print 3 == ($? >> 8) ? "" : "not ", "ok 3\n"; - $cv->broadcast; -}); +for my $it ("", 1, 2, 3, 4) { + print "ok ${it}1\n"; -$cv->wait; + AnyEvent::detect; # force-load event model -fork || exit 7; + my $pid = fork; -my $cv2 = AnyEvent->condvar; + defined $pid or die "unable to fork"; -my $w2 = AnyEvent->child (pid => 0, cb => sub { - print 7 == ($? >> 8) ? "" : "not ", "ok 4\n"; - $cv2->broadcast; -}); +# work around Tk bug until it has been fixed. +#my $timer = AnyEvent->timer (after => 2, cb => sub { }); -$cv2->wait; + my $cv = AnyEvent->condvar; -print "ok 5\n"; + unless ($pid) { + print "ok ${it}2\n"; + POSIX::_exit 3; + } + + my $w = AnyEvent->child (pid => $pid, cb => sub { + print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n"; + print 3 == ($_[1] >> 8) ? "" : "not ", "ok ${it}4 # 3 == $_[1] >> 8 ($_[1])\n"; + $cv->broadcast; + }); + + $cv->wait; + + my $pid2 = fork || POSIX::_exit 7; + + my $cv2 = AnyEvent->condvar; + + my $w2 = AnyEvent->child (pid => 0, cb => sub { + print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n"; + print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n"; + $cv2->broadcast; + }); + + my $error = AnyEvent->timer (after => 5, cb => sub { + print <wait; + + print "ok ${it}7\n"; + print "ok ${it}8\n"; + print "ok ${it}9\n"; + print "ok ", $it*10+10, "\n"; +}