#!/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; } #### [root@devel3 t]# cat run #!/bin/sh /usr/bin/perl -e 'use Test::Harness qw(&runtests); runtests @ARGV;' /some/path/t/*.t