perl-Test-Deep/perl-Test-Deep-0.103-arrayeach.patch

69 lines
2.0 KiB
Diff

Fix comparison against stuff other than ARRAY references with array_each().
Patch by Tomas Heran <tomas.heran@gooddata.com>,
Test by Lubomir Rintel <lubo.rintel@gooddata.com>
Submitted upstream by mail on 2008-10-22.
diff -up Test-Deep-0.103/lib/Test/Deep/ArrayEach.pm.arrayeach Test-Deep-0.103/lib/Test/Deep/ArrayEach.pm
--- Test-Deep-0.103/lib/Test/Deep/ArrayEach.pm.arrayeach 2005-11-30 15:09:02.000000000 +0100
+++ Test-Deep-0.103/lib/Test/Deep/ArrayEach.pm 2008-10-22 18:40:22.000000000 +0200
@@ -3,7 +3,7 @@ use warnings;
package Test::Deep::ArrayEach;
-use Test::Deep::Cmp;
+use Test::Deep::Ref;
sub init
{
@@ -19,6 +19,8 @@ sub descend
my $self = shift;
my $got = shift;
+ return 0 unless $self->test_reftype($got, "ARRAY");
+
my $exp = [ ($self->{val}) x @$got ];
return Test::Deep::descend($got, $exp);
diff -up Test-Deep-0.103/lib/Test/Deep/ArrayElementsOnly.pm.arrayeach Test-Deep-0.103/lib/Test/Deep/ArrayElementsOnly.pm
--- Test-Deep-0.103/lib/Test/Deep/ArrayElementsOnly.pm.arrayeach 2005-11-30 15:09:21.000000000 +0100
+++ Test-Deep-0.103/lib/Test/Deep/ArrayElementsOnly.pm 2008-10-22 18:40:22.000000000 +0200
@@ -22,6 +22,8 @@ sub descend
my $exp = $self->{val};
my $data = $self->data;
+
+ return 0 unless $self->test_reftype($got, "ARRAY");
for my $i (0..$#{$exp})
{
@@ -41,7 +43,9 @@ sub render_stack
my $self = shift;
my ($var, $data) = @_;
$var .= "->" unless $Test::Deep::Stack->incArrow;
- $var .= "[$data->{index}]";
+ if (exists($data->{index})) {
+ $var .= "[$data->{index}]";
+ }
return $var;
}
diff -up Test-Deep-0.103/t/array_each.t.arrayeach Test-Deep-0.103/t/array_each.t
--- Test-Deep-0.103/t/array_each.t.arrayeach 2005-11-30 15:08:22.000000000 +0100
+++ Test-Deep-0.103/t/array_each.t 2008-10-22 18:40:22.000000000 +0200
@@ -30,4 +30,14 @@ EOM
},
"array_each not eq"
);
+
+ check_test(
+ sub {
+ cmp_deeply({}, array_each( ignore() ));
+ },
+ {
+ actual_ok => 0,
+ },
+ "array_each not ARRAY reference"
+ );
}