leriksen has asked for the wisdom of the Perl Monks concerning the following question:
Background:
I am writing coverage tests, using Devel::Cover. The coverage tests are for a module that reads encoded files and turns their contents into
an object representation.
Problem:
I have tests that check the modules behaviour when there are various problems with the file e.g. file doesn't exist, is zero length, is actually a
directory, we dont have adequate permissions etc.
But the problem I am having is testing read failures on a file I have successfully opened. And to have those tests work on both Linux and Solaris (others would be nice - but those at a minimum).
Partial Solution:
I have tests that work correctly (that is, cause a read() to fail on a successfully opened file) on Linux, but they dont work on Solaris.
To get the Linux test working, I did this
<File.t> ... my $obj = Widget::File->new(filename => $testfile, # a real file otherstuff => ...); my $dirh = IO::File->new('/', O_RDONLY); # reading a dirhandle forces +a read() failure on Linux $obj->{fh} = $dirh; # invoke a method that calls read() internally eval { $obj->header(); # read()ing from a dirhandle forces an EISDIR erro +r }; like($@, qr(Error in reading file header - Is a directory at )); </File.t>
./t/File..........NOK 71# Failed test (./t/File.t at line 191) # '' # doesn't match '(?-xism:Error in reading file header - Is a direc +tory at )' ./t/File..........ok 73/0# Looks like you failed 1 tests of 73.
BTW
Solaris perl == 5.8.1
Linux perl == 5.8.3
So, please, can anyone advise me on a better way for testing cross platform read failures?
+++++++++++++++++
#!/usr/bin/perl
use warnings;use strict;use brain;
|
|---|