Created
August 16, 2010 20:24
-
-
Save wchristian/527670 to your computer and use it in GitHub Desktop.
a subclass of Test::Class that adds a TestGroup attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
package Test::Class::TestGroup; | |
no warnings 'redefine'; | |
use parent 'Test::Class'; | |
use Test::More; | |
use Data::Dumper; | |
sub TestGroup : ATTR(CODE,RAWDATA) { | |
my ($class, $symbol, $code_ref, $attr, $args) = @_; | |
# get the test description either from the args, or from the sub routine name; then reset the args to 1 (single test) | |
my $test_description = $args || *{$symbol}{NAME}; | |
$args = 1; | |
# wrap the old function in a subtest | |
my $old_func = \&{$symbol}; | |
*{$symbol} = sub { | |
my @params = @_; | |
subtest $test_description => sub { | |
$old_func->( @params ); | |
}; | |
}; | |
# tell Test::Class to run as a single test | |
Test::Class::Test($class, $symbol, $code_ref, $attr, $args); | |
}; | |
1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
package Z::Test; | |
use parent 'Test::Class::TestGroup'; | |
use Test::More; | |
sub overrides_basic : TestGroup(basic overrides work) { | |
ok( 1, "works" ); ok( 1, "works" ); | |
} | |
sub overrides_no_profile : TestGroup(overrides without profile work) { | |
ok( 2, "works" ); ok( 2, "works" ); | |
} | |
__PACKAGE__->runtests; | |
1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1..2 | |
ok 1 - works | |
ok 2 - works | |
1..2 | |
ok 1 - basic overrides work | |
ok 1 - works | |
ok 2 - works | |
1..2 | |
ok 2 - overrides without profile work |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment