Hi, I recently fell in love with Test::Base and I decided to use it at $work. Since the 'run filter, compare output' mode of T::B did not fit my needs, I wrote a small wrapper (Test::XXX for now...) that enables to check/establish preconditions, run one or more actions and check postconditions, for each block, depending on the sections that are present. I think this might be useful to others and I wanted to release it to CPAN, but I am stuck with finding it a proper name for it, and I also wonder if I chose the right interface.
The module iterates over the Test::Base blocks. The processing of each block is divided in three phases (begin, run, end). In each phase one or more subroutines is run for every section of the block. The (phase, section) -> subroutine association is declared in the testing module. Since the description above is a bit vague, I am pasting below an example test module based upon Test::XXX and a couple of example tests for a 'Dummy' module providing touch, mkdir, rmdir and ls functions. In the example the touch and mkpath sections execute actions, directory declared the directory whose contents I want to test and the created section (associated to sub post_created()) is the "real" test i.e. it tests the results of the executed actions. Thanks in advance for any suggestions! Regards Mattia # t/lib/DummyT.pm package DummyT; use Test::XXX::Plugin -base; use Test::Differences; use Dummy; use File::Path; __PACKAGE__->register( 'Test::XXX' ); sub run_mkpath : Run(mkpath) { my( $block, $section, @v ) = @_; Dummy::mkpath( @v ); } sub run_touch : Run(touch) { my( $block, $section, @v ) = @_; Dummy::touch( @v ); } my @orig; my $directory; sub pre_directory : Begin(directory) { my( $block, $section, @v ) = @_; $directory = $v[0]; } sub pre_created : Begin(created) { my( $block, $section, @v ) = @_; @orig = Dummy::ls( $directory . '/*' ); } sub _lsd { my( $block, $section, @v ) = @_; my %final = map { ( $_ => 1 ) } Dummy::ls( $directory . '/*' ); delete $final{$_} foreach @orig; my @final = map { s{^$directory/}//; $_ } keys %final; } sub post_created : End(created) { my( $block, $section, @v ) = @_; my @final = _lsd( @_ ); eq_or_diff( [EMAIL PROTECTED], [EMAIL PROTECTED], test_name ); } 1; # t/foo.t use DummyT; use Test::XXX tests => 1; Test::XXX->run; __DATA__ === Run some actions (1) --- touch lines chomp t/dummy/file1 === Run more actions (2) --- directory chomp t/dummy --- touch lines chomp t/dummy/file2 --- mkpath lines chomp t/dummy/dir --- created lines chomp file2 dir/