ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/03_child.t
(Generate patch)

Comparing AnyEvent/t/03_child.t (file contents):
Revision 1.5 by root, Fri Nov 16 05:08:18 2007 UTC vs.
Revision 1.14 by root, Fri Jul 17 22:05:12 2009 UTC

1BEGIN {
2 # check for broken perls
3 if ($^O =~ /mswin32/i) {
4 my $ok;
5 local $SIG{CHLD} = sub { $ok = 1 };
6 kill 'CHLD', 0;
7
8 unless ($ok) {
9 print <<EOF;
101..0 # Your perl interpreter is badly BROKEN. Child watchers will not work, ever. Try upgrading to a newer perl or a working perl (cygwin's perl is known to work). If that is not an option, you should be able to use the remaining functionality of AnyEvent, but child watchers WILL NOT WORK.
11EOF
12 exit 0;
13 }
14 }
15}
16
17BEGIN {
1$|=1; 18 $|=1;
2BEGIN { print "1..7\n" } 19 print "1..7\n"
20}
21
22use POSIX ();
3 23
4use AnyEvent; 24use AnyEvent;
5use AnyEvent::Impl::Perl; 25use AnyEvent::Impl::Perl;
6 26
27$AnyEvent::MAX_SIGNAL_LATENCY = 1;
28
7print "ok 1\n"; 29print "ok 1\n";
30
31AnyEvent::detect; # force-load event model
8 32
9my $pid = fork; 33my $pid = fork;
10 34
11defined $pid or die "unable to fork"; 35defined $pid or die "unable to fork";
12 36
13# work around Tk bug until it has been fixed. 37# work around Tk bug until it has been fixed.
14my $timer = AnyEvent->timer (after => 2, cb => sub { }); 38#my $timer = AnyEvent->timer (after => 2, cb => sub { });
15 39
16my $cv = AnyEvent->condvar; 40my $cv = AnyEvent->condvar;
17 41
18unless ($pid) { 42unless ($pid) {
19 print "ok 2\n"; 43 print "ok 2\n";
20 exit 3; 44 POSIX::_exit 3;
21} 45}
22 46
23my $w = AnyEvent->child (pid => $pid, cb => sub { 47my $w = AnyEvent->child (pid => $pid, cb => sub {
24 print $pid == $_[0] ? "" : "not ", "ok 3\n"; 48 print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n";
25 print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4\n"; 49 print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4 # 3 == $_[1] >> 8 ($_[1])\n";
26 $cv->broadcast; 50 $cv->broadcast;
27}); 51});
28 52
29$cv->wait; 53$cv->wait;
30 54
31my $pid2 = fork || exit 7; 55my $pid2 = fork || POSIX::_exit 7;
32 56
33my $cv2 = AnyEvent->condvar; 57my $cv2 = AnyEvent->condvar;
34 58
35my $w2 = AnyEvent->child (pid => 0, cb => sub { 59my $w2 = AnyEvent->child (pid => 0, cb => sub {
36 print $pid2 == $_[0] ? "" : "not ", "ok 5\n"; 60 print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n";
37 print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6\n"; 61 print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n";
38 $cv2->broadcast; 62 $cv2->broadcast;
63});
64
65my $error = AnyEvent->timer (after => 5, cb => sub {
66 print <<EOF;
67Bail out! No child exit detected. This is either a bug in AnyEvent or a bug in your Perl (mostly some windows distributions suffer from that): child watchers might not work properly on this platform. You can force installation of this module if you do not rely on child watchers, or you could upgrade to a working version of Perl for your platform.\n";
68EOF
69 exit 0;
39}); 70});
40 71
41$cv2->wait; 72$cv2->wait;
42 73
43print "ok 7\n"; 74print "ok 7\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines