I've finally gotten around to customizing my Test::More a bit more:
package My::Test::More; use Test::Builder::Module; @ISA = qw(Test::Builder::Module); use Test::More; use Test::Differences; use Test::Exception; INIT { unless ( exists $INC{'Test/Class.pm'} ) { # NoWarnings doesn't play well with Test::Class eval "use Test::NoWarnings"; } } @EXPORT = ( @Test::More::EXPORT, @Test::Differences::EXPORT, @Test::Exception::EXPORT, ); $ENV{RUNNING_TESTS} = 1; 1;
I use Test::Differences and Test::Exception constantly and I was getting tired of "use"ing them in every test program, so now I don't have to. Using this means you automatically get an extra test from Test::NoWarnings, but now you can't forget to have it :)
I should write some code to avoid function name conflicts in @EXPORT. Maybe even to rename or exclude them. Think 'traits' for functions :)
I've even been mulling over the idea of making some official sort of module for DBIC testing. If you look ad most of the DBIC based dists like DBIC, Handel, Mango, InflateColumn::Currency, UUIDColumns, etc, they all follow the basic pattern:package DBIC::Test;
use strict;
use warnings;
BEGIN {
# little trick by Ovid to pretend to subclass+exporter Test::More
use base qw/Test::Builder::Module Class::Accessor::Grouped/;
use Test::More;
use File::Spec::Functions qw/catfile catdir/;
@DBIC::Test::EXPORT = @Test::More::EXPORT;
__PACKAGE__->mk_group_accessors('inherited', qw/db_dir db_file/);
};
where init_schema creates/cleans t/var, inits a fresh sqlite db based on some schema, and populates test data before running the tests in eachuse Test::More;
use MyDBICClass;
MyDBICClass->init_schema
Re:I blame you
Ovid on 2007-03-08T14:27:29
You know, up until this post, I never realized that you and Chris Laco were one and the same. How the hell did I miss that?
:) Re:I blame you
jk2addict on 2007-03-08T14:49:42
Ha ha. Is that a good thing, or a bad thing?:-) Re:I blame you
Ovid on 2007-03-08T15:32:57
You know, either way I answer that could get interpreted negatively, so let me just say that I have the utmost respect for both of you
;) Re:I blame you
jk2addict on 2007-03-08T15:36:33
Respect? You must be confusing me with someone else.;-)
I've wanted a re-exporting solution before, but had never seen or thought of something this simple and clear. Thanks for sharing that!@EXPORT = (
@Test::More::EXPORT,
@Test::Differences::EXPORT,
@Test::Exception::EXPORT,
);
Mark
Re: re-exporting example
jk2addict on 2007-03-08T20:40:17
I love moments like that. You get so knee deep in perl, oop, orms, forms, code and such. Then along comes a few lines of dead obvious code and the light bulb goes on.