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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |