On Thursday 19 June 2003 15:15, Enrico Sorcinelli wrote:
> Why not to hack into Test::More in order to improve it and fix its bugs?
> Test::More is often used and I think that your patches will be welcome!

I did, my patches were accepted by Michael Schwern months ago but he hasn't 
released a new version, I think he's pretty busy at the moment.

Anyway, Test::Deep does huge amounts more than Test::More.

Simple usage is much like is_deeply():
cmp_deeply($hash, { a=> [1, 2, 3], b => \'hello'});

More advanced features:
cmp_deeply($set, set(1, 2, 3, 4));

will make sure that $set is an array ref which is setwise equal to (1, 2, 3, 
4) so any of the following would be ok: [1, 2, 3, 4] or [4, 2, 3, 1] or [4, 
4, 3, 2, 4, 2, 1, 3, 2, 1]

cmp_deepy($hash,
        {
                set1 => set(1, 2, 3, 4),
                set2 => set(5, 6, 7, 8),
        }
);

makes sure that $hash has 2 keys and that
$hash->{"set1"} is setwise equal to (1, 2, 3, 4) and
$hash->{"set2"} is setwise equal to (5..8)

cmp_deepy($set_of_sets, set(
        set(1..5),
        set(6..10),
);

give an OK for [[1..5], [6..10]] or [[10..6], [5..1]] and it would also pass 
[[1..5, 2, 3, 2,4, ,5],[6..10, 7, 6, 8,], [5..1]].

cmp_deeply($bag_of_objects,
        bag(
                methods(getName => "a"),
                methods(getName => "b"),
                methods(getName => "c"),
                methods(getName => "d"),
                re(qr/banana/),
        )
)

would make sure that $bag_of_objects is an array ref with 5 items, 1 of which 
is a string containing the word "banana" and the other 4 are objects and 
these objects return "a", "b", "c", "d" when the getName method is called. 
The order in which these elements occur is ignored.

cmp_deeply($father,
        methods(
                getName => re(qr/^\w+\s+\w+$/),
                getChildren => all(isa("Animal::Human")),
                getPets => all(isa("Animal")
        )
);

is the same as testing

$father->getName =~ /^\w+\s+\w+$/;

and

foreach my $child (@{$father->getChildren})
{
        $child->isa("Animal::Human");
}

except it's using a declarative syntax which (hopefully) makes it's easier to 
understand and maintain. It will also give sensible error reports and unlike 
the code above will not explode if $father->getChildren->[5] is not actually 
a blessed reference, instead it will just tell you about it in the test 
diagnostics.

So it's not something that can be hacked into Test::More,

F

Reply via email to