Permalink
Browse files

We now allow 'skip_all' tests.

  • Loading branch information...
1 parent 70aa017 commit f3ebb7febd9242e44c89efc5037b5f3eee1e6c2c Curtis Poe committed Sep 14, 2008
Showing with 55 additions and 43 deletions.
  1. +3 −0 Changes
  2. +1 −0 MANIFEST
  3. +7 −15 lib/Test/Aggregate.pm
  4. +41 −25 lib/Test/Aggregate/Builder.pm
  5. +1 −1 t/lib/Slow/Loading/Module.pm
  6. +2 −2 t/pre_post.t
View
@@ -1,5 +1,8 @@
Revision history for Test-Aggregate
+0.34_02 14/09/2008
+ - Allow skip_all tests.
+
0.34_01 04/09/2008
- Add an option to reinitialize FindBin for each aggregated test.
- Don't emit a plan when not running any tests.
View
@@ -2,6 +2,7 @@ aggtests/00-load.t
aggtests/boilerplate.t
aggtests/check_plan.t
aggtests/findbin.t
+aggtests/skip_all.t
aggtests/slow_load.t
aggtests/subs.t
Build.PL
View
@@ -32,11 +32,11 @@ Test::Aggregate - Aggregate C<*.t> tests to make them run faster.
=head1 VERSION
-Version 0.34_01
+Version 0.34_02
=cut
-$VERSION = '0.34_01';
+$VERSION = '0.34_02';
=head1 SYNOPSIS
@@ -445,10 +445,6 @@ if ( __FILE__ eq '$dump' ) {
if ( $test_code =~ /^(__(?:DATA|END)__)/m ) {
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);
push @{ $self->{_packages} } => [ $test, $package ];
if ( $setup ) {
@@ -499,15 +495,17 @@ $reinit_findbin->() if $reinit_findbin;
$test_packages .= <<" END_CODE";
{
$separator beginning of $test $separator
-package $package;
-sub run_the_tests {
+ package $package;
+ sub run_the_tests {
+ AGGTESTBLOCK: {
\$Test::Aggregate::Builder::FILE_FOR{$package} = '$test';
$set_filenames
$findbin
# line 1 "$test"
$test_code
$see_if_tests_passed
-}
+ } # END AGGTESTBLOCK:
+ }
$separator end of $test $separator
}
END_CODE
@@ -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
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 ...>
Because each test is wrapped in a method call, any of your subs which access a
@@ -11,11 +11,11 @@ Test::Aggregate::Builder - Internal overrides for Test::Builder.
=head1 VERSION
-Version 0.34_01
+Version 0.34_02
=cut
-$VERSION = '0.34_01';
+$VERSION = '0.34_02';
=head1 SYNOPSIS
@@ -56,7 +56,7 @@ END {
# allows us to minimize the monkey patching.
# 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 {
my $self = shift;
@@ -71,19 +71,44 @@ sub Test::Builder::no_header { 1 }
my $plan;
BEGIN { $plan = \&Test::Builder::plan }
-sub Test::Builder::plan {
- delete $_[0]->{Have_Plan};
- my $callpack = caller(1);
- if ( 'tests' eq ( $_[1] || '' ) ) {
- $PLAN_FOR{$callpack} = $_[2];
- if ( $TEST_NOWARNINGS_LOADED{$callpack} ) {
+{
+ my %skip_reason_for;
- # Test::NoWarnings was loaded before plan() was called, so it
- # didn't have a change to decrement it
- $PLAN_FOR{$callpack}--;
+ sub Test::Builder::plan {
+ delete $_[0]->{Have_Plan};
+
+ 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
@@ -96,15 +121,6 @@ sub Test::Builder::_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;
BEGIN { $skip = \&Test::Builder::skip }
@@ -113,9 +129,9 @@ sub Test::Builder::skip {
$skip->(@_);
}
+# two purposes: we check the test cout for a package, but we also return the
+# package name
sub __check_test_count {
- $DB::single = 1;
- return unless $CHECK_PLAN;
my $callpack;
my $stack_level = 1;
while ( my ( $package, undef, undef, $subroutine ) = caller($stack_level) ) {
@@ -132,6 +148,7 @@ sub __check_test_count {
no warnings 'uninitialized';
$TESTS_RUN{$callpack} += 1;
}
+ return $callpack;
}
END {
@@ -144,7 +161,6 @@ END {
# use. As a result, it can be extremely difficult to track
# this. We may change this in the future.
next unless my $file = $FILE_FOR{$package};
- $DB::single = 1;
Test::More::is( $TESTS_RUN{$package} || 0,
$plan || 0, "Test ($file) should have the correct plan" );
}
@@ -1,5 +1,5 @@
package Slow::Loading::Module;
-sleep 5;
+sleep 1;
1;
View
@@ -32,5 +32,5 @@ my $tests = Test::Aggregate->new(
$tests->run;
is $startup, 4, 'Startup should be called once';
is $shutdown, 1, '... as should shutdown';
-is $setup, 9, 'Setup should be called once for each test program';
-is $teardown, 6, '... as should teardown';
+is $setup, 10, 'Setup should be called once for each test program';
+is $teardown, 7, '... as should teardown';

0 comments on commit f3ebb7f

Please sign in to comment.