r61790 - in /branches/upstream/libtest-class-perl/current: ./ lib/Test/ lib/Test/Class/ t/

carnil-guest at users.alioth.debian.org carnil-guest at users.alioth.debian.org
Fri Aug 20 08:19:57 UTC 2010


Author: carnil-guest
Date: Fri Aug 20 08:19:19 2010
New Revision: 61790

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=61790
Log:
[svn-upgrade] new version libtest-class-perl (0.36)

Added:
    branches/upstream/libtest-class-perl/current/t/filter.t
    branches/upstream/libtest-class-perl/current/t/filter_bad_filter.t
    branches/upstream/libtest-class-perl/current/t/filter_fixtures.t
    branches/upstream/libtest-class-perl/current/t/filter_fixtures_only.t
    branches/upstream/libtest-class-perl/current/t/filter_multiple.t
Modified:
    branches/upstream/libtest-class-perl/current/Changes
    branches/upstream/libtest-class-perl/current/MANIFEST
    branches/upstream/libtest-class-perl/current/META.yml
    branches/upstream/libtest-class-perl/current/Makefile.PL
    branches/upstream/libtest-class-perl/current/README
    branches/upstream/libtest-class-perl/current/lib/Test/Class.pm
    branches/upstream/libtest-class-perl/current/lib/Test/Class/MethodInfo.pm
    branches/upstream/libtest-class-perl/current/t/todo.t

Modified: branches/upstream/libtest-class-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-class-perl/current/Changes?rev=61790&op=diff
==============================================================================
--- branches/upstream/libtest-class-perl/current/Changes (original)
+++ branches/upstream/libtest-class-perl/current/Changes Fri Aug 20 08:19:19 2010
@@ -1,4 +1,10 @@
 Changes for Perl extension Test-Class
+
+0.36 - or the "Adrian should have released this earlier" release [2010-08-19]
+(Thanks to Mark Morgan for doing all the useful work on this one!)
+    - New add_filter() method allows global filtering of test methods
+    - Apply t/todo.t patch to fix RT#55324 (test bug, not Test::Class bug).
+      This makes the test suite pass with Test::Simple 0.95_01 and greater.
 
 0.35 - or the "Yay! Open Source For The Win!" release [2010-04-28]
     -   Introducing Ovid & Mark Morgan in "Folk with commit bits who aren't 

Modified: branches/upstream/libtest-class-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-class-perl/current/MANIFEST?rev=61790&op=diff
==============================================================================
--- branches/upstream/libtest-class-perl/current/MANIFEST (original)
+++ branches/upstream/libtest-class-perl/current/MANIFEST Fri Aug 20 08:19:19 2010
@@ -23,6 +23,11 @@
 t/fail1.t
 t/fail2.t
 t/fail3.t
+t/filter.t
+t/filter_bad_filter.t
+t/filter_fixtures.t
+t/filter_fixtures_only.t
+t/filter_multiple.t
 t/header.t
 t/late_header.t
 t/methodinfo.t

Modified: branches/upstream/libtest-class-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-class-perl/current/META.yml?rev=61790&op=diff
==============================================================================
--- branches/upstream/libtest-class-perl/current/META.yml (original)
+++ branches/upstream/libtest-class-perl/current/META.yml Fri Aug 20 08:19:19 2010
@@ -7,7 +7,7 @@
   Test::Exception: 0.25
 configure_requires:
   Module::Build: 0.36
-generated_by: 'Module::Build version 0.3603'
+generated_by: 'Module::Build version 0.3607'
 license: perl
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -16,7 +16,7 @@
 provides:
   Test::Class:
     file: lib/Test/Class.pm
-    version: 0.35
+    version: 0.36
   Test::Class::Load:
     file: lib/Test/Class/Load.pm
     version: 0.35
@@ -35,4 +35,4 @@
 resources:
   license: http://dev.perl.org/licenses/
   repository: http://github.com/adrianh/test-class/
-version: 0.35
+version: 0.36

