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

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

Thread Previous | Thread Next
From:
Jim Cromie
Date:
April 27, 2006 09:16
Subject:
Re: [PATCH] t/op/pat.t using test.pl
Message ID:
4450EE64.8020202@gmail.com
David Landgren wrote:
> 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"'
> Xab
> Yab
>
> perl -le '$_="ab";/(a)(b)/; print "X$1$2"; undef=~/()/; /(c)/; print 
> "Y$1$2"'
> Xab
> Y
>
> Or through local
>
> perl -le '$_="ab";{local $1,$2;/(a)(b)/; print "X$1$2"} {local $1,$2; 
> /(c)/; print "Y$1$2"}'
> Xab
> Y
>
> 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.
>
I think the separate tests is fine / clear / better
2 of 4 cases shouldnt happen, but might, and when they do, it tells you 
something just by reading.

You might consider your own Ok(), starting with Yves' or Ron's snippets,
which wraps 2 checks into 1 call.

<aside>  does like() reset $1 etal ? </>

>> <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?

indeed.  unless it were already there, which it isnt, or somebody would 
have pointed at it.

>
> David


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About