Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

petdance (2468)

petdance
  andy@petdance.com
http://www.perlbuzz.com/
AOL IM: petdance (Add Buddy, Send Message)
Yahoo! ID: petdance (Add User, Send Message)
Jabber: petdance@gmail.com

I'm Andy Lester, and I like to test stuff. I also write for the Perl Journal, and do tech edits on books. Sometimes I write code, too.

Journal of petdance (2468)

Thursday August 08, 2002
11:00 AM

Making sure your modules all have their proper tests

[ #6980 ]
All of my modules are works in progress. I'm always adding new features, especially to HTML::Lint, so I want to make sure I always have valid test cases for those new features. I try to follow the principle of "write the test case first", but in case I don't, or I forget to update the MANIFEST, I've created the following test files.

For HTML::Lint, in the t/01.coverage.t file:

use Test::More 'no_plan';

use_ok( 'HTML::Lint::Error' );

my @errors = keys %HTML::Lint::Error::errors;
isnt( scalar @errors, 0, 'There are at least some errors to be found.' );

for my $error ( @errors ) {
    my $filename = "t/$error.t";
    ok( -e $filename, "$filename exists" );
}

and in the new Carp::Assert::More, in the t/02.coverage.t:

use Test::More 'no_plan';

use_ok( 'Carp::Assert::More' );

my @funcs = ( @Carp::Assert::More::EXPORT, @Carp::Assert::More::EXPORT_OK );

my %deduped;
$deduped{$_}++ for @funcs;
@funcs = sort keys %deduped;

isnt( scalar @funcs, 0, 'There are no function names!' );

for my $func ( @funcs ) {
    my $filename = "t/$func.t";
    ok( -e $filename, "$filename exists" );
}

In each case, the code tracks the features (possible error messages in HTML::Lint, or function names in Carp::Assert::More) and makes sure that there's an appropriate .t file that corresponds.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I like it! (Score:2, Interesting)

    This is an excellent idea. While most of the modules I'm writing these days do not use Exporter, I'm sure I could figure out a similar method you described. Perhaps you could grep through the package namespace looking for subroutine globs?
    --
    "Perl users are the Greatful Dead fans of computer science." --slashdot comment