Tests.PL

filter: Statementstmt 90.2% 46 / 51 Branchbran 50.0% 9 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 81.0% 60 / 74 CC 10 SCAR 23.7
CC
10
Cov
80%
write_test
14.6
BEGIN
1.0
BEGIN
1.0
CRAP 10.7
« blib/lib/Best.pm ↑ Summary
1 #!perl
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 write_test( file => 'basic', tests => 4, best => <<'BEST', code => <<'CODE' );
6 use Best qw/A::Module AnAlternative LastChance/;
7 BEST
8 is "@attempted", 'A::Module AnAlternative LastChance', 'tried all modules';
9 is "@loaded", 'LastChance', 'loaded correct one - trace evidence';
10 is (Best->which('A::Module'), 'LastChance', 'loaded correct one - which()');
11  
12 {
13 package Someother;
14 Test::More::is (Best->which('A::Module'), 'LastChance', 'loaded correct one - which() from other module');
15 }
16 CODE
17  
18 1 write_test(
19 file => 'basic-a',
20 tests => 2,
21 best => <<'BEST', code => <<'CODE' );
22 use Best [ qw/A::Module AnAlternative LastChance/ ];
23 BEST
24 is "@attempted", 'A::Module AnAlternative LastChance', 'tried all modules';
25 is "@loaded", 'LastChance', 'loaded correct one - trace evidence';
26 CODE
27  
28 1 write_test(
29 file => 'best',
30 tests => 3,
31 best => <<'BEST', code => <<'CODE' );
32 use Best [ [qw/A::Module AnAlternative LastChance/], qw/moose elk/ ];
33 BEST
34 is "@attempted", 'A::Module AnAlternative LastChance', 'tried all modules';
35 is "@loaded", 'LastChance', 'loaded correct one';
36 is "@args", 'LastChance moose elk', '->import';
37 CODE
38  
39 1 write_test(
40 file => 'onearg',
41 tests => 3,
42 best => <<'BEST', code => <<'CODE' );
43 # miyagawa++ noticed a crash when there was exactly one element on the
44 # import list. Oops!
45 use Best [ [qw/A::Module AnAlternative LastChance/], qw/moose/ ];
46 BEST
47 is "@attempted", 'A::Module AnAlternative LastChance', 'tried all modules';
48 is "@loaded", 'LastChance', 'loaded correct one';
49 is "@args", 'LastChance moose', '->import';
50 CODE
51  
52 1 write_test(
53 file => 'args-a',
54 tests => 3,
55 best => <<'BEST', code => <<'CODE' );
56 use Best [ [qw/A::Module AnAlternative LastChance/], [qw/moose elk/] ];
57 BEST
58 is "@attempted", 'A::Module AnAlternative LastChance', 'tried all modules';
59 is "@loaded", 'LastChance', 'loaded correct one';
60 is "@args", 'LastChance moose elk', '->import';
61 CODE
62  
63 1 write_test(
64 file => 'noargs',
65 tests => 3,
66 best => <<'BEST', code => <<'CODE' );
67 use Best [ [qw/A::Module AnAlternative LastChance/], [] ];
68 BEST
69 is "@attempted", 'A::Module AnAlternative', 'tried all modules';
70 is "@loaded", '', q[->import wasn't called]; # AnAlternative's import was not called
71 is "@args", '', q[->import];
72 CODE
73  
74 1 write_test( file => 'ver', tests => 3, best => <<'BEST', code => <<'CODE' );
75 use Best [ [qw/Version::TooLow 2.00 Version::Ok 1.00/], qw/moose elk/ ];
76 BEST
77 is "@attempted", 'Version::TooLow Version::Ok', 'attempted';
78 is "@loaded", 'Version::Ok', 'loaded';
79 is "@args", 'Version::Ok moose elk', 'args';
80 CODE
81  
82 1 write_test(
83 file => 'exist-a',
84 tests => 3,
85 best => <<'BEST', code => <<'CODE' );
86 use Best [ [qw/Doesn't::Exist LastChance/], qw/moose elk/ ];
87 BEST
88 is "@attempted", q[Doesn::t::Exist LastChance];
89 is "@loaded", 'LastChance';
90 is "@args", 'LastChance moose elk';
91 CODE
92  
93 1 write_test( file => 'exist', tests => 3, best => <<'BEST', code => <<'CODE' );
94 use Best qw/Doesn't::Exist LastChance/;
95 BEST
96 is "@attempted", q[Doesn::t::Exist LastChance];
97 is "@loaded", 'LastChance';
98 is "@args", 'LastChance';
99 CODE
100  
101 1 write_test( file => 'code', tests => 3, best => <<'BEST', code => <<'CODE' );
102 use Best [ [sub {
103 push @attempted, 'Failed code';
104 return;
105 },
106 'LastChance'], qw/moose elk/ ];
107 BEST
108 is "@attempted", 'Failed code LastChance';
109 is "@loaded", 'LastChance';
110 is "@args", 'LastChance moose elk';
111 CODE
112  
113 1 write_test( file => 'hash', tests => 3, best => <<'BEST', code => <<'CODE' );
114 use Best ( 'A::Module' => {},
115 AnAlternative => {},
116 LastChance => {}, );
117 BEST
118 is "@attempted", 'A::Module AnAlternative LastChance';
119 is "@loaded", 'LastChance';
120 is "@args", 'LastChance'
121 CODE
122  
123 1 write_test(
124 file => 'hash-a',
125 tests => 3,
126 best => <<'BEST', code => <<'CODE' );
127 use Best [ 'A::Module' => {},
128 AnAlternative => {},
129 LastChance => {}, ];
130 BEST
131 is "@attempted", 'A::Module AnAlternative LastChance';
132 is "@loaded", 'LastChance';
133 is "@args", 'LastChance'
134 CODE
135  
136 1 write_test(
137 file => 'hash-aa',
138 tests => 3,
139 best => <<'BEST', code => <<'CODE' );
140 use Best [[ 'A::Module' => {},
141 AnAlternative => {},
142 LastChance => {}, ]];
143 BEST
144 is "@attempted", 'A::Module AnAlternative LastChance';
145 is "@loaded", 'LastChance';
146 is "@args", 'LastChance'
147 CODE
148  
149 1 write_test(
150 file => 'ver-h',
151 tests => 3,
152 best => <<'BEST', code => <<'CODE' );
153 use Best [ [ 'Version::TooLow' => { version => '2.00', },
154 'Version::Ok' => { version => '2.00', }, ],
155 [qw/moose elk/], ];
156 BEST
157 is "@attempted", 'Version::TooLow Version::Ok';
158 is "@loaded", 'Version::Ok';
159 is "@args", 'Version::Ok moose elk';
160 CODE
161  
162 1 write_test(
163 file => 'ok-h',
164 tests => 3,
165 best => <<'BEST', code => <<'CODE' );
166 use Best [ [ 'Loads::Ok' => { ok => sub { return } },
167 'LastChance', ],
168 [qw/moose elk/], ];
169 BEST
170 is "@attempted", 'Loads::Ok LastChance', 'attempted';
171 is "@loaded", 'LastChance', 'loaded';
172 is "@args", 'LastChance moose elk', 'args';
173 CODE
174  
175 1 write_test( file => 'if-h', tests => 2, best => <<'BEST', code => <<'CODE' );
176 use Best [ [ 'A::Module' => { if => sub { 0 }, },
177 qw/AnAlternative LastChance/ ], ];
178 BEST
179 is "@attempted", 'AnAlternative LastChance';
180 is "@loaded", 'LastChance';
181 CODE
182  
183 1 write_test(
184 file => 'args-h',
185 tests => 3,
186 best => <<'BEST', code => <<'CODE' );
187 use Best [ [ qw/A::Module AnAlternative/,
188 LastChance => { args => [qw/moose elk/] } ],
189 qw/Unused arguments/];
190 BEST
191 is "@attempted", 'A::Module AnAlternative LastChance';
192 is "@loaded", 'LastChance';
193 is "@args", 'LastChance moose elk';
194 CODE
195  
196 1 write_test(
197 file => 'code-h',
198 tests => 2,
199 best => <<'BEST', code => <<'CODE' );
200 use Best [ [ sub { push @attempted, 'ignored' } => { if => sub { 0 } },
201 sub { push @attempted, 'ok'; push @loaded, 'ok' } => { ok => sub { 1 } } ] ];
202 BEST
203 is "@attempted", 'ok';
204 is "@loaded", 'ok';
205 CODE
206  
207 1 ▶use constant TEMPLATE => <<'TEMPLATE';
Subroutine BEGIN: called CC=1 SCAR=0.0
208 #!perl
209 ## DO NOT EDIT THIS FILE. It is generated by t/Tests.PL
210 use strict;
211 use warnings;
212 use vars qw/@attempted @loaded @args/;
213  
214 use Test::More tests => 1 + TESTS;
215 use lib qw(t t/lib);
216  
217 # preload for Load::Trace
218 use Carp ();
219 use Best ();
220 use overload ();
221 BEGIN { eval { require mro } } # fixes failure on bleadperl as of 2009-01-17
222 BEGIN {
223 overload::Overloaded( sub {} );
224 overload::Method( sub{}, '&{}' );
225 overload::StrVal( sub{} );
226 }
227  
228 use Load::Trace { port => \@attempted };
229  
230 BEST
231  
232 pass q[Best didn't crash];
233  
234 CODE
235  
236 TEMPLATE
237  
238 {
239 1 my $num;
240 1 ▶ BEGIN { $num = 50 }
Subroutine BEGIN: called CC=1 SCAR=0.0
241  
242 sub write_test {
243 18 ▶ my %p = @_;
Subroutine write_test: called CC=10 SCAR=26.8
244 my ( $tests, $best, $code, $file ) = map {
245 18 ▶ if ( not exists $p{$_} )
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $p{$_}) { } 0 72 72
elsif (not defined $p{$_}) { } 0 72 72
246 {
247 0 require Carp;
248 0 Carp::croak("Missing parameter: $_");
249 }
250 elsif ( not defined $p{$_} ) {
251 0 require Carp;
252 0 Carp::croak("Undefined parameter: $_");
253 }
254 72 delete $p{$_}
255 } qw(tests best code file);
256 18 ▶ die "Unknown parameters: @{[sort keys %p]}"
Branch: 1 branch
BranchTrueFalseTotal
if keys %p 0 18 18
257 if keys %p;
258  
259 18 my $src = TEMPLATE;
260  
261 18 ▶ $src =~ s/TESTS/$tests/ or die;
Branch: 1 branch
BranchTrueFalseTotal
$src =~ s/TESTS/$tests/ or die 0 18 18
262 18 ▶ $src =~ s/BEST/$best/ or die;
Branch: 1 branch
BranchTrueFalseTotal
$src =~ s/BEST/$best/ or die 0 18 18
263 18 ▶ $src =~ s/CODE/$code/ or die;
Branch: 1 branch
BranchTrueFalseTotal
$src =~ s/CODE/$code/ or die 0 18 18
264  
265 18 $file = sprintf 't/%02d-%s.t', $num++, $file;
266  
267 18 print "Writing test $file\n";
268 18 ▶ open my $fh, '>', $file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $file or die "Can't open ${file}: $!" 0 18 18
269 or die "Can't open $file: $!";
270 18 ▶ print {$fh} $src
Branch: 1 branch
BranchTrueFalseTotal
print {$fh;} $src or die "Can't write to ${file}: $!" 0 18 18
271 or die "Can't write to $file: $!";
272 18 ▶ close $fh
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Can't flush ${file}: $!" 0 18 18
273 or die "Can't flush $file: $!";
274 18 return;
275 }
276 1 }
« blib/lib/Best.pm ↑ Summary