On Sep 24, 2006, at 12:41 PM, Christopher H. Laco wrote:
I've got a crap loads of tests in Handel at the moment; 10000+
checkpoints, and enough files that I hit the dreaded "command line too
long" under win32 [now fixed]. That's not saying all the tests are
glorious and not repetitive. :-)
I've still got a ways to go before I'm happy without the dist
enough to
declare the 1.0 version done. Among things on my list are cleaning up
the current test code. A big offender is that not all of my tests have
labels.
I could've swore that sometime in the last month I saw some chatter
about a Test::TestDescriptions module, or a ::TestsHaveDescriptions
type
thing for Perl::Critic. Assuming I'm not just making that up, has
anyone
seen mention of such a thing?
If no such a beast exists thus far, what would be the easiest way
to get
such functionality? I was thinking that I could just run a subclass of
Test::More in my tests that dies whenever no label argument is
supplied.
That's not a terrible thing since I already have a Handel::Test module
that deals with SQLite setup and teardown in most tests.
Done. I created Perl::Critic::Policy::Testing::RequireTestLabels and
added it to the Perl::Critic SVN at
http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic
(username: "guest", password: "")
It was pretty simple to write. Below are the important bits of the
code. I encourage others to write Test::More-specific policies for
Perl::Critic!
Chris
==========================================================
my %label_arg_pos = (
ok => 1,
is => 2,
isnt => 2,
like => 2,
unlike => 2,
cmp_ok => 3,
is_deeply => 2,
pass => 0,
fail => 0,
);
sub default_severity { return $SEVERITY_MEDIUM }
sub applies_to { return 'PPI::Token::Word' }
sub violates {
my ($self, $elem, $doc) = @_;
my $arg_index = $label_arg_pos{$elem};
return if !defined $arg_index; # this is the fastest
conditional, so do it first
return if !is_function_call($elem);
return if !_has_test_more($doc);
# Does the function call have enough arguments?
my @args = parse_arg_list($elem);
return if ( @args > $arg_index );
return $self->violation( $desc, $expl, $elem );
}
sub _has_test_more {
my ( $doc ) = @_;
my $includes = $doc->find('PPI::Statement::Include');
return if !$includes;
return any { $_->module() eq 'Test::More' } @{ $includes };
}
==========================================================
--
Chris Dolan, Software Developer, Clotho Advanced Media Inc.
608-294-7900, fax 294-7025, 1435 E Main St, Madison WI 53703
vCard: http://www.chrisdolan.net/ChrisDolan.vcf
Clotho Advanced Media, Inc. - Creators of MediaLandscape Software
(http://www.media-landscape.com/) and partners in the revolutionary
Croquet project (http://www.opencroquet.org/)