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.1 by root, Mon Dec 11 01:16:09 2006 UTC vs.
Revision 1.12 by root, Thu Jul 9 01:08:22 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..4\n" } 19 print "1..7\n"
20}
21
22use POSIX ();
3 23
4use AnyEvent; 24use AnyEvent;
25use AnyEvent::Impl::Perl;
5 26
6print "ok 1\n"; 27print "ok 1\n";
28
29AnyEvent::detect; # force-load event model
7 30
8my $pid = fork; 31my $pid = fork;
9 32
10defined $pid or die "unable to fork"; 33defined $pid or die "unable to fork";
11 34
12# work around Tk bug until it has been fixed. 35# work around Tk bug until it has been fixed.
13my $timer = AnyEvent->timer (after => 2, cb => sub { }); 36#my $timer = AnyEvent->timer (after => 2, cb => sub { });
14 37
15my $cv = AnyEvent->condvar; 38my $cv = AnyEvent->condvar;
16 39
17unless ($pid) { 40unless ($pid) {
18 print "ok 2\n"; 41 print "ok 2\n";
19 exit 3; 42 POSIX::_exit 3;
20} 43}
21 44
22my $w = AnyEvent->child (pid => $pid, cb => sub { 45my $w = AnyEvent->child (pid => $pid, cb => sub {
46 print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n";
23 print 3 == ($? >> 8) ? "" : "not ", "ok 3\n"; 47 print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4 # 3 == $_[1] >> 8 ($_[1])\n";
24 $cv->broadcast; 48 $cv->broadcast;
25}); 49});
26 50
27$cv->wait; 51$cv->wait;
28 52
53my $pid2 = fork || POSIX::_exit 7;
54
55my $cv2 = AnyEvent->condvar;
56
57my $w2 = AnyEvent->child (pid => 0, cb => sub {
58 print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n";
59 print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n";
60 $cv2->broadcast;
61});
62
63my $error = AnyEvent->timer (after => 5, cb => sub {
64 print <<EOF;
65Bail 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";
66EOF
67 exit 0;
68});
69
70my $inter = AnyEvent->timer (after => 4, cb => sub {
71 print "not ok 5 # inter\n";#d# temporary
72 print "not ok 6 # inter\n";#d# temporary
73 $cv2->send;
74});
75
76$cv2->wait;
77
29print "ok 4\n"; 78print "ok 7\n";
30 79
31 80
32 81
33 82

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines