ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/67_tk_03_child.t
Revision: 1.4
Committed: Sat Jul 18 00:05:29 2009 UTC (14 years, 10 months ago) by root
Content type: application/x-troff
Branch: MAIN
Changes since 1.3: +7 -16 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.4 use POSIX ();
2    
3     use AnyEvent;
4     BEGIN { eval q{use AnyEvent::Impl::Tk;1} or ((print qq{1..0 # SKIP AnyEvent::Impl::Tk not found}), exit 0) }
5    
6 root 1.1 BEGIN {
7     # check for broken perls
8     if ($^O =~ /mswin32/i) {
9     my $ok;
10     local $SIG{CHLD} = sub { $ok = 1 };
11     kill 'CHLD', 0;
12    
13     unless ($ok) {
14     print <<EOF;
15     1..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.
16     EOF
17     exit 0;
18     }
19     }
20     }
21    
22 root 1.4 $| = 1; print "1..7\n";
23 root 1.1
24 root 1.3 $AnyEvent::MAX_SIGNAL_LATENCY = 1;
25    
26 root 1.1 print "ok 1\n";
27    
28     AnyEvent::detect; # force-load event model
29    
30     my $pid = fork;
31    
32     defined $pid or die "unable to fork";
33    
34     # work around Tk bug until it has been fixed.
35     #my $timer = AnyEvent->timer (after => 2, cb => sub { });
36    
37     my $cv = AnyEvent->condvar;
38    
39     unless ($pid) {
40     print "ok 2\n";
41 root 1.2 POSIX::_exit 3;
42 root 1.1 }
43    
44     my $w = AnyEvent->child (pid => $pid, cb => sub {
45     print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n";
46     print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4 # 3 == $_[1] >> 8 ($_[1])\n";
47     $cv->broadcast;
48     });
49    
50     $cv->wait;
51    
52 root 1.2 my $pid2 = fork || POSIX::_exit 7;
53 root 1.1
54     my $cv2 = AnyEvent->condvar;
55    
56     my $w2 = AnyEvent->child (pid => 0, cb => sub {
57     print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n";
58     print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n";
59     $cv2->broadcast;
60     });
61    
62 root 1.4 my $error = AnyEvent->timer (after => 5, cb => sub {
63 root 1.1 print <<EOF;
64     Bail 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";
65     EOF
66     exit 0;
67     });
68    
69     $cv2->wait;
70    
71     print "ok 7\n";
72    
73    
74    
75