Skip to content

Commit

Permalink
We now allow 'skip_all' tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Curtis Poe committed Sep 14, 2008
1 parent 70aa017 commit f3ebb7f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 43 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
Revision history for Test-Aggregate Revision history for Test-Aggregate


0.34_02 14/09/2008
- Allow skip_all tests.

0.34_01 04/09/2008 0.34_01 04/09/2008
- Add an option to reinitialize FindBin for each aggregated test. - Add an option to reinitialize FindBin for each aggregated test.
- Don't emit a plan when not running any tests. - Don't emit a plan when not running any tests.
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -2,6 +2,7 @@ aggtests/00-load.t
aggtests/boilerplate.t aggtests/boilerplate.t
aggtests/check_plan.t aggtests/check_plan.t
aggtests/findbin.t aggtests/findbin.t
aggtests/skip_all.t
aggtests/slow_load.t aggtests/slow_load.t
aggtests/subs.t aggtests/subs.t
Build.PL Build.PL
Expand Down
22 changes: 7 additions & 15 deletions lib/Test/Aggregate.pm
Expand Up @@ -32,11 +32,11 @@ Test::Aggregate - Aggregate C<*.t> tests to make them run faster.
=head1 VERSION =head1 VERSION
Version 0.34_01 Version 0.34_02
=cut =cut


$VERSION = '0.34_01'; $VERSION = '0.34_02';


