Test::Class Tags
A few folks have talked about adding tags to Test::Class. This would allow us to do things like load 'customer' fixtures if something is tagged 'customer', or only run tests tagged 'model'.
Here's what I have working now:
#!/usr/bin/env perl
use Modern::Perl;
{
package Foo;
use Test::Class::Most;
INIT { Test::Class->runtests }
sub setup : Tests(setup => 2) {
my $test = shift;
ok $test->has_tag('customer'), 'We have a customer tag';
ok !$test->has_tag('foobar'), 'We do not have a foobar tag';
}
sub foo : Tests Tags(customer items) {
my $test = shift;
ok $test->has_tag('customer'), 'We have a customer tag';
ok !$test->has_tag('foobar'), 'We do not have a foobar tag';
}
}
(Note: you don't really want tests in setup, but this is just an example)
Internally it's a bit hackish (due to attribute order and the fact that attribute arguments aren't Perl), but it works. Does this look like a reasonable implementation?
It's not clear to me if overridden tests should inherit parent tags or replace them. The latter is easy (that's what I have now). The former involves walking up the inheritance tree. Implementing both involves figuring out a clean syntax and this is what stumps me (and it would get nasty with MI).
Update: We have a solution. You can both replace and add tags. Tags(...) is a simple assertion of the tags for a method. AddTags(...) checks that we have a parent (unless it's test class) and the parent can do the method we're in. We add the tags to the parent tags (if any).
The only failure case I see here is if the parent had tags you depend on and someone comes in later and deletes them. Hopefully, they should be running the tests and see this.
Arse - I already have a patch in my queue for this from somebody else!
Okay.... getting T::C on github will be sorted this week. Then we can compare & contrast.
@Adrian: A couple of folks told me they were going to work on it, but I wasn't sure if any action was being taken and I didn't notice anything in RT. Github will be awesome :)