When I changed this line:

     push @stack_trace, [ (caller($i))[0 .. 3] ] while caller(++$i);

 to this (taken straight from Devel::StackTrace):

     while ( do { package DB; @DB::args = (); @c = caller($i++) } ) {
         push @stack_trace, [ @c[0 .. 3] ];        
     }

(Note the post-increment of $i instead of the pre-increment)

This makes the Devel::Cover run work, and the plain test fail. So it seems that maybe Devel::Cover is pushing up the caller() level?

Using the DB package did help though, because even just changing $i to a post-increment like this:

     push @stack_trace, [ (caller($i))[0 .. 3] ] while caller($i++);

did not help, only the addition of the DB package AND the post-increment made the Devel::Cover run work (but made the normal test fail).

Anyway, I am still looking.

Steve


On Sep 10, 2004, at 12:50 PM, stevan little wrote:

I am seeing some weird behavior where Devel::Cover seems to be removing/consuming information I am trying to extract with caller(). I have managed to isolate the behavior in a small script, which is included below.

Anyone else seen this problem before? Am I doing something wrong? Or is this a limitation of Devel::Cover? Any thoughts?

Thanks,

Steve

Here is the script:
-----------------------------------------------------
#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 2;

{
    package TestCaller;

    use strict;
    use warnings;

sub throw {
my $self = bless {}, __PACKAGE__;
my $i = 0;
my @stack_trace;
push @stack_trace, [ (caller($i))[0 .. 3] ] while caller(++$i);
$self->{stack_trace} = [EMAIL PROTECTED];
die $self;
}
}


eval { throw TestCaller };
isa_ok($@, 'TestCaller');

is_deeply([EMAIL PROTECTED]>{stack_trace},
          [[ 'main', 'test.pl', 24, '(eval)']],
          '... got the stack trace we expected');
1;

-----------------------------------------------------
And here is the output of that script:
-----------------------------------------------------

[:~] stevan% perl test.pl
1..2
ok 1 - The object isa TestCaller
ok 2 - ... got the stack trace we expected
[:~] stevan% perl -MDevel::Cover test.pl
1..2
Devel::Cover 0.47: Collecting coverage data for branch, condition, pod, statement, subroutine and time.
Selecting packages matching:
Ignoring packages matching:
/Devel/Cover[./]
Ignoring packages in:
.
/Library/Perl
/Library/Perl/darwin
/Users/stevan/Projects/PerlFramework
ok 1 - The object isa TestCaller
not ok 2 - ... got the stack trace we expected
# Failed test (test.pl at line 27)
# Structures begin differing at:
# $got->[0][0] = Does not exist
# $expected->[0][0] = 'main'
# Looks like you failed 1 tests of 2.
Devel::Cover: Writing coverage database to /Users/stevan/cover_db/runs/1094834470.5906.15059
---------------------------- ------ ------ ------ ------ ------ ------ ------
File stmt branch cond sub pod time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
test.pl 100.0 n/a n/a 100.0 n/a 100.0 100.0
Total 100.0 n/a n/a 100.0 n/a 100.0 100.0
---------------------------- ------ ------ ------ ------ ------ ------ ------






Reply via email to