chexmix has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to put together my first-ever test of a standalone script. I've been looking at the last chapter of the O'Reilly Perl Testing: A Developer's Notebook as well as some of the standard testing documentation (Test::Tutorial, etc). However, though I've gotten a start, I'm not sure where to go from here.
The script to be tested expects two parameters, the name of an input file and the name of an output file (so it is a filter, in a way).
As Perl Testing suggests I have added the following line to the script:
main( @ARGV ) unless caller( );
... and recast the first part of the program as a sub called main. I then created a test script that looks like this:
#!/usr/bin/perl use warnings; use strict; use Test::More tests => 5; ok( require( 'myScript' ), 'loaded file okay' ) or exit; throws_ok { main( ) } qr/Usage:/, 'main( ) should give a usage error without any arguments'; throws_ok { main( 'bad command' ) } qr/Unknown command 'bad command'/, '... or with a bad command given';
When I run this against the script 'myScript', I get the following output:
./test_myScript.t 1..5 ok 1 - loaded file okay parameter `files' not set parameter `output' not set # Looks like you planned 5 tests but only ran 1.
... which is fine, but what I'd like to do is set up some tests which confirm that the script is doing its thing correctly, e.g. tests that a dummy file (provided as part of the testing suite or created by an intermediate script) passed to the script correctly creates a dummy output file, or what have you.
So really the question is how, in that testing script, do I go about passing in those parameters to the main() routine in myScript?
In the main() routine, input and output params are coded as $param{files} and $param{output}, respectively, e.g. with Getopt::Long.
Thanks in advance for any pointers, or pointers to tutorials that have more info on testing standalone scripts.
GB
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: testing a standalone script with parameters
by GrandFather (Saint) on Mar 04, 2009 at 00:47 UTC | |
|
Re: testing a standalone script with parameters
by zwon (Abbot) on Mar 03, 2009 at 20:13 UTC | |
by chexmix (Hermit) on Mar 03, 2009 at 20:18 UTC | |
by chexmix (Hermit) on Mar 03, 2009 at 21:36 UTC | |
by chexmix (Hermit) on Mar 04, 2009 at 20:44 UTC | |
|
Re: testing a standalone script with parameters
by andreas1234567 (Vicar) on Mar 04, 2009 at 06:15 UTC |