Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Fixed RT#39266: Test::Class with Package::Alias

-   startup and shutdown methods are no longer run if a class will not
    run any test methods
  • Loading branch information...
commit 99b701ed389d853f10c5eb1cc74ab5fb4e304f8d 1 parent c2e8604
@adrianh authored
View
3  Changes
@@ -3,6 +3,9 @@ Changes for Perl extension Test-Class
0.37 - or the "QA Hackathon 2011" release [2011-04-XX]
- Fixed RT#64470: minor documentation error in Test::Class::Load (thanks
to Andrew Grangaard for patch)
+ - Fixed RT#39266: Test::Class with Package::Alias
+ - startup and shutdown methods are no longer run if a class will not
+ run any test methods
- Added some more folk to acknowledgements
0.36 - or the "Adrian should have released this earlier" release [2010-08-19]
View
43 lib/Test/Class.pm
@@ -174,6 +174,8 @@ sub _num_expected_tests {
if (my $reason = $self->SKIP_CLASS ) {
return $reason eq "1" ? 0 : 1;
};
+ my @test_methods = _get_methods($self, TEST);
+ return 0 unless @test_methods;
my @startup_shutdown_methods =
_get_methods($self, STARTUP, SHUTDOWN);
my $num_startup_shutdown_methods =
@@ -182,7 +184,6 @@ sub _num_expected_tests {
my @fixture_methods = _get_methods($self, SETUP, TEARDOWN);
my $num_fixture_tests = _total_num_tests($self, @fixture_methods);
return(NO_PLAN) if $num_fixture_tests eq NO_PLAN;
- my @test_methods = _get_methods($self, TEST);
my $num_tests = _total_num_tests($self, @test_methods);
return(NO_PLAN) if $num_tests eq NO_PLAN;
return($num_startup_shutdown_methods + $num_tests + @test_methods * $num_fixture_tests);
@@ -345,27 +346,31 @@ sub runtests {
$Builder->skip( $reason ) unless $reason eq "1";
} else {
$t = $t->new unless ref($t);
- foreach my $method (_get_methods($t, STARTUP)) {
- _show_header($t, @tests) unless _has_no_tests($t, $method);
- my $method_passed = _run_method($t, $method, \@tests);
- $all_passed = 0 unless $method_passed;
- next TEST_OBJECT unless $method_passed;
- };
- my $class = ref($t);
- my @setup = _get_methods($t, SETUP);
- my @teardown = _get_methods($t, TEARDOWN);
- foreach my $test (_get_methods($t, TEST)) {
- local $Current_method = $test;
- $Builder->diag("\n$class->$test") if $ENV{TEST_VERBOSE};
- foreach my $method (@setup, $test, @teardown) {
+ my @test_methods = _get_methods($t, TEST);
+ if ( @test_methods ) {
+ foreach my $method (_get_methods($t, STARTUP)) {
_show_header($t, @tests) unless _has_no_tests($t, $method);
- $all_passed = 0 unless _run_method($t, $method, \@tests);
+ my $method_passed = _run_method($t, $method, \@tests);
+ $all_passed = 0 unless $method_passed;
+ next TEST_OBJECT unless $method_passed;
};
- };
- foreach my $method (_get_methods($t, SHUTDOWN)) {
- _show_header($t, @tests) unless _has_no_tests($t, $method);
- $all_passed = 0 unless _run_method($t, $method, \@tests);
+ my $class = ref($t);
+ my @setup = _get_methods($t, SETUP);
+ my @teardown = _get_methods($t, TEARDOWN);
+ foreach my $test ( @test_methods ) {
+ local $Current_method = $test;
+ $Builder->diag("\n$class->$test") if $ENV{TEST_VERBOSE};
+ foreach my $method (@setup, $test, @teardown) {
+ _show_header($t, @tests) unless _has_no_tests($t, $method);
+ $all_passed = 0 unless _run_method($t, $method, \@tests);
+ };
+ };
+ foreach my $method (_get_methods($t, SHUTDOWN)) {
+ _show_header($t, @tests) unless _has_no_tests($t, $method);
+ $all_passed = 0 unless _run_method($t, $method, \@tests);
+ }
}
+
}
}
return($all_passed);
View
41 t/filter_fixtures_only.t
@@ -2,34 +2,33 @@
use strict;
use warnings;
+use Test::More tests => 1;
-package Foo;
+{ package Foo;
+ use Test::More;
+ use base qw(Test::Class);
-use Test::More;
-use base qw(Test::Class);
+ sub test_filtered_startup : Test( startup => 1 ) {
+ fail( "startup test not run, as no normal tests are unfiltered" );
+ }
-sub test_filtered_startup : Test( startup => 1 ) {
- pass( "startup test is run, even though all tests match filter" );
-}
-
-sub test_filtered_setup : Test( setup => 1 ) {
- fail( "setup test not run, as no normal tests are unfiltered" );
-}
+ sub test_filtered_setup : Test( setup => 1 ) {
+ fail( "setup test not run, as no normal tests are unfiltered" );
+ }
-sub test_filtered_teardown : Test( teardown => 1 ) {
- fail( "teardown test not run, as no normal tests are unfiltered" );
-}
+ sub test_filtered_teardown : Test( teardown => 1 ) {
+ fail( "teardown test not run, as no normal tests are unfiltered" );
+ }
-sub test_filtered_shutdown : Test( shutdown => 1 ) {
- pass( "shutdown test is run, even though all tests match filter" );
-}
+ sub test_filtered_shutdown : Test( shutdown => 1 ) {
+ fail( "shutdown test not run, as no normal tests are unfiltered" );
+ }
-sub test_filtered : Test( 1 ) {
- fail( "shouldn't run, due to matching filter" );
+ sub test_filtered : Test( 1 ) {
+ fail( "shouldn't run, due to matching filter" );
+ }
}
-package main;
-
Test::Class->add_filter( sub { 0 } );
-Test::Class->runtests;
+is( Test::Class->expected_tests, 0, 'setup/teardown not run when no test methods' );
View
6 t/show_plan_in_shutdown.t
@@ -2,7 +2,7 @@
use strict;
use warnings FATAL => 'all';
-use Test::More tests => 1;
+use Test::More;
my $shutdown_has_run;
@@ -14,6 +14,10 @@ my $shutdown_has_run;
$shutdown_has_run = 1;
}
+ sub test : Test {
+ pass "passing test to force shutdown method to run";
+ }
+
}
My::Test->runtests( +1 );
View
69 t/skip_empty_classes.t
@@ -0,0 +1,69 @@
+#! /usr/bin/perl -T
+
+use strict;
+use warnings;
+use Test::Class;
+use Test;
+use Fcntl;
+use IO::File;
+use Test::Builder;
+
+{
+ package Base::Test;
+ use base qw(Test::Class);
+ use Test::More;
+
+ sub startup :Test(startup => 1) {
+ pass "startup run"
+ }
+
+ sub setup :Test(setup => 1) {
+ pass "setup run"
+ }
+
+ sub teardown :Test(teardown => 1) {
+ pass "teardown run"
+ }
+
+ sub shutdown :Test(shutdown => 1) {
+ pass "shutdown run"
+ }
+}
+
+{
+ package Bar::Test;
+ use base qw(Base::Test);
+ use Test::More;
+
+ sub the_test :Test {
+ pass "the_test has been run";
+ }
+}
+
+# plan tests => 3;
+#
+# my $io = IO::File->new_tmpfile or die "couldn't create tmp file ($!)\n";
+# my $Test = Test::Builder->new;
+# $Test->output($io);
+# $Test->failure_output($io);
+#
+# $ENV{TEST_VERBOSE}=0;
+
+$ENV{TEST_VERBOSE}=1;
+Test::Class->runtests;
+#
+# END {
+# seek $io, SEEK_SET, 0;
+# while (my $actual = <$io>) {
+# chomp($actual);
+# my $expected=<DATA>; chomp($expected);
+# ok($actual, $expected);
+# };
+#
+# ok($?, 0, "exit value okay");
+# $?=0;
+# };
+#
+# __DATA__
+# 1..1
+# ok 1 # skip because SKIP_CLASS returned a string
Please sign in to comment.
Something went wrong with that request. Please try again.