I am writing a test suite which a user will run either with prove or with make test as part of module installation. The module distro includes an executable script located in the scripts/ directory.

In the executable script -- which we'll call login.pl -- I have the following code:

my $config = {}; print "Type your username: "; chomp ($config->{username} = <>); system "stty -echo" and croak "Unable to turn off echoing to STDOUT"; print "Type your password: "; chomp ($config->{password} = <>); print "\n"; system "stty echo" and croak "Unable to turn echoing to STDOUT back on";

It DWIMs. But now suppose that in one of my test files I want to call login.pl, have the user enter her username and password and then use that data to log in to a server. If the login is successful, a string will be returned whose content I would like to validate with Test::More::like. How can I do that?

I have found that if I enter this code directly in a file where Test::More has been used, the prompt is never printed but the program hangs. I've explored both Test::Expect and IPC::Run, but I haven't been able to match anything in the documentation of either module to my needs.

Suggestions? Thanks in advance.

Jim Keenan

In reply to 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.