I am puzzled as to how to test for a read() failure across two platform we deploy to here.

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>

But this doesn't work on Solaris - instead I get this

./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.

Now I expect that Solaris is actually returning EISDIR in errno at the C library level, but this isn't propagating up to Perl in Solaris the same way it does in Linux - and hence the regex error.

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;


In reply to Testing for read() failures on different platforms by leriksen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.