develooper Front page | perl.perl5.porters | Postings from April 2006

Re: [PATCH] t/op/pat.t using

Thread Previous | Thread Next
David Landgren
April 27, 2006 07:06
Re: [PATCH] t/op/pat.t using
Message ID:
Jim Cromie wrote:
> David Landgren wrote:
>> In a further iteration I'd like to break out all the
>>   ok(/(expr)/ && $1 eq 'foo', 'my test')
>> tests into
>>   ok(/(expr)/, 'my test match');
>>   cmp_ok($1, 'eq', 'foo', 'my test result');
> does it matter that $1 is only set on a match (IIRC), and that an old value
> could accidentally match the expected  ?  ('foo' being as common as it is)
> I imagine the tests avoided that potential..

You are quite right, they do, so some defensive coding would be required.

perl -le '$_="ab";/(a)(b)/; print "X$1$2"; /(c)/; print "Y$1$2"'

perl -le '$_="ab";/(a)(b)/; print "X$1$2"; undef=~/()/; /(c)/; print 

Or through local

perl -le '$_="ab";{local $1,$2;/(a)(b)/; print "X$1$2"} {local $1,$2; 
/(c)/; print "Y$1$2"}'

Unless there's a better way to reset the capture variables, especially 
in the context of "what are we really trying to test here?".

Perhaps the idea is unwise. It started out with the notion that if a 
combo-test fails you have to figure out which part of the test failed. 
It could be that the match succeeded, but the result was wrong, or that 
the match failed. With two tests, you would know that immediately.

> <insane>
>    is there a string equivalent to NaN, that doent match any string, inc 
> (another copy of) itself ?
> </>

I think that would require tied magic, thus more trouble than it's worth?

"It's overkill of course, but you can never have too much overkill."

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About