I've got a Web site heavily spiked with tutorials and sample code. The tutorial programs are very simple, and the user interaction is not what you'd consider demanding.

Given a simple Parrot PIR program like this:

.sub 'main' :main .local string name .local string greeting .local pmc stdin stdin = getstdin name = stdin.'readline_interactive'("Please enter your name: ") greeting = "Hello, " . name greeting .= "!" say greeting .end

The sample usage is straightforward, but bothersome to double-check every time I update my Parrot install.

$ parrot code/example-01-06.pir
Please enter your name: Brian
Hello, Brian!

Manually verifying behavior after a language update has become tiresome. So I wrote some tests. They use IO::Pty::Easy to handle input and output.

use Modern::Perl; use IO::Pty::Easy; use Test::More tests => 3; my $pty = IO::Pty::Easy->new; ok $pty->spawn("parrot", "code/example-01-06.pir"); my $output = $pty->read(); is $output, "Please enter your name: "; $pty->write("Brian\n"); $output = $pty->read(); is $output, "Hello, Brian!\n"; $pty->close;

There's nothing wrong with this code - at least nothing that is obvious to me. I'm just wondering if there is a test approach or IO library preferred by the monks for testing lots of simple scripts of this nature.

Edit: Added the Parrot script being tested to hopefully improve the coherence of my late night post.


In reply to Suggestions for testing interactive CLI apps? by webfiend

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.