Skip to content

Instantly share code, notes, and snippets.

@wchristian
Created August 16, 2010 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wchristian/527670 to your computer and use it in GitHub Desktop.
Save wchristian/527670 to your computer and use it in GitHub Desktop.
a subclass of Test::Class that adds a TestGroup attribute
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;
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;
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