The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::Aggregate - Aggregate *.t tests to make them run faster.

VERSION

Version 0.02

SYNOPSIS

    use Test::Aggregate;

    Test::Aggregate->runtests($dir);

DESCRIPTION

WARNING: this is ALPHA code. The interface is not guaranteed to be stable.

A common problem with many test suites is that they can take a long time to run. The longer they run, the less likely you are to run the tests. This module borrows a trick from Apache::Registry to load up your tests at once, create a separate package for each test and wraps the code in a method named run_the_tests. This allows us to load perl only once and related modules only once. If you have modules which are expensive to load, this can dramatically speed up a test suite.

USAGE

Create a separate directory for your tests. This should not be a subdirectory of your regular test directory. Write a small driver program and put it in your regular test directory (t/ is the standard):

 use Test::Aggregate;
 my $other_test_dir = 'aggregate_tests';
 Test::Aggregate->runtests($other_test_dir);

Take your simplest tests and move them, one by one, into the new test directory and keep running the Test::Aggregate program. You'll find some tests will not run in a shared environment like this. You can either fix the tests or simply leave them in your regular test directory. See how this distribution's tests are organized for an example.

METHODS

runtests

 my $test_dir = 'aggtests/';
 Test::Aggregate->runtests($test_dir);
 

Attempts to aggregate all test programs in a given directory and run them at the same time.

If $Test::Aggregate::DUMP is set, will attempt to use the value as a filename and print the code to it.

CAVEATS

Not all tests can be included with this technique. If you have Test::Class tests, there is no need to run them with this. Otherwise:

  • __END__ and __DATA__ tokens.

    These won't work and the tests will call BAIL_OUT() if these tokens are seen.

  • BEGIN and END blocks.

    Since all of the tests are aggregated together, BEGIN and END blocks will be for the scope of the entire set of aggregated tests.

  • Syntax errors

    Any syntax errors encountered will cause this program to BAIL_OUT(). This is why it's recommended that you move your tests into your new directory one at a time: it makes it easier to figure out which one has caused the problem.

  • no_plan

    Unfortunately, due to how this works, the plan is always no_plan. If Test::Builder implements "deferred plans", we can get a bit more safety. See http://groups.google.com/group/perl.qa/browse_thread/thread/d58c49db734844f4/cd18996391acc601?#cd18996391acc601 for more information.

  • Variable "$x" will not stay shared at (eval ...

    Because each test is wrapped in a method call, any of your subs which access a variable in an outer scope will likely throw the above warning. Pass in arguments explicitly to suppress this.

    Instead of:

     my $x = 17;
     sub foo {
         my $y = shift;
         return $y + $x;
     }

    Write this:

     my $x = 17;
     sub foo {
         my ( $y, $x ) = @_;
         return $y + $x;
     }

AUTHOR

Curtis Poe, <ovid at cpan.org>

BUGS

Please report any bugs or feature requests to bug-test-aggregate at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Aggregate. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Test::Aggregate

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2007 Curtis Poe, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.