I often use a data-driven approach in such situations:

You have three parameters for each program:

  1. The program and its path and command line
  2. The output of the command
  3. A regular expression that should match the output

One of 2. and 3. seems superfluous - either you have a literal match or a regex, but it's unlikely you need both. But that's a different problem.

My approach is to store all three items in a simple ASCII table and let the test driver run over that table:

use strict; use Test::More; use Test::Cmd; my @tests = map { split /\|/, $_, 3 } <DATA>; close DATA; plan tests => @tests * 3; for (@tests) { my ($prog,$stdout,$stdout_re) = @$_; my $cmd = Test::Cmd->new( prog => $prog ); is $cmd->run, 0, ">>$prog<< ran okay"; is $cmd->stdout, $stdout, 'Output is OK'; like $cmd->stdout, qr/$stdout_re/, 'Found expected output'; }; __DATA__ /bin/uname|Linux|Linux /bin/uname -n|Desktop1|Desktop

Update: andreas1234567 spotted a bug in the argument order to split, fixed


In reply to Re: Better arranging Test Suite by Corion
in thread Better arranging Test Suite by piew

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.