The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::DataDriven - when Test::Base is not enough

SYNOPSIS

In the test module:

    # t/lib/MyTest.pm
    package MyTest;

    use Test::DataDriven::Plugin -base;
    __PACKAGE__->register;

    my $time;
    my $result;

    sub check_before : Begin(add1) {
        my( $block, $section_name, @data ) = @_;
        $time = time();
    }

    sub do_that : Run(add1) {
        my( $block, $section_name, @data ) = @_;
        $result = add_1( $data[0] );
    }

    sub check_after : End(result) {
        my( $block, $section_name, @data ) = @_;
        is( $result, $data[0] );
        ok( time() - $time < 1 ); # check side effects
    }

In the test file:

   use MyTest;
   use Test::More tests => 4;

   Test::DataDriven->run;

   __END__

   === Test 1
   --- add1 chomp
   3
   --- result
   4

   === Test 1
   --- add1 chomp
   7
   --- result
   8

DESCRIPTION

Test::Base is great for writing data driven tests, but sometimes you need to test things that cannot be easily expressed using the filter-and-compare-output approach.

Test::DataDriven builds upon Test::Base adding the ability to declare actions to be run for each section of each test block. In particular, the processing of each block is divided in three phases: "begin", "run" and "end". The "begin" phase can be used to assess or establish the preconditions for the test. The "run" phase is used to perform some actions. The "end" phase can be used to check the side effects of the "run" phase.

METHODS

register

    Test::DataDriven->register
      ( plugin   => $plugin,
        tag      => 'section_name',
        );

    Test::DataDriven->register
      ( plugin   => $plugin,
        tag_re   => qr/match/,
        );

Registers a plugin whose begin, run and end methods will be called for each section whose name equals the one specified with 'tag' or matches the regular expression specified with 'tag_re'. At least one of 'tag' or 'tag_re' must be present.

$plugin can be either a class or object reference.

run

    Test::DataDriven->run;

Iterates over the Test::Base blocks calling the plugins that match the block sections.

stop_run

    Test::DataDriven->stop_run;

Stop the tests being run.

BUGS

Needs more documentation and examples.

AUTHOR

Mattia Barbon <mbarbon@cpan.org>

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.