IMHO, the only reliable cross platform way to check that AF_UNIX is available is to attempt to use it. So you could write code like:

use English eval { # code that uses AF_UNIX }; if( $EVAL_ERROR ) { # AF_UNIX is not avalable } else { # AF_UNIX is not avalable }

However in a test script the code that uses AF_UNIX, is a test, so in effect you are running tests where it is OK if they fail on some platforms. Tests like that are normally configured as TODO tests, so you end up with code like:

TODO: { local $TODO = 'no UNIX sockets on Windows' if $^O =~ /Win/; use Sys::Syslog (); my $path = Sys::Syslog::_PATH_LOG() || '/dev/log'; skip 'unable to detect syslog socket', 1 if !-S $path; lives_ok { $LOG->config({type=>'unix',path=>$path}) }; throws_ok { $LOG->config({type=>'unix',path=>'nosuch'}) } qr/con +nect:/; }

In other words, if the tests fail under windows, then it is not a problem but they are expected to pass on other platforms. I think that describes what you are trying to achieve.

If you think marking the tests as TODO is wrong as it implies that it is something you need to fix, I would say that in this case it is a missing feature that the OS vendor needs to fix, not that they ever will.

Couple of points with the code above. Firstly, I don't have a windows box handy, so I am assuming that nothing bad will happen if you attempt to use AF_Unix sockets on that platform. If the attempt would cause a bluescreen or suchlike, then you would obvously need to skip the tests instead.

Secondly, there are a large number of platforms described in perlport-platforms, and I suspect that there are others besides Windows where AF_UNIX sockets are not supported, so for completeness, you should probably provide a list of values for $^O that will skip the test. Alternatively, use explain (from Test::More), to emit a message to say to users on unusual platforms that these tests might fail, and if they do should contact you with the details.


In reply to Re: Is AF_UNIX available? by chrestomanci
in thread Is AF_UNIX available? by powerman

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.