line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::If; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
189363
|
use 5.006; |
|
6
|
|
|
|
|
22
|
|
|
6
|
|
|
|
|
234
|
|
4
|
6
|
|
|
6
|
|
30
|
use warnings; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
156
|
|
5
|
6
|
|
|
6
|
|
29
|
use strict; |
|
6
|
|
|
|
|
22
|
|
|
6
|
|
|
|
|
361
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Test::If - Test only if ... |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 0.01 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Generic usage |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Test::More; |
25
|
|
|
|
|
|
|
use Test::If 'Test::Something', [ tests => N ]; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Is equal to |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use Test::More; |
30
|
|
|
|
|
|
|
eval q{ use Test::Something; 1 } or plan skip_all => 'Module Test::Something required for this test'; |
31
|
|
|
|
|
|
|
plan tests => N; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
use Test::More; |
35
|
|
|
|
|
|
|
use Test::If sub { $ENV{TEST_AUTHOR} }, [ tests => N ]; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Is equal to |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
use Test::More; |
40
|
|
|
|
|
|
|
$ENV{TEST_AUTHOR} or plan skip_all => "Test condition not met"; |
41
|
|
|
|
|
|
|
plan tests => N; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
You can also combine options and it is allowed to omit plan options, if it is runned by loaded module or you want to load it manually |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
For example common C: |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
use Test::More; |
48
|
|
|
|
|
|
|
use Test::If |
49
|
|
|
|
|
|
|
sub { $ENV{TEST_AUTHOR} }, # Checked first $ENV{TEST_AUTHOR}, otherwise skip |
50
|
|
|
|
|
|
|
'Test::Pod::Coverage 1.08', # Use Test::Pod::Coverage of at least version 1.08 |
51
|
|
|
|
|
|
|
'Pod::Coverage 0.18', # And want Pod::Coverage at least of version 0.18 |
52
|
|
|
|
|
|
|
; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
all_pod_coverage_ok(); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
If some of conditions will not be met, test will be skipped. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
6
|
|
|
6
|
|
28
|
use Test::Builder (); |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
89
|
|
61
|
6
|
|
|
6
|
|
27
|
use Test::More (); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
1752
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub import { |
66
|
6
|
|
|
6
|
|
55
|
my $me = shift; |
67
|
6
|
|
|
|
|
15
|
my $caller = caller; |
68
|
6
|
|
|
|
|
22
|
$Test->exported_to($caller); |
69
|
6
|
100
|
|
|
|
38
|
my $plan;$plan = pop if ref $_[-1] eq 'ARRAY'; |
|
6
|
|
|
|
|
32
|
|
70
|
6
|
|
|
|
|
17
|
for my $check (@_) { |
71
|
7
|
100
|
|
|
|
169
|
if (ref $check eq 'CODE') { |
72
|
4
|
100
|
|
|
|
13
|
$check->() or return $Test->plan(skip_all => "Test condition not met"); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
else { |
75
|
3
|
100
|
|
3
|
|
164
|
if (eval qq{package main; use $check; 1}) { |
|
3
|
|
|
|
|
776
|
|
|
1
|
|
|
|
|
36
|
|
|
1
|
|
|
|
|
7
|
|
76
|
|
|
|
|
|
|
# Module loaded |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else { |
79
|
2
|
|
|
|
|
30
|
return $Test->plan(skip_all => "Module $check required for this test"); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
2
|
100
|
|
|
|
29
|
$Test->plan( @$plan ) if $plan; |
84
|
|
|
|
|
|
|
# unless $Test->has_plan; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 AUTHOR |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Mons Anderson, C<< >> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Copyright 2009 Mons Anderson, all rights reserved. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
97
|
|
|
|
|
|
|
under the same terms as Perl itself. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; # End of Test::If |