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

evals in t/op/append.t

Thread Next
From:
David Landgren
Date:
April 28, 2006 04:52
Subject:
evals in t/op/append.t
Message ID:
445201C7.1050005@landgren.net
In t/op/append.t, given the preamble:

     my $a   = "a";
     my $ab  = "a\0b";
     my $ua  = pack("U0a*", $a);
     my $uab = pack("U0a*", $ab);
     my $ub  = pack("U0a*", 'b');

some tests employ eval:

     my $t4 = $ua; $t4 .= $uab;
     print eval '$t4 =~ /$ub/' ? "ok 9\n" : "not ok 9\t# $t4\n";

and some don't:

     my $t3 = $ua; $t3 .= $ab;
     print $t3 =~ /$ub/ ? "ok 8\n" : "not ok 8\t# $t3\n";

I have a feeling that this is to test that an embedded \0 in a string in 
an eval doesn't truncate. Is that correct? All other things being equal, 
it would make just as much sense to eval the thing tested, not the test 
itself, hence:

     my $t4 = $ua; eval '$t4 .= $uab';
     print $t4 =~ /$ub/ ? "ok 9\n" : "not ok 9\t# $t4\n";

I don't like the way the tests are just happy to find the source in the 
target, anywhere, anytime. I think it would be better to nail down the 
results precisely:

   cmp_ok($t3,'eq',"aa\0b",'concat gives aa\\0b');

Or does this mean that I'm not testing the thing that is supposed to be 
tested....

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


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