My New Custom Test::More

Ovid on 2007-03-08T11:08:01

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 blame you

jk2addict on 2007-03-08T14:03:51

for getting me started on doing this. :-)

[repeated from the qa list]

I think it was you or someone else who got me started on this in Handel
and my other DBIC based dists where I needed both Test::More and custom
sqlite t/var initializer junk:

http://search.cpan.org/src/CLACO/DBIx-Class-InflateColumn-Currency-0.01/t/lib/DB IC/Test.pm

Yup, in fact, you're still in the comments... :-)

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/);
};
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:

use Test::More;
use MyDBICClass;
 
MyDBICClass->init_schema
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 each .t file.

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. ;-)

re: re-exporting example

markjugg on 2007-03-08T16:18:16

@EXPORT = (
    @Test::More::EXPORT,
    @Test::Differences::EXPORT,
    @Test::Exception::EXPORT,
);
I've wanted a re-exporting solution before, but had never seen or thought of something this simple and clear. Thanks for sharing that!

 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.