1 | $|=1; |
1 | $|=1; |
2 | BEGIN { print "1..5\n" } |
2 | BEGIN { |
|
|
3 | print "1..7\n" |
|
|
4 | } |
3 | |
5 | |
4 | use AnyEvent; |
6 | use AnyEvent; |
|
|
7 | use AnyEvent::Impl::Perl; |
|
|
8 | |
|
|
9 | print STDERR <<EOF; |
|
|
10 | |
|
|
11 | If the following test hangs for a long time you either found a bug in |
|
|
12 | AnyEvent or, more likely, you have a defective perl (most windows perl |
|
|
13 | distros are broken, cygwin perl works). If you do not rely on child |
|
|
14 | handlers you can force the installation of this module and the rest will |
|
|
15 | likely work. Otherwise upgrading to a working perl is recommended. |
|
|
16 | EOF |
5 | |
17 | |
6 | print "ok 1\n"; |
18 | print "ok 1\n"; |
|
|
19 | |
|
|
20 | AnyEvent::detect; # force-load event model |
7 | |
21 | |
8 | my $pid = fork; |
22 | my $pid = fork; |
9 | |
23 | |
10 | defined $pid or die "unable to fork"; |
24 | defined $pid or die "unable to fork"; |
11 | |
25 | |
12 | # work around Tk bug until it has been fixed. |
26 | # work around Tk bug until it has been fixed. |
13 | my $timer = AnyEvent->timer (after => 2, cb => sub { }); |
27 | #my $timer = AnyEvent->timer (after => 2, cb => sub { }); |
14 | |
28 | |
15 | my $cv = AnyEvent->condvar; |
29 | my $cv = AnyEvent->condvar; |
16 | |
30 | |
17 | unless ($pid) { |
31 | unless ($pid) { |
18 | print "ok 2\n"; |
32 | print "ok 2\n"; |
19 | exit 3; |
33 | exit 3; |
20 | } |
34 | } |
21 | |
35 | |
22 | my $w = AnyEvent->child (pid => $pid, cb => sub { |
36 | my $w = AnyEvent->child (pid => $pid, cb => sub { |
23 | print $pid == $_[0] ? "" : "not ", "ok 3\n"; |
37 | print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n"; |
24 | print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4\n"; |
38 | print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4 # 3 == $_[1] >> 8 ($_[1])\n"; |
25 | $cv->broadcast; |
39 | $cv->broadcast; |
26 | }); |
40 | }); |
27 | |
41 | |
28 | $cv->wait; |
42 | $cv->wait; |
29 | |
43 | |
30 | my $pid2 = fork || exit 7; |
44 | my $pid2 = fork || exit 7; |
31 | |
45 | |
32 | my $cv2 = AnyEvent->condvar; |
46 | my $cv2 = AnyEvent->condvar; |
33 | |
47 | |
34 | my $w2 = AnyEvent->child (pid => 0, cb => sub { |
48 | my $w2 = AnyEvent->child (pid => 0, cb => sub { |
35 | print $pid2 == $_[0] ? "" : "not ", "ok 5\n"; |
49 | print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n"; |
36 | print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6\n"; |
50 | print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n"; |
37 | $cv2->broadcast; |
51 | $cv2->broadcast; |
|
|
52 | }); |
|
|
53 | |
|
|
54 | my $error = AnyEvent->timer (after => 5, cb => sub { |
|
|
55 | print <<EOF; |
|
|
56 | 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"; |
|
|
57 | EOF |
|
|
58 | exit 0; |
38 | }); |
59 | }); |
39 | |
60 | |
40 | $cv2->wait; |
61 | $cv2->wait; |
41 | |
62 | |
42 | print "ok 7\n"; |
63 | print "ok 7\n"; |