=head1 SYNOPSIS =head1 SYNOPSIS
Expand Down Expand Up @@ -445,10 +445,6 @@ if ( __FILE__ eq '$dump' ) {
if ( $test_code =~ /^(__(?:DATA|END)__)/m ) { if ( $test_code =~ /^(__(?:DATA|END)__)/m ) {
Test::More::BAIL_OUT("Test $test not allowed to have $1 token"); Test::More::BAIL_OUT("Test $test not allowed to have $1 token");
} }
if ( $test_code =~ /skip_all/m ) {
warn
"Found possible 'skip_all'. This can cause test suites to abort";
}
my $package = $self->_get_package($test); my $package = $self->_get_package($test);
push @{ $self->{_packages} } => [ $test, $package ]; push @{ $self->{_packages} } => [ $test, $package ];
if ( $setup ) { if ( $setup ) {
Expand Down Expand Up @@ -499,15 +495,17 @@ $reinit_findbin->() if $reinit_findbin;
$test_packages .= <<" END_CODE"; $test_packages .= <<" END_CODE";
{ {
$separator beginning of $test $separator $separator beginning of $test $separator
package $package; package $package;
sub run_the_tests { sub run_the_tests {
AGGTESTBLOCK: {
\$Test::Aggregate::Builder::FILE_FOR{$package} = '$test'; \$Test::Aggregate::Builder::FILE_FOR{$package} = '$test';
$set_filenames $set_filenames
$findbin $findbin
# line 1 "$test" # line 1 "$test"
$test_code $test_code
$see_if_tests_passed $see_if_tests_passed
} } # END AGGTESTBLOCK:
}
$separator end of $test $separator $separator end of $test $separator
} }
END_CODE END_CODE
Expand Down Expand Up @@ -730,12 +728,6 @@ This is needed when you use C<check_plan> and have C<Test::NoWarnings> used.
This is because we do work internally to subtract the extra test added by This is because we do work internally to subtract the extra test added by
C<Test::NoWarnings>. It's painful and experimental. Good luck. C<Test::NoWarnings>. It's painful and experimental. Good luck.
=item * No 'skip_all' tests, please
Tests which potentially 'skip_all' will cause the aggregate test suite to
abort prematurely. Do not attempt to aggregate them. This may be fixed in a
future release.
=item * C<Variable "$x" will not stay shared at (eval ...> =item * C<Variable "$x" will not stay shared at (eval ...>
Because each test is wrapped in a method call, any of your subs which access a Because each test is wrapped in a method call, any of your subs which access a
Expand Down
66 changes: 41 additions & 25 deletions lib/Test/Aggregate/Builder.pm
Expand Up @@ -11,11 +11,11 @@ Test::Aggregate::Builder - Internal overrides for Test::Builder.
=head1 VERSION =head1 VERSION
Version 0.34_01 Version 0.34_02
=cut =cut


$VERSION = '0.34_01'; $VERSION = '0.34_02';


=head1 SYNOPSIS =head1 SYNOPSIS
Expand Down Expand Up @@ -56,7 +56,7 @@ END {
# allows us to minimize the monkey patching. # allows us to minimize the monkey patching.


# XXX We fully-qualify the sub names because PAUSE won't index what it thinks # XXX We fully-qualify the sub names because PAUSE won't index what it thinks
# is an attempt to hijeck the Test::Builder namespace. # is an attempt to hijack the Test::Builder namespace.


sub Test::Builder::_plan_check { sub Test::Builder::_plan_check {
my $self = shift; my $self = shift;
Expand All @@ -71,19 +71,44 @@ sub Test::Builder::no_header { 1 }
my $plan; my $plan;
BEGIN { $plan = \&Test::Builder::plan } BEGIN { $plan = \&Test::Builder::plan }


sub Test::Builder::plan { {
delete $_[0]->{Have_Plan}; my %skip_reason_for;
my $callpack = caller(1);
if ( 'tests' eq ( $_[1] || '' ) ) {
$PLAN_FOR{$callpack} = $_[2];
if ( $TEST_NOWARNINGS_LOADED{$callpack} ) {


# Test::NoWarnings was loaded before plan() was called, so it sub Test::Builder::plan {
# didn't have a change to decrement it delete $_[0]->{Have_Plan};
$PLAN_FOR{$callpack}--;
if ( 'skip_all' eq ( $_[1] || '' )) {
my $callpack = caller(1);
$skip_reason_for{$callpack} = $_[2];
return;
}

my $callpack = caller(1);
if ( 'tests' eq ( $_[1] || '' ) ) {
$PLAN_FOR{$callpack} = $_[2];
if ( $TEST_NOWARNINGS_LOADED{$callpack} ) {

# Test::NoWarnings was loaded before plan() was called, so it
# didn't have a change to decrement it
$PLAN_FOR{$callpack}--;
}
}
$plan->(@_);
}

my $ok;
BEGIN { $ok = \&Test::Builder::ok }

sub Test::Builder::ok {
my $callpack = __check_test_count();
if ( my $reason = $skip_reason_for{$callpack} ) {
no warnings 'exiting';
$_[0]->skip($reason);
last AGGTESTBLOCK;
} }
local $Test::Builder::Level = $Test::Builder::Level + 1;
$ok->(@_);
} }
$plan->(@_);
} }


# Called in _ending and prevents the 'you tried to run a test without a # Called in _ending and prevents the 'you tried to run a test without a
Expand All @@ -96,15 +121,6 @@ sub Test::Builder::_sanity_check {
$_sanity_check->(@_); $_sanity_check->(@_);
} }


my $ok;
BEGIN { $ok = \&Test::Builder::ok }

sub Test::Builder::ok {
__check_test_count();
local $Test::Builder::Level = $Test::Builder::Level + 1;
$ok->(@_);
}

my $skip; my $skip;
BEGIN { $skip = \&Test::Builder::skip } BEGIN { $skip = \&Test::Builder::skip }


Expand All @@ -113,9 +129,9 @@ sub Test::Builder::skip {
$skip->(@_); $skip->(@_);
} }


# two purposes: we check the test cout for a package, but we also return the
# package name
sub __check_test_count { sub __check_test_count {
$DB::single = 1;
return unless $CHECK_PLAN;
my $callpack; my $callpack;
my $stack_level = 1; my $stack_level = 1;
while ( my ( $package, undef, undef, $subroutine ) = caller($stack_level) ) { while ( my ( $package, undef, undef, $subroutine ) = caller($stack_level) ) {
Expand All @@ -132,6 +148,7 @@ sub __check_test_count {
no warnings 'uninitialized'; no warnings 'uninitialized';
$TESTS_RUN{$callpack} += 1; $TESTS_RUN{$callpack} += 1;
} }
return $callpack;
} }


END { END {
Expand All @@ -144,7 +161,6 @@ END {
# use. As a result, it can be extremely difficult to track # use. As a result, it can be extremely difficult to track
# this. We may change this in the future. # this. We may change this in the future.
next unless my $file = $FILE_FOR{$package}; next unless my $file = $FILE_FOR{$package};
$DB::single = 1;
Test::More::is( $TESTS_RUN{$package} || 0, Test::More::is( $TESTS_RUN{$package} || 0,
$plan || 0, "Test ($file) should have the correct plan" ); $plan || 0, "Test ($file) should have the correct plan" );
} }
Expand Down
2 changes: 1 addition & 1 deletion t/lib/Slow/Loading/Module.pm
@@ -1,5 +1,5 @@
package Slow::Loading::Module; package Slow::Loading::Module;


sleep 5; sleep 1;


1; 1;
4 changes: 2 additions & 2 deletions t/pre_post.t
Expand Up @@ -32,5 +32,5 @@ my $tests = Test::Aggregate->new(
$tests->run; $tests->run;
is $startup, 4, 'Startup should be called once'; is $startup, 4, 'Startup should be called once';
is $shutdown, 1, '... as should shutdown'; is $shutdown, 1, '... as should shutdown';
is $setup, 9, 'Setup should be called once for each test program'; is $setup, 10, 'Setup should be called once for each test program';
is $teardown, 6, '... as should teardown'; is $teardown, 7, '... as should teardown';

0 comments on commit f3ebb7f

Please sign in to comment.