> If it's a one-off, though, you could try the following (untested):
> 
>   {
>     my $ok = \&Test::Builder::ok;
>     no warnings 'redefined';
>     *Test::Builder::ok = sub {
>         my ( $package, $filename, $line ) = caller;
>         $_[0]->diag("ok() called in $package, $filename at line $line");
>         goto $ok;
>     };
>   }

I've been using something very similar for quite a while, which not only allows
printing of line numbers (invaluable to me for reasons similar to the original
caller), but allows bailing out after a specified number of failures, e.g.:

    no warnings;
    sub is_deeply {
        t($_[2],$_[3] || (caller)[2]);
        return if Test::More::is_deeply($_[0],$_[1],$testmsg);
        if ($bail_on_error > $total_errors++) {
            my $line = (caller)[2];
            my $time = time;
            Test::More::diag("GOT: ".Dumper $_[0]);
            Test::More::diag("EXPECTED: ".Dumper $_[1]);
            Test::More::BAIL_OUT "Stopping on a failed 'is_deeply' test from
line $line. Time: $time";
        }
    } ## end of is_deeply

(The t() function provides some time measurements and formats the $testmsg to
provide things like line numbers. caller is used twice because there are times
when I want to pass in a line number to is_deeply directly.)

-- 
Greg Sabino Mullane g...@endpoint.com
End Point Corporation
PGP Key: 0x14964AC8

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to