1 |
use AnyEvent; |
2 |
|
3 |
BEGIN { $ENV{PERL_ANYEVENT_LOOP_TESTS} or ((print qq{1..0 # SKIP PERL_ANYEVENT_LOOP_TESTS not true\n}), exit 0) } |
4 |
BEGIN { eval q{use AnyEvent::Impl::FLTK2;1} or ((print qq{1..0 # SKIP AnyEvent::Impl::FLTK2 not loadable\n}), exit 0) } |
5 |
|
6 |
|
7 |
|
8 |
$| = 1; print "1..28\n"; |
9 |
|
10 |
print "ok 1\n"; |
11 |
|
12 |
{ |
13 |
my $cv = AnyEvent->condvar; |
14 |
|
15 |
$cv->cb (sub { |
16 |
print $_[0]->ready ? "" : "not ", "ok 4\n"; |
17 |
|
18 |
my $x = $_[0]->recv; |
19 |
print $x == 7 ? "" : "not ", "ok 5 # $x == 7\n"; |
20 |
|
21 |
my @x = $_[0]->recv; |
22 |
print $x[1] == 5 ? "" : "not ", "ok 6 # $x[1] == 5\n"; |
23 |
|
24 |
my $y = $cv->recv; |
25 |
print $y == 7 ? "" : "not ", "ok 7 # $x == 7\n"; |
26 |
}); |
27 |
|
28 |
my $t = AnyEvent->timer (after => 0, cb => sub { |
29 |
print "ok 3\n"; |
30 |
$cv->send (7, 5); |
31 |
}); |
32 |
|
33 |
print "ok 2\n"; |
34 |
$cv->recv; |
35 |
print "ok 8\n"; |
36 |
|
37 |
my @x = $cv->recv; |
38 |
print $x[1] == 5 ? "" : "not ", "ok 9 # $x[1] == 5\n"; |
39 |
} |
40 |
|
41 |
{ |
42 |
my $cv = AnyEvent->condvar; |
43 |
|
44 |
$cv->cb (sub { |
45 |
print $_[0]->ready ? "" : "not ", "ok 12\n"; |
46 |
|
47 |
my $x = eval { $_[0]->recv }; |
48 |
print !defined $x ? "" : "not ", "ok 13\n"; |
49 |
print $@ =~ /^kill/ ? "" : "not ", "ok 14 # $@\n"; |
50 |
}); |
51 |
|
52 |
my $t = AnyEvent->timer (after => 0, cb => sub { |
53 |
print "ok 11\n"; |
54 |
$cv->croak ("kill"); |
55 |
print "ok 15\n"; |
56 |
$cv->send (8, 6, 4); |
57 |
print "ok 16\n"; |
58 |
}); |
59 |
|
60 |
print "ok 10\n"; |
61 |
my @x = eval { $cv->recv }; |
62 |
print !@x ? "" : "not ", "ok 17 # @x\n"; |
63 |
print $@ =~ /^kill / ? "" : "not ", "ok 18 # $@\n"; |
64 |
} |
65 |
|
66 |
{ |
67 |
my $cv = AnyEvent->condvar; |
68 |
|
69 |
print "ok 19\n"; |
70 |
my $t = AnyEvent->timer (after => 0, cb => $cv); |
71 |
|
72 |
print "ok 20\n"; |
73 |
$cv->recv; |
74 |
print "ok 21\n"; |
75 |
} |
76 |
|
77 |
{ |
78 |
my $cv = AE::cv { |
79 |
print +($_[0]->recv)[0] == 6 ? "" : "not ", "ok 27\n"; |
80 |
}; |
81 |
|
82 |
print "ok 22\n"; |
83 |
|
84 |
$cv->begin (sub { |
85 |
print "ok 26\n"; |
86 |
$_[0](6); |
87 |
}); |
88 |
|
89 |
print "ok 23\n"; |
90 |
$cv->begin; |
91 |
print "ok 24\n"; |
92 |
$cv->end; |
93 |
print "ok 25\n"; |
94 |
$cv->end; |
95 |
|
96 |
print "ok 28\n"; |
97 |
} |
98 |
|