Devel::Cover recommendations... or maybe not?
Pete Sergeant
pete at clueball.com
Thu Mar 15 15:45:46 GMT 2007
On Thu, Mar 15, 2007 at 03:17:49PM +0000, Tara Andrews wrote:
> On 3/15/07, Pete Sergeant <pete at clueball.com> wrote:
>> and perhaps you have to occasionally tie yourself in
>> knots trying to hit certain failure conditions (especially file-system
>> error ones),
>
> OK, I'll bite. How?
Mostly by trying to split out and reuse code as much as possible. For
example, some code I wrote recently has a 'load()' method which takes a
data structure, looks in a specific place for a file path, checks that
file exists, check that that file matches a regex, check that the
application is allowed to delete that file, and then tries to delete it.
The subroutine looks a bit like:
sub load {
my $self = shift;
my $payload = shift;
return undef unless $self->_check_payload_integrity( $payload )
my $file = $self->_check_valid_file( $payload->{file} );
...
unless ( unlink( $file ) { $self->log( FILE_ERROR, "unlink failed: $!" ); return undef }
return 1;
}
All the validation checks were making it pretty difficult to get a
filename which unlink() would fail on past it, so I subclassed the
module, and over-wrote them to return the values I wanted in that
instance:
{
package FakePackage;
use base 'Package';
package Main;
local *FakePackage::_check_valid_file;
*FakePackage::_check_valid_file = sub { return t::lib::IO::file( exists => 1, readable => 0, writeable => 0 ) }
my $object = FakePAckage->new();
etc...
}
I don't know if this is the 'right' way to do it, but it works for me
:-)
> Seriously, a list of hints somewhere of "how to programmatically
> manufacture useful sets of edge cases" would be very useful to people
> who want complete testing for their software, but don't have a wizzo
> tester to get us from A to B.
That I can't help you with :-) I'd guess there are books and so on?
+Pete
More information about the london.pm
mailing list