prove with line numbers

2009-05-18 Thread Gabor Szabo
Is there a way to ask prove to print out the row number of each ok() call ?

I have a test script that blows up after 18 calls to ok() inside
the application printing only the line number in the application.
I can search for the title of the ok() all but it would be nice if I
could ask prove
(maybe in the -d flag) to print the line number of each ok() call.

Gabor


Re: prove with line numbers

2009-05-18 Thread Ovid

--- On Mon, 18/5/09, Gabor Szabo  wrote:

> From: Gabor Szabo 

> I have a test script that blows up after 18 calls to ok()
> inside
> the application printing only the line number in the
> application.
> I can search for the title of the ok() all but it would be
> nice if I
> could ask prove
> (maybe in the -d flag) to print the line number of each
> ok() call.


ok() generally comes from Test::Simple/Test::More, which in turn comes from 
Test::Builder.  It's the test builder which controls what can and cannot be 
printed and it really doesn't have a direct way of handling this.  Thus, I 
don't think there's much which could be exposed via prove.  (Seriously 
hungover, though, so I might be talking complete bollocks -- again).

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;
};
  }

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



Re: Cpan Dist Layout Issue

2009-05-18 Thread David Cantrell
On Fri, May 15, 2009 at 06:29:19PM +0100, Smylers wrote:

> [*1]  Though actually is there anything stopping somebody from checking
> whether modules actuall install and sending FAIL results to Cpan Testers
> for those that didn't?  Surely they'd just display like other FAILs.
> Yes that'd be more involved than what current testers are doing, but I
> don't think it means it couldn't be done by somebody.

I don't think it would be particularly more involved*.  If people are
currently not installing what they test, it makes no difference to them.
Those of us who *do* install what we test will see very little
difference - most stuff either goes all the way through and does indeed
install OK, or it stops at one of the previous stages.

Just about the only time I've seen stuff fail at the 'make install'
stage is when I'm running as the wrong user.  And that happens rather
more often than stuff not installing because it's broken but passed its
tests.  I'd worry about false positives.

* at least not for users.  It would presumably require a bit more code
  in CPAN::Reporter etc.

-- 
David Cantrell | Enforcer, South London Linguistic Massive

 I'm in retox


Re: prove with line numbers

2009-05-18 Thread Greg Sabino Mullane
> 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



signature.asc
Description: OpenPGP digital signature