On 20/07/06, chromatic <[EMAIL PROTECTED]> wrote:
On Wednesday 19 July 2006 10:35, Fergal Daly wrote:
> A correctly documented bad user experience is still a bad user
> experience. What possible justification is there for not being able to
> easily use subroutines in test scripts?
Who broke your fingers? You can use subroutines in test scripts. If you
write them badly, you get bad results -- the same as subroutines in any other
programs and in any other language.
Simple question. Given this code:
sub foo {
my $thing;
is($thing->x(), "x"); # line 4
is($thing->y(), "y");
}
$t1 = Thing->new(1);
foo($t1); # line 9
$t2 = Thing->new(2);
foo($t2);
lets say the first is() is going to fail for $t1. What's the correct
line number to print? If we print line 9 then we don't know which is()
failed. If we print line 4 then we don't know which Thing failed.
There is no right line to print, the only right thing to print is a stack trace.
Or maybe my subroutine is broken but I don't see how.
If you don't want to get bad results, use the $Level variable or use the
attribute solution Aristotle posted.
> It's already done! Test::Builder already knows how to find where the
> user script jumps into Test::XXX land. All I'm saying is that instead
> of just outputting that 1 frame, output all the frame from there on up
> (in this case 2). Neither magic nor rocket science.
Do you *really* want to force everyone, everywhere to name their test modules
Test::*, name none of their Test::Class-based tests anything starting with
Test::, and wade through call stack output on every failure?
What on earth are you talking about? This is *NOT* how Test::Builder
figures out the line number for the diagnostics.
Please go and read the code.
Enforcing some sort of naming scheme for a heuristic to work seems like a
mistake to me.
> I'm not proposing elminating the local $blah stuff from Test::XXX
> modules, just making it possible for users to get sensible messages
> even if they use subroutines in their test scripts.
I much prefer Aristotle's solution. Stack traces are scary. They're not
common in Perl code I come across.
Aristotle's solution doesn't make any difference to whether stack
traces are required. All it does is eliminate the need for boiler
plate code.
> See above for why there is no dozen lines,
Again, that depends on how far you push the heuristic.
Again, read the code, there is no "heuristic",
F