Test::Kit

Ovid on 2008-08-14T11:24:16

Doing more work with Test::Kit and now you can do this:

package My::Tests;

use Test::Kit
  'Test::More' => {
    exclude => 'is_deeply', # force use of eq_or_diff
  },
  'Test::Differences' => {
    rename => {
      eq_or_diff => 'is_deeply',
    },
  },
  'Test::Exception',
  '+explain',
  '+on_fail';

sub BUILD {    
    # completely optional
    # only needed if you want to extend with your own behavior
    my ( $class, @args ) = @_;
    # your own custom extensions, and return @args or a new
    # import list
    return @your_new_import_list;
}

And in your code:

use My::Tests 'no_plan';
on_fail {
    my $test = shift;
    if ( $test->name =~ /critical/i ) {
        my $message = sprintf "Test %s failed at %s line %d package %s" =>
          $test->name,
          $test->file,
          $test->line,
          $test->package;
        email_admin($message);
    }
};

is_deeply $foo, $bar, 'Uses eq_or_diff internally';
explain $baz;  # if it's a reference, uses Data::Dumper
throws_ok { some_func() }
  qr/some message/, 'some_func() is hateful';

So now you can set your own callbacks for test failures and do anything you really need. You can mix and match your own test modules. You can automatically dump references with explain. You can easily extend it. You can choose which test functions you do or do not want or rename them. Conflicting test functions fail at compile time. Yada, yada, yada.


Looks good

grink on 2008-08-14T16:36:33

This looks very cool... can't wait for a release

Not had a chance to play with this yet...

Adrian on 2008-08-17T18:39:07

.... but it looks bloody useful.

Ob: wish-i-was-coding