in reply to Pre-empting STDIN during Testing

Jim,

This looks like what `expect` / Expect.pm is made for. It talks to the unit under test, waiting for a string and answering with another one.

Refactoring the verification into subroutines might be the best long term solution. Do you know that your program never ever will use a different form of input? What if you need to verify e. g. XML file input?

Replies are listed 'Best First'.
Re^2: Pre-empting STDIN during Testing
by jkeenan1 (Deacon) on Feb 15, 2005 at 20:07 UTC
    I did look at Expect.pm. I suppose my immediate reaction was: "This is immense. Which one of these dozens of functions could be the one I need?" In other words, the learning curve I would face for Expect seemed much greater than what I thought was needed for the task at hand. So I passed on it, but will definitely keep it in mind for similar projects in the future.

    Thanks for responding.

    jimk

      You'll want to start with Expect::Simple. And, frankly, you can start with the following methods and probably never need more:
      • send() - this is what you use to interact with STDIN
      • before() - this is what the prompt was that you just sent stuff to with send()
      • after() - this is what the program blabs to you after you send the stuff with send()

      If you need more, then more reading is the thing to do. Note: As you've found out, interacting with STDIN is hard. Don't complain if you have to read for a few hours to have someone else take all the craziness out of it for you.

      Being right, does not endow the right to be rude; politeness costs nothing.
      Being unknowing, is not the same as being stupid.
      Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
      Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.