On Thu, 2005-03-31 at 16:46 +0000, Mark Stosberg wrote:
> Hello,

Hello,

> 
> I've been working on a Perl test suite for darcs, with notable recent
> help from Schwern. 
> 
> We used to have tests that looked like this:
> 
>    like(`echo y | darcs command`,qr/$re/); 
> 
> That would run the command and answer "y" to the first and only question
> it asked. It worked well enough, but I looked for for a pure Perl
> solution in the spirit of "being more portable".
> 
> I came up with this:
> 
>  {
>      open2(*READ, *WRITE, "$DARCS unpull -p add");
>      print WRITE "a\n";
>      like( (<READ>)[4], qr/really unpull/i, "additional confirmation is given 
> when 'all' option is selected");
>      close(WRITE);
>      close(READ);
>      # (We never confirmed, so those patches are still there )
>  }
> 
> This is more time consuming to write, because not only is more verbose, but I
> know exactly how many lines to read on STDERR. Already for two people 
> something
> got slightly off, causing the test to hang indefinitely.
> 
> Windows users weren't having problems with the first method, so maybe I
> should just go back to that. 
> 
> I'm I missing an easier and less fragile way to test interactive
> commands with Perl?
> 
> Thanks!
> 
>     Mark

For commands that need more than one input (i.e. shell installers) you
can use the Expect module, which you can use to test such programs, that
wait your input for more than one time.

> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 

Reply via email to