Subject: | comparator junctions modify operands |
Date: | Wed, 14 Nov 2012 14:42:52 +0000 |
To: | bug-Test-Deep [...] rt.cpan.org |
From: | Zefram <zefram [...] fysh.org> |
perl -lwe 'use Test::More; use Test::Deep; my $comparator = re(qr/a/) & re(qr/b/); cmp_deeply "ab", $comparator; cmp_deeply "abc", $comparator & re(qr/c/); cmp_deeply "ab", $comparator; done_testing()'
ok 1
ok 2
not ok 3
# Failed test at -e line 1.
# Using Regexp on (Part 3 of 3 in $data)
# got : 'ab'
# expect : (?-xism:c)
1..3
# Looks like you failed 1 test of 3.
The "&" operation in which $comparator is an operand has the
side effect of modifying $comparator, permanently incorporating
the re(qr/c/) test into it. This breaks subsequent use of
$comparator.
This can be trivially solved by removing most of the
logic from Test::Deep::Cmp::make_{all,any}, along with
the overloads on Test::Deep::{All,Any}. In fact, once the
special-effort-to-damage-an-operand logic is removed, there's nothing
distinctive to those functions left, and the overload declaration may
as well refer directly to Test::Deep::{all,any}. (Incidentally, the
overload on Test::Deep::Any overloads "&" rather than the correct "|".)
-zefram