mikosullivan has asked for the wisdom of the Perl Monks concerning the following question:

I am developing a module that is specifically for Unixish systems. It will have no applicability to Windows. When I release the module on CPAN, how should I go about allowing for tests on Windows machines? Should I just let them fail, or should I do some kind of OS detection? If I do OS detection, should I just output a bunch of meaningless ok's so that it "passes"?

I hate seeing any fails in the tests section of my modules on CPAN, so I'd rather have the module "pass" on windows if that makes sense to do so.

Replies are listed 'Best First'.
Re: Tests on Windows for Unix-only module
by VinsWorldcom (Prior) on Dec 19, 2014 at 18:32 UTC

    I have a Windows-only module on CPAN (exact opposite of your case) but I do the "same", test if it's Windows and then the version of Windows. I do it in the Makefile.PL since the module is completely useless on *nix:

    # Only supported on Win32 unless ($^O eq "MSWin32" || $^O eq "cygwin") { die "OS unsupported\n" } # Must be Win32 version greater than 5 # _WIN32_WINNT must be defined as greater than 5 for # LockWorkStation prototype to be defined in winuser.h. my $ver = `ver`; $ver =~ / ([\d\.]+)/; $ver = $1; if ($ver < 5) { die "OS unsupported\n Windows version must be greater than 5.\n +Found '$ver' with the 'ver' command." } WriteMakefile( [...]

    If you don't want to preemptive test in the Makefile.PL, you can use SKIP in the tests after determining OS is Windows to skip over tests that won't make sense / fail.

      OK, skip looks like what I want, but it results in something I don't understand. Here's a bare-bones example that causes the curios behavior:
      #!/usr/bin/perl -w
      use strict;
      use Test;
      BEGIN { plan tests => 1 };
      skip (0, sub { ok(1) } );
      
      I thought that would produce a single "ok", but here's the actual output:
      1..1
      # Running under perl version 5.018002 for linux
      # Current time local: Tue Dec 30 00:51:18 2014
      # Current time GMT:   Tue Dec 30 05:51:18 2014
      # Using Test.pm version 1.26
      ok 1
      ok 2
      
      Why are there two ok's?

      If I change that first param to 1, so that it skips the test, it outputs one ok:

      1..1
      # Running under perl version 5.018002 for linux
      # Current time local: Tue Dec 30 00:54:55 2014
      # Current time GMT:   Tue Dec 30 05:54:55 2014
      # Using Test.pm version 1.26
      ok 1 # skip
      
      ???

        Why are there two ok's?

        One from skip the other from the ok? Probably true :)

        If I change that first param to 1, so that it skips the test, it outputs one ok: ???

        So what does the documentation for skip say?

        Try see here https://metacpan.org/pod/Test#skip-skip_if_true-args

Re: Tests on Windows for Unix-only module ( Devel::AssertOS )
by Anonymous Monk on Dec 19, 2014 at 21:17 UTC

    What does the cpan testers wiki say?

    IIRC Devel::AssertOS

    update: http://wiki.cpantesters.org/wiki/CPANAuthorNotes "How can I indicate that my distribution only works on a particular operating system?"

    # in a Makefile.PL or Build.PL use lib 'inc'; use Devel::AssertOS qw(Linux FreeBSD Cygwin);

    I do want to say, I've seen once or twice these types of tests used because of a dependence on /bin/gzip or some typical unix program ... they do exist on windows also :) so test for the program if thats the real dependency