Subject: | please add space to PERL_RL environment variable |
Expect.pm lacks a simple space when setting Term::Readline's environment
variable PERL_RL, which, unusually, expects a space-separated tail (see
http://perldoc.perl.org/Term/ReadLine.html#ENVIRONMENT).
The bug makes it impossible to test interactive programs relying on
Term::Readline. The patch is quite simple:
--- Expect.pm.orig 2008-09-02 17:22:02.080045310 +0200
+++ Expect.pm 2008-09-02 17:22:12.541665779 +0200
@@ -39,7 +39,7 @@
sub expect_run {
my (%conf) = @_;
$expect = Expect::Simple->new(
- { Cmd => "PERL_RL=\"o=0\" " . $conf{command},
+ { Cmd => "PERL_RL=\" o=0\" " . $conf{command},
Prompt => $conf{prompt},
DisconnectCmd => $conf{quit},
Verbose => 0,
To reproduce, please consider the attached files: For simplicity,
myprogram.pl just outputs what comes in via Term::Readline.
test1.pl should test that, but fails with the error "Expect::Simple:
Expect::Simple: couldn't find prompt at /usr/share/perl5/Test/Expect.pm
line 41" with unpatched Test::Expect.
test2.pl also fails, but prints some debug info: calling myprogram.pl
failed with "Can't locate object method "new" via package
"Term::ReadLine::Gnu" at myprogram.pl line 10."
test3.pl is just like test1.pl, only that it sets PERL_RL to a correctly
space-separated value, and succeeds, proving that the lacking space is
indeed the problem.
With the above patch applied, test1.pl succeeds just as it should.
Subject: | myprogram.pl |
#!/usr/bin/perl -w
use strict;
use warnings;
use Term::ReadLine;
my ($readlineterm, $input);
$readlineterm = new Term::ReadLine::Gnu 'myterm'; #init readline
while (1) {
$input = $readlineterm->readline('Input: ');
last unless $input;
print "$input\n";
}
Subject: | test2.pl |
#!/usr/bin/perl -w
use strict;
use Test::More tests => 3;
use Test::Expect;
expect_run(
command => "perl myprogram.pl",
prompt => ' ',
quit => "\n",
);
print "\nDEBUG: " . expect_handle->before . " | " . expect_handle->after . " | " . expect_handle->error . "\n";
expect_send('something');
expect_is('something', '...ok');
Subject: | test3.pl |
#!/usr/bin/perl -w
use strict;
use Test::More tests => 3;
use Test::Expect;
expect_run(
command => 'PERL_RL=" o=0" perl myprogram.pl',
prompt => 'Input: ',
quit => "\n",
);
expect_send('something', 'sending...');
expect_is('something', '...ok');
Subject: | test1.pl |
#!/usr/bin/perl -w
use strict;
use Test::More tests => 3;
use Test::Expect;
expect_run(
command => "perl myprogram.pl",
prompt => 'Input: ',
quit => "\n",
);
expect_send('something');
expect_is('something', '...ok');