On Thursday 19 June 2003 15:24, Andy Lester wrote:
> It would be nice if the functions ended in _ok, so it's clear that
> they are actually outputting and not just returning booleans.
There is only 1 function really, all the rest are shortcuts to the
constructors of various plugins. I suppose I could call it cmp_deeply_ok. Not
sure if I like that too much though.
> I think that Test::Data might be a better place for them, somehow.
> I'm maintaining brian d foy's Test::Data:: hierarchy, so maybe we can
> figure something out.
Test::Data takes a totally different approach. With Test::Data::Hash you'd do
something like
hash_value_false_ok("key1", $hash);
hash_value_true_ok("key2", $hash);
hash_value_false_ok("key3", $hash);
hash_value_true_ok("key4", $hash);
with Test::Deep you'd do
cmp_deeply($hash,
{
key1 => bool(0),
key2 => bool(1),
key3 => bool(0),
key4 => bool(1),
}
);
You build a structure that looks like the result you're expecting except
sometimes instead of simple values you have special comparators which .
You can also do this
my $is_person = all(
isa("Person"),
methods(
getName => re(qr/^\w+\s+\w+$/),
getMaritalStatus => any("single", "married"),
),
);
my $is_company = all(
isa("Company"),
methods(
getName => re(qr/\w/),
getCEO => $is_person,
getDirectors => all($is_person),
),
);
cmp_deeply([EMAIL PROTECTED], all($is_company));
You can also make your definitions available to other modules so that when
they run their tests they can check that they are getting good values back
from you. It'd be nice to put this in the test code for my fictitious log
handler,
use IO::File::Test qw( $opened_fh );
my $log_handler = Log->new("$test_file");
cmp_deeply($log_handler,
methods(
getFileName => $test_file,
getEntriesCount => 0,
getFH => $opened_fh,
)
);
and that'll make sure that my file was opened correctly along with various
other relevant tests,
F