File Coverage

blib/lib/Test/Is.pm
Criterion Covered Total %
statement 18 19 94.7
branch 12 16 75.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 35 42 83.3


line stmt bran cond sub pod time code
1 7     7   5003 use strict;
  7         15  
  7         328  
2 7     7   36 use warnings;
  7         12  
  7         3244  
3             package Test::Is;
4             $Test::Is::VERSION = '20140823.1';
5             sub import
6             {
7 8     8   51 shift;
8 8 50       69 die "missing arguments for Test::Is" unless @_;
9              
10             # TODO: check if a Test::Builder exists. If this is the case,
11             # this means we are running too late and this is wrong!
12              
13 8         30 while (@_) {
14 8 100       71 if ($_[0] eq 'interactive') {
    100          
    50          
15 2 50       5 skip_all($_[0]) if env('NONINTERACTIVE_TESTING');
16             } elsif ($_[0] eq 'extended') {
17 1 50       4 skip_all($_[0]) unless env('EXTENDED_TESTING');
18             } elsif ($_[0] =~ /^(?:perl[- ])?(v?5\.[0-9.]+)\+?$/) {
19 5 100       238 eval "require $1" or skip_all("perl $1");
20             } else {
21 0         0 die "invalid Test::Is argument";
22             }
23 3         80 shift;
24             }
25             }
26              
27             sub env
28             {
29 3 100   3 0 35 exists $ENV{$_[0]} && $ENV{$_[0]} eq '1'
30             }
31              
32              
33             sub skip_all
34             {
35 5     5 0 9 my $kind = shift;
36 5         30 print "1..0 # SKIP $kind test";
37 5         8262 exit 0
38             }
39              
40             1;
41              
42             =encoding UTF-8
43              
44             =head1 NAME
45              
46             Test::Is - Skip test in a declarative way, following the Lancaster Consensus
47              
48             =head1 VERSION
49              
50             version 20140823.1
51              
52             =head1 SYNOPSIS
53              
54             I want that this runs only on interactive environments:
55              
56             use Test::Is 'interactive';
57              
58             This test is an extended test: it takes much time to run or may have special
59             running conditions that may inconvenience a user that just want to install the
60             module:
61              
62             use Test::Is 'extended';
63              
64             Both:
65              
66             use Test::Is 'interactive', 'extended';
67              
68             This test is only for perl 5.10+:
69              
70             use Test::Is 'perl v5.10';
71             use feature 'say';
72             ...
73              
74              
75             =head1 DESCRIPTION
76              
77             This module is a simple way of following the
78             L
79             variables available for Perl tests as defined as one of the
80             "L"
81             at Perl QA Hackathon 2013. Those variables
82             (C, C) define which tests should be
83             skipped.
84              
85             If the environment does not match what the author of the test expected, the
86             complete test is skipped (in the same way as C skip_all =E
87             ...>).
88              
89             As an author, you can also expect that you will automatically benefit of later
90             evolutions of this specification just by upgrading the module.
91              
92             As a CPAN toolchain author (CPAN client, smoker...) you may want to ensure at
93             runtime that the installed version of this module matches the environment
94             you set yourself.
95              
96             =head1 SEE ALSO
97              
98             =over 4
99              
100             =item *
101              
102             L:
103             the specification of the Lancaster Consensus.
104              
105             =item *
106              
107             L by WOLFSAGE, also created at Perl QA Hackathon 2013.
108              
109             =back
110              
111             =head1 AUTHOR
112              
113             Olivier MenguĂ©, L
114              
115             =head1 COPYRIGHT & LICENSE
116              
117             Copyright E 2013 Olivier MenguĂ©.
118              
119             This library is free software; you can redistribute it and/or modify it under
120             the same terms as Perl 5 itself.
121              
122             =cut
123              
124             # vim: set et sw=4 sts=4 :