Skip Menu |
 

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

Report information
The Basics
Id: 30836
Status: resolved
Priority: 0/
Queue: Test-Class

People
Owner: Nobody in particular
Requestors: chris+rt [...] chrisdolan.net
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.24
Fixed in: (no value)



Subject: [wish] permit access to number of tests from outside package
Download (untitled) / with headers
text/plain 1.4k
Short version: I'd like a method like num_method_tests that doesn't rely on caller() but instead walks the @ISA if calling as an instance method. Long version: I've been working on some helper attributes to annotate my tests and have come across a problem. I want my helper to be able to skip the right number of tests conditionally (wrapping the test method along the lines of http://use.perl.org/~ChrisDolan/journal/34906). This works great as long as the wrapping code is in the same package as the test method. However, as soon as I subclass my own test class, the helper is no longer able to get the number of tests because _find_calling_test_class uses caller() to decide which class the requested test belongs to. Contrived, but simple, problem scenario: ---- test.pl ---- use Foo; my $test = Bar->new; Test::More::plan tests => 2; $test->do_skip("test1", 1); $test->do_skip("test2", 1); ---- Foo.pm ---- package Foo; use base 'Test::Class'; use Test::More; sub do_skip { my ($self, $test_name, $bool) = @_; SKIP: { skip "skip requested", $self->num_method_tests($test_name) if $bool; $self->$test_name(); } } sub test1 : Test(1) { fail(); } package Bar; use base 'Foo'; use Test::More; sub test2 : Test(1) { fail(); } 1; ---------------- Output: % perl test.pl 1..2 ok 1 # skip skip requested test2 is not a test method of class Foo at test.pl line 5 # Looks like you planned 2 tests but only ran 1.
From: ADIE [...] cpan.org
Download (untitled) / with headers
text/plain 1.7k
Hi Chris, On Sun Nov 18 21:20:01 2007, CDOLAN wrote: Show quoted text
> Short version: I'd like a method like num_method_tests that doesn't rely > on caller() but instead walks the @ISA if calling as an instance method. > > Long version: I've been working on some helper attributes to annotate my > tests and have come across a problem. I want my helper to be able to > skip the right number of tests conditionally (wrapping the test method > along the lines of http://use.perl.org/~ChrisDolan/journal/34906).
[snip] Like the annotation hack BTW - nice :-) This might be me being dim - but why can't you just return() from the test method. Doesn't T::C already have the right test-skipping behaviour there by default? Cheers, Adrian Show quoted text
> works great as long as the wrapping code is in the same package as the > test method. However, as soon as I subclass my own test class, the > helper is no longer able to get the number of tests because > _find_calling_test_class uses caller() to decide which class the > requested test belongs to. > > Contrived, but simple, problem scenario: > > ---- test.pl ---- > use Foo; > my $test = Bar->new; > Test::More::plan tests => 2; > $test->do_skip("test1", 1); > $test->do_skip("test2", 1); > ---- Foo.pm ---- > package Foo; > use base 'Test::Class'; > use Test::More; > > sub do_skip { > my ($self, $test_name, $bool) = @_; > SKIP: { > skip "skip requested", $self->num_method_tests($test_name) > if $bool; > $self->$test_name(); > } > } > > sub test1 : Test(1) { > fail(); > } > > package Bar; > use base 'Foo'; > use Test::More; > > sub test2 : Test(1) { > fail(); > } > 1; > ---------------- > > Output: > % perl test.pl > 1..2 > ok 1 # skip skip requested > test2 is not a test method of class Foo at test.pl line 5 > # Looks like you planned 2 tests but only ran 1.
Download (untitled) / with headers
text/plain 258b
On Tue Nov 20 07:31:30 2007, ADIE wrote: Show quoted text
> This might be me being dim - but why can't you just return() from the > test method. Doesn't > T::C already have the right test-skipping behaviour there by default?
Oops! So simple, I didn't think of that. Thanks
Download (untitled) / with headers
text/plain 337b
On Tue Nov 20 08:46:59 2007, CDOLAN wrote: Show quoted text
> On Tue Nov 20 07:31:30 2007, ADIE wrote:
> > This might be me being dim - but why can't you just return() from the > > test method. Doesn't > > T::C already have the right test-skipping behaviour there by default?
> > Oops! So simple, I didn't think of that. Thanks
No worries :-) Adrian
Download (untitled) / with headers
text/plain 337b
On Tue Nov 20 08:46:59 2007, CDOLAN wrote: Show quoted text
> On Tue Nov 20 07:31:30 2007, ADIE wrote:
> > This might be me being dim - but why can't you just return() from the > > test method. Doesn't > > T::C already have the right test-skipping behaviour there by default?
> > Oops! So simple, I didn't think of that. Thanks
No worries :-) Adrian


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.