1#!perl
2
3use Test::More;
4
5eval "use AnyEvent; 1" or
6    plan skip_all => "AnyEvent is not installed.";
7
8# seeing as the entire point of this test is to test the event handler,
9# we need to mock as little as possible.  To keep things tightly controlled,
10# we'll use the Stub directly.
11BEGIN {
12    $ENV{PERL_RL} = 'Stub o=0';
13}
14plan tests => 3;
15
16# need to delay this so that AE is loaded first.
17require Term::ReadLine;
18use File::Spec;
19
20my $t = Term::ReadLine->new('AE');
21ok($t, "Created object");
22is($t->ReadLine, 'Term::ReadLine::Stub', 'Correct type');
23
24my ($cv, $fe);
25$t->event_loop(
26               sub {
27                   $cv = AE::cv();
28                   $cv->recv();
29               }, sub {
30                   my $fh = shift;
31                   $fe ||= AE::io($fh, 0, sub { $cv->send() });
32               }
33              );
34
35my $text = 'some text';
36my $T = $text . "\n";
37my $w = AE::timer(0,1,sub { 
38pass("Event loop called");
39exit 0;
40});
41
42my $result = $t->readline('Do not press enter>');
43fail("Should not get here.");
44