How to skip tests with Test::More

The following piece of code demonstrates how, using Test::More, to skip some tests for a particular Perl version. In this case, it tests for a version of 5.16. The Perl version variable is stored in $[.

#!/usr/local/bin/perl
use warnings;
use strict;
use Test::More tests => 2;
print "$]\n";
SKIP: {
    skip "wrong version", 1 unless $] >= 5.016;
    ok (1, "Skip");
};
ok (1, "Ok");

(download)

Run with Perl 5.8.9, it produces the following output:

1..2
5.008009
ok 1 # skip wrong version
ok 2 - Ok

Copyright © Ben Bullock 2009-2023. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer