[Melbourne-pm] n00b question: how to exclude test code from production

Toby Corkindale toby.corkindale at strategicdata.com.au
Tue May 18 17:40:29 PDT 2010

On 19/05/10 10:23, Alec Clews wrote:
> Hash: SHA1
> I have a Perl script that I want to embed some tests in (Using
> Test::More). What is the best practice way to ignore the test code in
> production?

Put your production code in lib/MyModule.pm and script/myscript.pl
(Where myscript.pl parses the command-line flags and then call MyModule)
Then put your tests into t/*.t
One test can "use MyModule" and run a variety of tests upon it.
Another test can create a fake MyModule for myscript.pl to hit, and then 
call myscript.pl with a variety of parameters to check how they are handled.

More information about the Melbourne-pm mailing list