--- AnyEvent/t/03_child.t 2006/12/11 01:16:09 1.1 +++ AnyEvent/t/03_child.t 2009/07/20 06:00:42 1.18 @@ -1,32 +1,81 @@ -$|=1; -BEGIN { print "1..4\n" } +use POSIX (); + +no warnings; + +BEGIN { + # check for broken perls + if ($^O =~ /mswin32/i) { + my $ok; + local $SIG{CHLD} = sub { $ok = 1 }; + kill 'CHLD', 0; + + unless ($ok) { + print <timer (after => 2, cb => sub { }); + AnyEvent::detect; # force-load event model -my $cv = AnyEvent->condvar; + my $pid = fork; -unless ($pid) { - print "ok 2\n"; - exit 3; -} + defined $pid or die "unable to fork"; -my $w = AnyEvent->child (pid => $pid, cb => sub { - print 3 == ($? >> 8) ? "" : "not ", "ok 3\n"; - $cv->broadcast; -}); +# work around Tk bug until it has been fixed. +#my $timer = AnyEvent->timer (after => 2, cb => sub { }); -$cv->wait; + my $cv = AnyEvent->condvar; -print "ok 4\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"; +}