Nicholas Clark wrote:
> Any well written ok function can use (caller)[2] to report 
> the line number. IIRC Test::More uses Test::Simple::ok, which
> in turn is Test::Builder::ok which does.

Which is of limited utility if your test goes something like this:

    BEGIN { use_ok 'Some::Module', 'foo'; }
    # foo is a sub which returns an arrayref with six elements

    sub form_ok {
        my($name, $should, $is) = @_;

        is($should->[0], $is->[0], "Fritz of $name");
        is($should->[1], $is->[1], "Flurble of $name");
        is($should->[2], $is->[2], "average glumpf of $name");
        is($should->[3], $is->[3], "maximum glumpf of $name");
        is($should->[4], $is->[4], "minimum glumpf of $name");
        is($should->[5], $is->[5], "Schlurp of $name");
    }

    form_ok('zark', foo('zark'), [ 1, 27, -4, 6.4, -200, 'bork' ]);
    form_ok('buz',  foo('buz' ), [ 28, -1, 0, 200, -3.14159, 'ulp' ]);
    :
    :
    form_ok('plug', foo('plug'), [ 3, 3, 5, 6, 2, 'knork' ]);

(all names changed to protect the innocent), in which case the test will
report "error at line x", where x lies inside form_ok(), rather than
reporting line y, which is where form_ok('buz', ...) is called.

Fortunately, the fact that the error message contains "Schlurp of buz: got
'yulp', expected 'ulp'" helps a but. But it would have been even more
helpful if the caller() in Test::More had gone up one more level.

And the subroutine form_ok, I felt, was necessary since I did *not* want to
type six 'is(...)' calls for each line. Especially not when I'm testing
twenty inputs to foo() and each has not six but eight or twelve outputs.

"Patches Welcome", I suppose. Oh well.

Or has anyone any better suggestions? Or does Test::More perhaps already
support this by setting some variable, perhaps?

Cheers,
Philip

(The problem actually came from one of my Lingua::Zompist::* modules;
probably Lingua::Zompist::Verdurian, but I don't remember exactly as
L::Z::Cadhinor uses a very similar testing scheme and the error may have
struck me there.)
-- 
Philip Newton <[EMAIL PROTECTED]>
All opinions are my own, not my employer's.
If you're not part of the solution, you're part of the precipitate.

Reply via email to