Subject: | Test::Deep dies |
Date: | Tue, 17 Feb 2009 13:35:56 -0800 |
To: | bug-test-deep [...] rt.cpan.org |
From: | Clayton Magouyrk <clayton.magouyrk [...] gmail.com> |
First I want to say thank you for this great module - it's a very useful
pattern matching tool.
I was performing some unit tests and I ran across what I consider to be a
bug:
$ perl -e 'use Test::Deep; cmp_deeply("string", array_each("string"));'
Can't use string ("string") as an ARRAY ref while "strict refs" in use at
/imdb/tools/2.65/lib/perl5/5.8.8/Test/Deep/ArrayEach.pm line 22.
# Looks like your test died before it could output anything.
This seems to be contrary to what the documentation says:
my $common_tests = all(
isa("MyFile"),
methods(
handle => isa("IO::Handle")
filename => re("^/home/ted/tmp"),
)
);
cmp_deeply($got, array_each($common_tests));
is similar to
foreach my $got_v (@$got) {
cmp_deeply($got_v, $common_tests)
}
Except it will not explode is $got is not an array reference.
Looks like the issue could be resolved by something as simple as:
my $exp = [ ($self->{val}) x (reftype($got) eq 'ARRAY' ? @$got : 1)
];
Which would just shove the validation down a level, where it would fail
(just a guess - there may be other assumed preconditions later on that are
violated).
Thanks,
Clay Magouyrk