Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Exception CPAN distribution.

Report information
The Basics
Id: 11846
Status: resolved
Priority: 0/
Queue: Test-Exception

People
Owner: Nobody in particular
Requestors: steve [...] purkis.ca
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.20
Fixed in: 0.22



Subject: throws_ok breaks tests that depend on caller stack
Hiya, I find Test::Exception quite useful for the most part - kudos. Run into a little snag where, for abstract methods I do this in the parent class: package Foo; sub an_abstract_method { shift->subclass_responsibility; } sub subclass_responsibility { my $class = shift->class; my $method = (caller(1))[3]; $method =~ s/.*:://; confess( "abstract method '$method' not implemented for $class" ); } if I wanna test that using Test::Exception, I find the caller stack gets changed under my feet: throws_ok( Foo->an_abstract_method, qr/abstract method 'an_abstract_method'/, 'blah' ); results in a failed test because the 'subclass_responsibility' is returning: abstract method '_try_as_caller' not implemented for Foo So I have to resort to using eval {} & Test::More's like()... Any way around it in Test::Exception? -Steve
[guest - Fri Mar 11 11:57:03 2005]: Show quoted text
> Hiya, > > I find Test::Exception quite useful for the most part - kudos.
Ta. Show quoted text
> > Run into a little snag where, for abstract methods I do this in the > parent class:
[nasty behaviour snipped] You're right. That shouldn't happen. I'll look into it. Cheers, Adrian
Just to let you know I've finally had time to look at this. It's a foul up with the way I'm using Sub::Uplevel. I'm gonna rewrite this bit to avoid S::U and pretend to be a normal eval as far as caller() is concerned. Fix will be in the next release. Adrian [guest - Fri Mar 11 11:57:03 2005]: Show quoted text
> Hiya, > > I find Test::Exception quite useful for the most part - kudos. > > Run into a little snag where, for abstract methods I do this in the > parent class: > > package Foo; > sub an_abstract_method { shift->subclass_responsibility; } > sub subclass_responsibility { > my $class = shift->class; > my $method = (caller(1))[3]; > $method =~ s/.*:://; > confess( "abstract method '$method' not implemented for $class" ); > } > > if I wanna test that using Test::Exception, I find the caller stack > gets changed under my feet: > > throws_ok( Foo->an_abstract_method, qr/abstract method > 'an_abstract_method'/, 'blah' ); > > results in a failed test because the 'subclass_responsibility' is > returning: > > abstract method '_try_as_caller' not implemented for Foo > > So I have to resort to using eval {} & Test::More's like()... Any way > around it in Test::Exception? > > -Steve
From: dagolden [...] cpan.org
[ADIE - Mon Aug 15 15:39:10 2005]: Show quoted text
> Just to let you know I've finally had time to look at this. It's a > foul up with the way I'm using > Sub::Uplevel. I'm gonna rewrite this bit to avoid S::U and pretend to > be a normal eval as far as > caller() is concerned. Fix will be in the next release.
Just FYI, I think there's an off-by-one bug in Sub::Uplevel that may (or may not) be related. It affects a subroutine called with uplevel then calling another subroutine. I wrote it up for Schwern: https://rt.cpan.org/Ticket/Display.html?id=13893 My fix for it then breaks some stuff in Test::Exception, so I thought I'd mention it if you're wrestling with Sub::Uplevel issues.
On Sun Aug 21 21:22:04 2005, DAGOLDEN wrote: Show quoted text
> My fix for it then breaks some stuff in Test::Exception, so I thought > I'd mention it if you're wrestling with Sub::Uplevel issues.
I've taken over maintenance of Sub::Uplevel. There's a better fix just released in Sub::Uplevel 0.12 that no longer breaks Test::Exception as far as I can tell.