Hi,
I've just uploaded Test::Deep 0.02 to CPAN. This module is a very souped up
version of the is_deeply() test from Test::More. If you don't include an
special comparison instructions, it behaves exactly like is_deeply() except
it handles circular data structures and it compares the class of bless
references.
By including special comparisons, it gives you control of the comparison
process at every level of the structures you are comparing by letting you
insert special comparisons wherever you want. Special comparisons include
checking the results of method calls, treating an array like a set or a bag,
forcing numerical comparisons, forcing shallow comparisons of refs, regexp
comparisons, applying multiple tests to the same piece of the structure etc.
One interesting new thing that this can be used for is exporting tests for
reuse by other modules. A very simple example is IO::Handle, it could define
a test
$open_handle = all( isa("IO::Handle"), methods(opened => 1) );
then
cmp_deeply($fh, $open_handle);
would check $fh->isa("IO::Handle") and $fh->opened == 1. More usefully, you
can now use this test as part of another test, so that
cmp_deeply(
$got,
array_each(
methods(
FileHandle => $open_handle,
FileName => re("^/tmp/"),
Members => bag(1, 2, 3, 4),
)
)
);
This will make sure that each element of @$got is an object who's FileHandle
method returns an open file handle, who's FileName method returns a string
starting with "/tmp/" and who's Members method returns an array containing 4
elemets: 1, 2, 3 and 4 in any order.
This is a quite trivial example but it illustrates the idea of how big tests
can be built up from smaller ones and could include tests defined outside of
the module's own test suite,
F
--
Do you need someone with lots of Unix sysadmin and/or lots of OO software
development experience? Go on, giz a job.
My CV - http://www.fergaldaly.com/cv.html