httpd-test-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <>
Subject Re: switching t_cmp() argument order
Date Wed, 09 Jun 2004 15:35:28 GMT
Geoffrey Young wrote:
>>but the tests need to be adjusted to swap the args, no?
> only the regex ones, and only before the deprecation period ends.
> outside of the regex case, where the comparison order is important, the
> syllogism principle applies.

nice, learned a new term here :)

>>That won't work with readonly args:
>>% perl -le 'a("A", "b"); sub a {($_[0], $_[1]) = ($_[1], $_[0]);}'
>>Modification of a read-only value attempted at -e line 1.
> yeah, ok.  but I don't think this is very common:
>   t_cmp("a", qr/a/);
> which would be the only case where the argument swapping would occur _and_
> that would cause a problem.
> so, I can change the patch to use temporary assignments of $@ arguments and
> avoid the problem, or we can agree that comparing a regex to a constant is
> probably never going to happen, or at least it's not a problem if it does,
> since it would force people to recode since they need to anyway.

But it's quite possible that argument could be readonly while not a string, a 
simple example is a return value of a function:

% perl -le 'a(b(), "b"); sub a {($_[0], $_[1]) = ($_[1], $_[0]);}; \
             sub b { 5 }'
Modification of a read-only value attempted at -e line 1.

>>>+    return t_is_equal($_[1], $_[0]);
>>why the swap of the t_is_equal args?
> because the regex needs to occur first in t_is_equal().  the new t_cmp()
> expects the regex second (in $expected) so the order needs to be swapped to
> make t_cmp() actually work, since t_is_equal() wants the regex first.  I
> could have changed t_is_equal() instead, but I didn't see the need to play
> with two functions when simply changing t_cmp() to match is() (where the
> functionality is essentially the same) was the issue.

I'd rather see t_is_equal and t_cmp have identical API, if it's not too much 
of a trouble to you.

btw, you don't need to craft \n in t_debug:

+        my $warning = "WARNING!!! t_cmp() argument order has changed.\n" .
+                      "use of a regular expression as the first argument\n" .
+                      "is deprecated.  support will be removed soon.";
+        t_debug($warning);

just pass an array and it'll add them for you:

t_debug("foo", "bar", "tar");

Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker     mod_perl Guide --->

View raw message