Testing Entire Distributions

     

A proper Perl distribution contains a handful of files and lists any prerequisite modules that it needs to function properly. Each package should have a version number and have valid POD syntax. If you've signed your distribution cryptographically , the signature should validate. These are all important features, so why not test them?

The Test::Distribution module can do just that with one simple test script.

How do I do that?

Given a module distribution Text::Hogwash , create a test file t/distribution.t containing:

 use Test::More;     eval 'require Test::Distribution';     plan( skip_all => 'Test::Distribution not installed' ) if $@;     Test::Distribution->import(  ); 

The -l option tells prove that modules for the distribution are in the lib/ directory. Run t/distribution.t using prove :

 $  prove -v -l t/distribution.t  t/distribution....1..14     ok 1 - Checking MANIFEST integrity     ok 2 - use Text::Hogwash::Tomfoolery;     ok 3 - use Text::Hogwash::Silliness;     ok 4 - Text::Hogwash::Tomfoolery defines a version     ok 5 - Text::Hogwash::Silliness defines a version     ok 6 - All non-core use(  )d modules listed in PREREQ_PM     ok 7 - POD test for lib/Text/Hogwash/Tomfoolery.pm     ok 8 - POD test for lib/Text/Hogwash/Silliness.pm     ok 9 - MANIFEST exists     ok 10 - README exists     ok 11 - Changes or ChangeLog exists     ok 12 - Build.PL or Makefile.PL exists     ok 13 - Pod Coverage ok     ok 14 - Pod Coverage ok     ok     All tests successful.     Files=1, Tests=14,  0 wallclock secs ( 0.19 cusr +  0.01 csys =  0.20 CPU) 

What just happened ?

Test::Distribution calculates how many tests it will run and declares the plan during its import( ) call. Some of these tests use modules covered earlier, such as Test::Pod (Testing POD Files"), Test::Pod::Coverage (Testing Documentation Coverage"), and Module::Signature (Distribution Signatures"). Others are simple checks that would be tedious to perform manually, such as ensuring that the MANIFEST and README files exist.

What about...

Q:

Is it possible to test a subset of distribution properties, such as the module prerequisites or package versions?

A:

The Test::Distribution documentation includes a list of the types of tests it performs , such as prereq and versions . Specify the types of tests you want to run by using only or not after the import statement:

 Test::Distribution->import(  only =  >  [ qw( prereq versions ) ]  ); 

The previous listing passes two additional arguments to import( ) : the string only and a reference to an array of the strings that represent the only types of tests that Test::Distribution should perform. When running the modified test file, the test output is much shorter because Test::Distribution runs only the named tests:

 $  prove -v t/distribution.t  t/distribution....1..5     ok 1 - use Text::Hogwash::Tomfoolery;     ok 2 - use Text::Hogwash::Silliness;     ok 3 - Text::Hogwash::Tomfoolery defines a version     ok 4 - Text::Hogwash::Silliness defines a version     ok 5 - All non-core use(  )d modules listed in PREREQ_PM     ok     All tests successful.     Files=1, Tests=5,  1 wallclock secs ( 0.62 cusr +  0.04 csys =  0.66 CPU) 

You can also use the not argument instead of only to prohibit Test::Distribution from running specified tests. It will run everything else.



Perl Testing. A Developer's Notebook
Perl Testing: A Developers Notebook
ISBN: 0596100922
EAN: 2147483647
Year: 2003
Pages: 107

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net