I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2008-01-14 20:01:41-08 by ilial
base class method with many tests
I have a base class Foo that inherits from Test::Class and provides a method, action_ok which calls ok 3 times. Then I have a class called Bar which inherits from Foo. Bar::test_something calls
$self->action_ok()
two times. As a result, Bar::test_something actually does 6 tests. So test_something has to be declared as:
sub test_something : Test(6)
But this is not intuitive. A user shouldn't need to know that action_ok() performs 3 tests. I tried to make it more intuitive by implementing action_ok() using fail and pass from Test::More. ie.:
sub action_ok { my ($self, $function, $args) = @_; return 'no function passed' unless $function; my $result = api_call(@_); defined $result or fail("$function returned ok"); ref $result eq 'HASH' or fail("$function returned proper data structure"); $result->{error} == 0 or fail("$function returned no error"); pass("action ok"); return $result; }
I guess another way is to use Test::Builder to export an action_ok method. Thoughts?
Direct Responses: 6874 | Write a response
Posted on 2008-01-14 20:15:31-08 by adrianh in response to 6872
Re: base class method with many tests

Doing what you did is fine. If you look at the various modules that provide assertions (like Test::Deep, Test::Exception, etc.) you'll see that they all encapsulate a complex test as a single pass/fail. So it's pretty much the default approach.

Without seeing the rest of your class it's hard to tell - but perhaps action_ok doesn't really belong to the test class and should be in a separate Test::Actions module?

Direct Responses: Write a response