Modified: branches/upstream/libtest-class-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-class-perl/current/Makefile.PL?rev=61790&op=diff
==============================================================================
--- branches/upstream/libtest-class-perl/current/Makefile.PL (original)
+++ branches/upstream/libtest-class-perl/current/Makefile.PL Fri Aug 20 08:19:19 2010
@@ -1,23 +1,23 @@
-# Note: this file was auto-generated by Module::Build::Compat version 0.3603
+# Note: this file was auto-generated by Module::Build::Compat version 0.3607
 require 5.006001;
 use ExtUtils::MakeMaker;
 WriteMakefile
 (
-          'NAME' => 'Test::Class',
-          'VERSION_FROM' => 'lib/Test/Class.pm',
-          'PREREQ_PM' => {
-                           'Attribute::Handlers' => '0.77',
-                           'IO::File' => '1.09',
-                           'MRO::Compat' => '0.11',
-                           'Storable' => '2.04',
-                           'Test::Builder' => '0.78',
-                           'Test::Builder::Tester' => '1.02',
-                           'Test::Exception' => '0.25',
-                           'Test::More' => '0.78',
-                           'Test::Simple' => '0.78'
-                         },
-          'INSTALLDIRS' => 'site',
-          'EXE_FILES' => [],
-          'PL_FILES' => {}
-        )
+  'PL_FILES' => {},
+  'INSTALLDIRS' => 'site',
+  'NAME' => 'Test::Class',
+  'EXE_FILES' => [],
+  'VERSION_FROM' => 'lib/Test/Class.pm',
+  'PREREQ_PM' => {
+                   'Test::Exception' => '0.25',
+                   'IO::File' => '1.09',
+                   'Attribute::Handlers' => '0.77',
+                   'Storable' => '2.04',
+                   'Test::Simple' => '0.78',
+                   'Test::Builder::Tester' => '1.02',
+                   'Test::More' => '0.78',
+                   'Test::Builder' => '0.78',
+                   'MRO::Compat' => '0.11'
+                 }
+)
 ;

Modified: branches/upstream/libtest-class-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-class-perl/current/README?rev=61790&op=diff
==============================================================================
--- branches/upstream/libtest-class-perl/current/README (original)
+++ branches/upstream/libtest-class-perl/current/README Fri Aug 20 08:19:19 2010
@@ -275,7 +275,7 @@
   
       # and run them all
       Test::Class->runtests;
-
+  
     You can use Test::Class::Load to automatically load all the test classes
     in a given set of directories.
 
@@ -355,7 +355,7 @@
     test description, for example:
 
       is $something, $something_else, 'a description of my test';
-
+    
     If you do not supply a test description, and the test function does not
     supply its own default, then Test::Class will use the name of the
     currently running test method, replacing all "_" characters with spaces
@@ -364,7 +364,7 @@
       sub one_plus_one_is_two : Test {
           is 1+1, 2;
       }
-
+  
     will result in:
 
       ok 1 - one plus one is two
@@ -437,7 +437,7 @@
       sub read_file : Test {
           is(read_file('test.txt'), "content", 'test file read');
       };
-
+  
     If more than one test remains after an exception then the first one is
     failed, and the remaining ones are skipped.
 
@@ -642,11 +642,11 @@
     modules. Basically while:
 
       require $some_test_class;
-
+  
     will break, doing:
 
       BEGIN { require $some_test_class };
-
+  
     will work just fine. For more information on CHECK blocks see "BEGIN,
     CHECK, INIT and END" in perlmod.
 
@@ -659,6 +659,50 @@
       __PACKAGE__->add_testinfo('test_something', test => 3);
 
     See the add_testinfo method for more details.
+
+GENERAL FILTERING OF TESTS
+    The use of $ENV{TEST_METHOD} to run just a subset of tests is useful,
+    but sometimes it doesn't give the level of granularity that you desire.
+    Another feature of this class is the ability to do filtering on other
+    static criteria. In order to permit this, a generic filtering method is
+    supported. This can be used by specifying coderefs to the 'add_filter'
+    method of this class.
+
+    In determining which tests should be run, all filters that have
+    previously been specified via the add_filter method will be run in-turn
+    for each normal test method. If any of these filters return a false
+    value, the method will not be executed, or included in the number of
+    tests. Note that filters will only be run for normal test methods, they
+    are ignored for startup, shutdown, setup, and teardown test methods.
+
+    Note that test filters are global, and will affect all tests in all
+    classes, not just the one that they were defined in.
+
+    An example of this mechanism that mostly simulates the use of
+    TEST_METHOD above is:
+
+     package MyTests;
+
+     use Test::More;
+
+     use base qw( Test::Class );
+
+     my $MYTEST_METHOD = qr/^t_not_filtered$/;
+
+     my $filter = sub {
+        my ( $test_class, $test_method ) = @_;
+
+        return $test_method =~ $MYTEST_METHOD;
+     };
+     Test::Class->add_filter( $filter );
+
+     sub t_filtered : Test( 1 ) {
+        fail( "filtered test run" );
+     }
+
+     sub t_not_filtered : Test( 1 ) {
+        pass( "unfiltered test run" );
+     }
 
 METHODS
   Creating and running tests
