Take a look at the Perl Testing, A Developer's Notebook, Langworth and chromatic, page 169 - "Testing Interactive Programs"; this is a quick write-up on Test::Expect. The example shown is a test harness for an iterative routine; it keeps prompting the User until it receives a 'quit-it' string ("\n" in this case).

Last Monday, I was also confronted with the need to automate 'Password, Please!' routine in a test-harness. I did a bit of research, read the PT section, and said "Eureka". I then ran into a spot of difficulty dealing with password prompting - I was only prompting one time and then moving on, rather than re-issuing a prompt in a loop and waiting for the User to say 'done, enough'. After a bit of playing around, I sorted a way to allow me to get this behavior to work in the context of Expect::Simple. Last Thursday I sent a patch off to the maintainer (Leon Brocard).

Basically, the patch adds the prompt-string and the quit-string to the results obtained from the test-code, before the results are passed on to Expect::Simple. This results in Expect::Simple returning the right stuff to the test-harness, and then, since the quit-string appeared following the 'next prompt', Expect::Simple cleans up and exits normally. I set things up so that you can call-out this behavior at will via a parameter passed into the Test::Expect::expect_run() routine.

/msg me if you need the work-around immediately, or wait until it gets incorporated formally into Test::Expect.

----
I Go Back to Sleep, Now.

OGB


In reply to Re: Interactive prompts inside a test harness by Old_Gray_Bear
in thread Interactive prompts inside a test harness by jkeenan1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.