Skip to content

Commit

Permalink
Make test filename argument to setup/teardown methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Curtis Poe committed Nov 24, 2009
1 parent 4626122 commit d0ab75a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 19 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Revision history for Test-Aggregate

0.363 24/11/2009
- Pass current test name to setup and teardown.

0.362 17/11/2009
- Removed broken "check_plan" from Test::Aggregate. It was always
dodgy and really doesn't contribute much and the latest release
Expand Down
10 changes: 5 additions & 5 deletions META.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Test-Aggregate
version: 0.362
version: 0.363
author:
- 'Curtis "Ovid" Poe <ovid@cpan.org>'
abstract: Aggregate C<*.t> tests to make them run faster.
Expand All @@ -23,16 +23,16 @@ configure_requires:
provides:
Test::Aggregate:
file: lib/Test/Aggregate.pm
version: 0.362
version: 0.363
Test::Aggregate::Base:
file: lib/Test/Aggregate/Base.pm
version: 0.362
version: 0.363
Test::Aggregate::Builder:
file: lib/Test/Aggregate/Builder.pm
version: 0.362
version: 0.363
Test::Aggregate::Nested:
file: lib/Test/Aggregate/Nested.pm
version: 0.362
version: 0.363
generated_by: Module::Build version 0.35
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
Expand Down
16 changes: 10 additions & 6 deletions lib/Test/Aggregate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Test::Aggregate - Aggregate C<*.t> tests to make them run faster.
=head1 VERSION
Version 0.362
Version 0.363
=cut

our $VERSION = '0.362';
our $VERSION = '0.363';
$VERSION = eval $VERSION;

=head1 SYNOPSIS
Expand Down Expand Up @@ -306,7 +306,7 @@ sub run {
foreach my $data (@packages) {
$current_test++;
my ( $test, $package ) = @$data;
$self->_setup->() if $self->_setup;
$self->_setup->($test) if $self->_setup;
run_this_test_program( $package => $test, $current_test, $total_tests, 2 );
if ( my $error = $@ ) {
Test::More::ok( 0, "Error running ($test): $error" );
Expand All @@ -316,7 +316,7 @@ sub run {
# internally.
$BUILDER->{XXX_test_failed} = 0;
$BUILDER->{TEST_MOST_test_failed} = 0;
$self->_teardown->() if $self->_teardown;
$self->_teardown->($test) if $self->_teardown;
}
$self->_shutdown->() if $self->_shutdown;
}
Expand Down Expand Up @@ -625,18 +625,22 @@ called in an END block.
=item * C<setup>
setup => sub {
my $filename = shift;
# this gets run before each test program.
},
The setup function will be run before every test program.
The setup function will be run before every test program. The name of the
test file will be passed as the first argument.
=item * C<teardown>
teardown => sub {
my $filename = shift;
# this gets run after every test program.
}
The teardown function gets run after every test program.
The teardown function gets run after every test program. The name of the test
file will be passed as the first argument.
=back
Expand Down
4 changes: 2 additions & 2 deletions lib/Test/Aggregate/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use File::Find;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Test::Builder::Module);

our $VERSION = '0.362';
our $VERSION = '0.363';
$VERSION = eval $VERSION;

BEGIN {
Expand Down Expand Up @@ -214,7 +214,7 @@ Test::Aggregate::Base - Base class for aggregated tests.
=head1 VERSION
Version 0.362
Version 0.363
=head1 SYNOPSIS
Expand Down
4 changes: 2 additions & 2 deletions lib/Test/Aggregate/Builder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Test::Aggregate::Builder - Internal overrides for Test::Builder.
=head1 VERSION
Version 0.362
Version 0.363
=cut

our $VERSION = '0.362';
our $VERSION = '0.363';
$VERSION = eval $VERSION;

=head1 SYNOPSIS
Expand Down
4 changes: 2 additions & 2 deletions lib/Test/Aggregate/Nested.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ Test::Aggregate::Nested - Aggregate C<*.t> tests to make them run faster.
=head1 VERSION
Version 0.362
Version 0.363
=cut

our $VERSION = '0.362';
our $VERSION = '0.363';
$VERSION = eval $VERSION;

=head1 SYNOPSIS
Expand Down
12 changes: 10 additions & 2 deletions t/pre_post.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ $SIG{__WARN__} = sub {

my $dump = 'dump.t';

my $found_it;
my $tests = Test::Aggregate->new(
{
dirs => 'aggtests',
findbin => 1,
startup => sub { $startup++ },
shutdown => sub { $shutdown++ },
setup => sub { $setup++ },
setup => sub {
my $file = shift;
if ( $file =~ /slow_load\.t$/ ) {
$found_it = 1;
}
$setup++;
},
teardown => sub { $teardown++ },
# dump => $dump,
}
Expand All @@ -36,4 +43,5 @@ is $shutdown, 1, '... as should shutdown';
is $setup, 7, 'Setup should be called once for each test program';
is $teardown, 7, '... as should teardown';
#unlink $dump or warn "Cannot unlink ($dump): $!";
done_testing() if __PACKAGE__->can('done_testing');
ok $found_it, '... and file names should be passed to setup';
done_testing();

0 comments on commit d0ab75a

Please sign in to comment.