I am having trouble figuring out how to test a Perl script which
functions as a command-line utility and which is included with a
CPAN-style distribution.
For purpose of discussion, let's call the distribution XYZ and the
script xyz.pl. My distribution has the following standard structure:
README
Makefile.PL
MANIFEST
lib/
XYZ.pm
scripts/
xyz.pl
t/
01_module.t
02_script.t
xyz.pl is a Perl script, intended for use at the command-line, which
parses some options and then calls XYZ->new() with those options:
eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
use strict;
use warnings;
use Getopt::Std;
use XYZ;
getopts( "Vh", \%opts );
die Usage() if ( $opts{h} );
my $mod = XYZ->new(
VERBOSE => ( ( $opts{V} ) ? 1 : 0 ),
...
);
I would like to be able to write tests which call xyz.pl with different
combinations of options and examine the results. I assume that I would
have to call the utility with something like this:
system(xyz.pl -V);
The problem I'm facing is that the version of XYZ that I want xyz.pl to
'use' is the version I am currently developing, namely, the one that
will be placed in 'blib/lib' by 'make'. I *don't* want xyz.pl to 'use'
the *older* version of XYZ which I have installed on disk (presumably at
/usr/local/lib/perl5/5.8.4/XYZ.pm).
However, it seems that when I call 'system(xyz.pl -V)' from inside file
t/02_script.t, it goes for the *installed* (and now incorrect) version
of XYZ.pm rather than the one in the development tree. (I have tried
adding 'use blib;' to xyz.pl, but (a) it doesn't locate blib properly
and (b) I don't want that in the version of xyz.pl to be distributed to
customers or on CPAN.
So, how do I structure the distribution and write the test so that I can
test the command-line utility, not just the Perl module?
TIA
Jim Keenan