@@ -787,7 +831,7 @@
         "runtests" is used to run test classes. At its most basic doing:
 
           $test->runtests
-
+  
         will run the test methods of the test object $test, unless
         "$test->SKIP_CLASS" returns a true value.
 
@@ -827,7 +871,7 @@
   
           # run all the Foo*Test modules we just loaded
           Test::Class->runtests;
-
+    
     SKIP_CLASS
           $reason = CLASS->SKIP_CLASS;
           CLASS->SKIP_CLASS( $reason );
@@ -841,7 +885,7 @@
         class that should not run just add the following to your module:
 
           My::Abstract::Test->SKIP_CLASS( 1 );
-
+  
         This will not affect any sub-classes of "My::Abstract::Test" which
         will run as normal.
 
@@ -866,7 +910,7 @@
           sub My::Postgres::Test::SKIP_CLASS {
               $ENV{POSTGRES_HOME} ? 0 : '$POSTGRES_HOME needs to be set'
           };
-
+  
   Fetching and setting a method's test number
     num_method_tests
           $n = $Tests->num_method_tests($method_name)
@@ -1069,6 +1113,20 @@
         $name is the name of the method, $type must be one of "startup",
         "setup", "test", "teardown" or "shutdown", and $num_tests has the
         same meaning as "N" in the description of the Test attribute.
+
+    add_filter
+            CLASS->add_filter($filter_coderef);
+
+        Adds a filtering coderef. Each filter is passed a test class and
+        method name and returns a boolean. All filters are applied globally
+        in the order they were added. If any filter returns false the test
+        method is not run or included in the number of tests.
+
+        Note that filters will only be run for normal test methods, they are
+        ignored for startup, shutdown, setup, and teardown test methods.
+
+        See the section on the "GENERAL FILTERING OF TESTS" for more
+        information.
 
 HELP FOR CONFUSED JUNIT USERS
     This section is for people who have used JUnit (or similar) and are

Modified: branches/upstream/libtest-class-perl/current/lib/Test/Class.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-class-perl/current/lib/Test/Class.pm?rev=61790&op=diff
==============================================================================
--- branches/upstream/libtest-class-perl/current/lib/Test/Class.pm (original)
+++ branches/upstream/libtest-class-perl/current/lib/Test/Class.pm Fri Aug 20 08:19:19 2010
@@ -11,7 +11,7 @@
 use Test::Builder;
 use Test::Class::MethodInfo;
 
