Your thoughts seem to focus on setting up data structures. That is IMHO wrong. You should focus on setting up a simple harness structure. You don't need (or probably want) a data structure for your tests. You want simple. You want easy. You want quick. You want understandable. You don't need easily modifiable as if the tests were valid in the first place they should always pass, thus you almost never delete from a test suite, you only add. It is also a hell of a lot easier to find a test if each test has its own chunk of code.... I would have one test script per script. Typically you call these test files 'prog_or_module_name.t' and put them in a t/ directory. Here is a suggested simple framework:

#!/usr/bin/perl -s use Test; BEGIN{ plan tests => 3 }; my $prog = 'script.pl'; our $TMPFILE = '/tmp/tmpfile' . time(); my ( $input, $output, $opt ); # make sure program exists or we are bound to fail ok( -e $prog ); #1 # make sure we can write to our tmpfile ok( write_tmpfile('') ); #2 END{ unlink $TMPFILE }; # clean up at end # tests go here $input = ''; $output = ''; $opts = ''; ok( test_prog( $prog, $input, $opts ), $output ); #3 # ..... # we could use open2 or open3 but why complicate it.... sub test_prog { my ( $prog, $input, $opts ) = @_; write_tmpfile( $input ); my $actual_output = `cat $tmpfile | $prog $opts`; return $actual_output; } sub write_tmpfile { open F, '>$TMPFILE' or return 0; print F $_[0]; close F; return 1; }

All you need to do to add a test is copy the input/output/opts/ok stub and fill in the blanks. As you find bugs you just add yet another test case. Assuming you go for the t/*.t format you can make a little shell or perl script like this:

[root@devel3 t]# cat run #!/bin/sh /usr/bin/perl -e 'use Test::Harness qw(&runtests); runtests @ARGV;' /s +ome/path/t/*.t

And then just call run to run all your tests. UpdateFixed typo, thanks blyman

cheers

tachyon


In reply to Re: Setting up tests for cat-type filter programs by tachyon
in thread Setting up tests for cat-type filter programs by dmorgo

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.