[Israel.pm] Testing scripts

Shlomi Fish shlomif at iglu.org.il
Thu Dec 23 11:29:03 PST 2004


On Thursday 23 December 2004 18:05, Offer Kaye wrote:
> Hi,
> I have a Perl script I would like to test.
> So I started using Test::Simple and later moved to Test::More.
> My problem is, all the documentation talks about testing modules and
> it isn't clear to me how to test stuff like the output files and error
> messages my script outputs.
>

First of all, it is generally a good idea that if you wish to test your 
script, then make sure most of the functionality is implemented in a 
dedicated module and the script would be just a simple instantiation and a 
method call.

> Is there a standard framework for testing scripts?

Not that I'm aware of.

> Is there a standard way to compare an output file to an expected output
> file? 

You can use the UNIX diff command (preferably with the -u flag). Or cmp if you 
just want a yes/no answer. If that's not enough, there are many modules 
implementing the diff algorithm in CPAN.

> How do I easily catch the STDERR of an external call? 

You can point to a file using the shell's "2>" notation. You can also try 
IPC::Open3:

http://search.cpan.org/~nwclark/perl-5.8.6/lib/IPC/Open3.pm


> Anything else I'm missing?
>

Well, I don't know if it helps, but Devel::LineTrace (my own module, albeit it 
was inspired by a discussion in a Perl Mongers meeting and here) can aid with 
the testing of Perl scripts:

http://search.cpan.org/dist/Devel-LineTrace/

Regards,

	Shlomi Fish

---------------------------------------------------------------------
Shlomi Fish      shlomif at iglu.org.il
Homepage:        http://www.shlomifish.org/

Knuth is not God! It took him two days to build the Roman Empire.



More information about the Perl mailing list