-our $VERSION = '0.35';
+our $VERSION = '0.36';
 
 my $Check_block_has_run;
 {
@@ -36,6 +36,7 @@
 
 
 my $Tests = {};
+my @Filters = ();
 
 
 my %_Test;  # inside-out object field indexed on $self
@@ -143,8 +144,18 @@
 	
 	my %methods = ();
 	foreach my $class ( @{mro::get_linear_isa( $test_class )} ) {
+      FILTER:
 		foreach my $info ( _methods_of_class( $self, $class ) ) {
 		    my $name = $info->name;
+
+            if ( $info->type eq TEST ) {
+                # determine if method is filtered, true if *any* filter
+                # returns false.
+                foreach my $filter ( @Filters ) {
+                    next FILTER unless $filter->( $class, $name );
+                }
+            }
+
 			foreach my $type ( @types ) {
 			    if ( $info->is_type( $type ) ) {
     				$methods{ $name } = 1 
@@ -413,6 +424,16 @@
 	exit(0);
 }
 
+sub add_filter {
+    my ( $class, $cb ) = @_;
+
+    if ( not ref $cb eq 'CODE' ) {
+        croak "Filter isn't a code-ref"
+    }
+
+    push @Filters, $cb;
+}
+
 1;
 
 __END__
@@ -1044,6 +1065,49 @@
 
 See the L<add_testinfo|/"add_testinfo"> method for more details.
 
+=head1 GENERAL FILTERING OF TESTS
+
+The use of $ENV{TEST_METHOD} to run just a subset of tests is useful, but
+sometimes it doesn't give the level of granularity that you desire.  Another
+feature of this class is the ability to do filtering on other static criteria.
+In order to permit this, a generic filtering method is supported.  This can
+be used by specifying coderefs to the 'add_filter' method of this class.
+
+In determining which tests should be run, all filters that have previously
+been specified via the add_filter method will be run in-turn for each normal
+test method.  If B<any> of these filters return a false value, the method will
+not be executed, or included in the number of tests.  Note that filters will
+only be run for normal test methods, they are ignored for startup, shutdown,
+setup, and teardown test methods.
+
+Note that test filters are global, and will affect all tests in all classes,
+not just the one that they were defined in.
+
+An example of this mechanism that mostly simulates the use of TEST_METHOD
+above is:
+
+ package MyTests;
+
+ use Test::More;
+
+ use base qw( Test::Class );
+
+ my $MYTEST_METHOD = qr/^t_not_filtered$/;
+
+ my $filter = sub {
+    my ( $test_class, $test_method ) = @_;
+
+    return $test_method =~ $MYTEST_METHOD;
+ };
+ Test::Class->add_filter( $filter );
+
+ sub t_filtered : Test( 1 ) {
+    fail( "filtered test run" );
+ }
+
+ sub t_not_filtered : Test( 1 ) {
+    pass( "unfiltered test run" );
+ }
 
 =head1 METHODS
 
@@ -1420,6 +1484,16 @@
 
 C<$name> is the name of the method, C<$type> must be one of C<startup>, C<setup>, C<test>, C<teardown> or C<shutdown>, and C<$num_tests> has the same meaning as C<N> in the description of the L<Test|/"Test"> attribute.
 
+
+=item B<add_filter>
+
+    CLASS->add_filter($filter_coderef);
+
+Adds a filtering coderef. Each filter is passed a test class and method name and returns a boolean. All filters are applied globally in the order they were added. If any filter returns false the test method is not run or included in the number of tests.
+
+Note that filters will only be run for normal test methods, they are ignored for startup, shutdown, setup, and teardown test methods.
+
+See the section on the L</"GENERAL FILTERING OF TESTS"> for more information.
 
 =back
 

Modified: branches/upstream/libtest-class-perl/current/lib/Test/Class/MethodInfo.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-class-perl/current/lib/Test/Class/MethodInfo.pm?rev=61790&op=diff
==============================================================================
--- branches/upstream/libtest-class-perl/current/lib/Test/Class/MethodInfo.pm (original)
+++ branches/upstream/libtest-class-perl/current/lib/Test/Class/MethodInfo.pm Fri Aug 20 08:19:19 2010
@@ -20,6 +20,8 @@
 };
 
 sub name { shift->{name} };
+
+sub type { shift->{type} };
 
 sub num_tests	{ 
 	my ( $self, $n ) = @_;
@@ -76,6 +78,8 @@
 
 =item B<name>
 
+=item B<type>
+
 =item B<num_tests>
 
 =back
@@ -114,4 +118,4 @@
 
 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
 
-=cut
+=cut

Added: branches/upstream/libtest-class-perl/current/t/filter.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-class-perl/current/t/filter.t?rev=61790&op=file
==============================================================================
--- branches/upstream/libtest-class-perl/current/t/filter.t (added)
+++ branches/upstream/libtest-class-perl/current/t/filter.t Fri Aug 20 08:19:19 2010
@@ -1,0 +1,26 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+package Foo;
+use Test::More;
+use base qw(Test::Class);
+
+sub test_run : Test(1) {
+	pass( "test_run not filtered, so is run" );
+};
+
+package Bar;
+use Test::More;
+use base qw(Test::Class);
+
+sub test_filter_due_to_class : Test(1) {
+    fail( "shouldn't run, due to class filter" );
+}
+
+package main;
+
+Test::Class->add_filter( sub { $_[0] eq 'Foo' } );
+
+Test::Class->runtests;

Added: branches/upstream/libtest-class-perl/current/t/filter_bad_filter.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-class-perl/current/t/filter_bad_filter.t?rev=61790&op=file
==============================================================================
--- branches/upstream/libtest-class-perl/current/t/filter_bad_filter.t (added)
+++ branches/upstream/libtest-class-perl/current/t/filter_bad_filter.t Fri Aug 20 08:19:19 2010
@@ -1,0 +1,14 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+package main;
+
+use Test::Class;
+use Test::More tests => 1;
+
+eval {
+    Test::Class->add_filter( 'not a sub' );
+};
+like( $@, qr/^Filter isn't a code-ref/, "error on non-coderef filter" );

Added: branches/upstream/libtest-class-perl/current/t/filter_fixtures.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-class-perl/current/t/filter_fixtures.t?rev=61790&op=file
==============================================================================
--- branches/upstream/libtest-class-perl/current/t/filter_fixtures.t (added)
+++ branches/upstream/libtest-class-perl/current/t/filter_fixtures.t Fri Aug 20 08:19:19 2010
@@ -1,0 +1,39 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+package Foo;
+
+use Test::More;
+use base qw(Test::Class);
+
+sub test_filtered_startup : Test( startup => 1 ) {
+    pass( "startup test is run, even though matches filter" );
+}
+
+sub test_filtered_setup : Test( setup => 1 ) {
+    pass( "setup test is run, even though matches filter" );
+}
+
+sub test_filtered_teardown : Test( teardown => 1 ) {
+    pass( "teardown test is run, even though matches filter" );
+}
+
+sub test_filtered_shutdown : Test( shutdown => 1 ) {
+    pass( "shutdown test is run, even though matches filter" );
+}
+
+sub test_filtered : Test( 1 ) {
+    fail( "shouldn't run, due to matching filter" );
+}
+
+sub test_should_run : Test( 1 ) {
+    pass( "should run, due to not matching filter" );
+}
+
+package main;
+
+Test::Class->add_filter( sub { $_[1] !~ /filtered/ } );
+
+Test::Class->runtests;

Added: branches/upstream/libtest-class-perl/current/t/filter_fixtures_only.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-class-perl/current/t/filter_fixtures_only.t?rev=61790&op=file
==============================================================================
--- branches/upstream/libtest-class-perl/current/t/filter_fixtures_only.t (added)
+++ branches/upstream/libtest-class-perl/current/t/filter_fixtures_only.t Fri Aug 20 08:19:19 2010
@@ -1,0 +1,35 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+package Foo;
+
+use Test::More;
+use base qw(Test::Class);
+
+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_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 : Test( 1 ) {
+    fail( "shouldn't run, due to matching filter" );
+}
+
+package main;
+
+Test::Class->add_filter( sub { 0 } );
+
+Test::Class->runtests;

Added: branches/upstream/libtest-class-perl/current/t/filter_multiple.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-class-perl/current/t/filter_multiple.t?rev=61790&op=file
==============================================================================
--- branches/upstream/libtest-class-perl/current/t/filter_multiple.t (added)
+++ branches/upstream/libtest-class-perl/current/t/filter_multiple.t Fri Aug 20 08:19:19 2010
@@ -1,0 +1,35 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+package Foo;
+use Test::More;
+use base qw(Test::Class);
+
+sub test_not_filtered : Test(1) {
+    pass( "test_not_filtered doesn't meet any filters, so is run" );
+};
+
+sub test_filter_me : Test(1) {
+    fail( "shouldn't run, due to filtering of /filter_me/" );
+}
+
+sub test_me_too : Test(1) {
+    fail( "shouldn't run, due to filtering of /me_too/" );
+}
+
+sub test_filter_me_as_well : Test(1) {
+    fail( "shouldn't run, due to filtering of /filter_me/" );
+}
+
+sub test_another_not_matching : Test(1) {
+    pass( "test_another_not_matching doesn't meet any filters, so is run" );
+}
+
+package main;
+
+Test::Class->add_filter( sub { $_[1] !~ /filter_me/ } );
+Test::Class->add_filter( sub { $_[1] !~ /me_too/ } );
+
+Test::Class->runtests;

Modified: branches/upstream/libtest-class-perl/current/t/todo.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-class-perl/current/t/todo.t?rev=61790&op=diff
==============================================================================
--- branches/upstream/libtest-class-perl/current/t/todo.t (original)
+++ branches/upstream/libtest-class-perl/current/t/todo.t Fri Aug 20 08:19:19 2010
@@ -18,14 +18,27 @@
 
 package main;
 use Test::Builder::Tester tests => 2;
+use Test::More;
 $ENV{TEST_VERBOSE}=0;
 
 my $filename = sub { return (caller)[1] }->();
 
+my $test_more_version = eval($Test::More::VERSION);
+diag "Test::More: $test_more_version";
+
 test_out( "not ok 1 - object live # TODO unimplemented" );
-test_err( "#     Failed (TODO) test ($filename at line 16)" );
-
-test_err( "#   (in Foo->todo_test)" );
+if ($test_more_version >= 0.9501) {
+    # Test-Simple-0.95_01 or later output TODO message to output handle.
+    # see http://cpansearch.perl.org/src/MSCHWERN/Test-Simple-0.95_01/Changes
+    #    Test::Builder::Tester now sets $tb->todo_output to the output handle and
+    #    not the error handle (to be in accordance with the default behaviour of
+    #    Test::Builder and allow for testing TODO test behaviour).
+    test_out( "#     Failed (TODO) test ($filename at line 16)" );
+    test_out( "#   (in Foo->todo_test)" );
+} else {
+    test_err( "#     Failed (TODO) test ($filename at line 16)" );
+    test_err( "#   (in Foo->todo_test)" );
+}
 Foo->runtests;
 test_test("todo tests work");
 




More information about the Pkg-perl-cvs-commits mailing list