in reply to Tests on Windows for Unix-only module

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.

Replies are listed 'Best First'.
Re^2: Tests on Windows for Unix-only module
by mikosullivan (Novice) on Dec 30, 2014 at 05:55 UTC
    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

        Basically when you're giving skip/ok subs, you don't want to run other ok/skips inside, you want the return value

        ok( wanted, gotten, testname )

        skip( skipit, wanted, gotten, testname )

        $ perl -MTest -le " plan tests=>1; skip 0, sub{ -monkeys }, sub {-bana +nas } ; 1..1 # Running under perl version 5.016001 for MSWin32 # Current time local: Mon Dec 29 22:53:31 2014 # Current time GMT: Tue Dec 30 06:53:31 2014 # Using Test.pm version 1.25_02 not ok 1 # Test 1 got: "-monkeys" (-e at line 1) # Expected: "-bananas" $ perl -MTest -le " plan tests=>1; skip 1, sub{ -monkeys }, sub {-bana +nas } ; 1..1 # Running under perl version 5.016001 for MSWin32 # Current time local: Mon Dec 29 22:53:47 2014 # Current time GMT: Tue Dec 30 06:53:47 2014 # Using Test.pm version 1.25_02 ok 1 # skip $ perl -MTest -le " plan tests=>1; ok sub{ -monkeys }, sub {-bananas } + ; 1..1 # Running under perl version 5.016001 for MSWin32 # Current time local: Mon Dec 29 22:53:53 2014 # Current time GMT: Tue Dec 30 06:53:53 2014 # Using Test.pm version 1.25_02 not ok 1 # Test 1 got: "-monkeys" (-e at line 1) # Expected: "-bananas"