1#!perl
2
3use Test::More;
4
5eval "use Tk; use AnyEvent; 1" or
6    plan skip_all => "AnyEvent and/or Tk 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    # ensure AE uses Tk.
14    $ENV{PERL_ANYEVENT_MODEL} = 'Tk';
15}
16
17eval {
18    use File::Spec;
19    my $mw = MainWindow->new(); $mw->withdraw();
20    1;
21} or plan skip_all => "Tk can't start. DISPLAY not set?";
22
23plan tests => 3;
24
25# need to delay this so that AE is loaded first.
26require Term::ReadLine;
27use File::Spec;
28
29my $t = Term::ReadLine->new('AE/Tk');
30ok($t, "Created object");
31is($t->ReadLine, 'Term::ReadLine::Stub', 'Correct type');
32my ($cv, $fe);
33$t->event_loop(
34               sub {
35                   $cv = AE::cv();
36                   $cv->recv();
37               }, sub {
38                   my $fh = shift;
39                   $fe ||= AE::io($fh, 0, sub { $cv->send() });
40               }
41              );
42
43
44my $text = 'some text';
45my $T = $text . "\n";
46my $w = AE::timer(0,1,sub {
47pass("Event loop called");
48exit 0;
49});
50
51my $result = $t->readline('Do not press enter>');
52fail("Should not get here.");
53