blib/lib/Test/Smoke/App/RunSmoke.pm

filter: Statementstmt 84.5% 126 / 149 Branchbran 48.0% 24 / 50 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 95.6% 22 / 23 Podpod 100% 8 / 8 totaltotal 76.4% 182 / 238 CC 31 SCAR 18.5
CC
31
Cov
75%
run_smoke
12.7
run
10.7
do_manifest_check
8.1
CRAP 6.4
« blib/lib/Test/Smoke/Archiver.pm ↑ Summary blib/lib/Test/Smoke/App/ConfigSmoke/Reporter.pm »
1 package Test::Smoke::App::RunSmoke;
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.001';
7  
8 2 ▶use base 'Test::Smoke::App::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Cwd 'cwd';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use File::Spec::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Test::Smoke::BuildCFG;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Test::Smoke::Policy;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Test::Smoke::Smoker;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Test::Smoke::SourceTree qw/ST_MISSING ST_UNDECLARED/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Test::Smoke::Util qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
18 calc_timeout
19 get_local_patches
20 get_patch
21 set_local_patch
22 skip_config
23 2 /;
24 2 ▶use Test::Smoke::Util::Execute;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 =head1 NAME
27  
28 Test::Smoke::App::RunSmoke - The tsrunsmoke.pl application.
29  
30 =head1 DESCRIPTION
31  
32 This applet takes care of running the "smoke-mantra" for all
33 build-configurations.
34  
35 =head2 $smoker->run();
36  
37 reimplemention of the old C<Test::Smoke::run_smoke()>.
38  
39 =cut
40  
41 3 ▶sub run {
Subroutine run: called CC=7 SCAR=23.7
Pod documented
42 3 my $self = shift;
43  
44 3 my $cwd = cwd();
45 3 $self->log_info("[%s] chdir(%s)", $0, $self->option('ddir'));
46 3 ▶ chdir $self->option('ddir') or
Branch: 1 branch
BranchTrueFalseTotal
chdir $self->option("ddir") or die sprintf("Cannot chdir(%s): %s", $self->option("ddir"), $!) 2 1 3
47 die sprintf("Cannot chdir(%s): %s", $self->option('ddir'), $!);
48  
49 2 my $timeout = 0;
50 2 ▶ if ($Config{d_alarm} && $self->option('killtime')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Test::Smoke::App::RunSmoke::Config{"d_alarm"} and $self->option("killtime")) 0 2 2
Condition33%1/3
$Test::Smoke::App::RunSmoke::Config{"d_alarm"} and $self->option("killtime")
!ll&&!rl&&r
020
MC/DC0%0/2
$Test::Smoke::App::RunSmoke::Config{"d_alarm"} and $self->option("killtime")
$Test::Smoke::App::RunSmoke::Config{"d_alarm"} $self->option("killtime")
Truth table33%1/3
A and B
A= $Test::Smoke::App::RunSmoke::Config{"d_alarm"}B= $self->option("killtime")
ABresult
0X0
100
111
51 0 $timeout = calc_timeout($self->option('killtime'));
52 0 $self->log_info(
53 "Setup alarm: %s", scalar localtime(time + $timeout)
54 );
55 }
56 0 ▶ $timeout and local $SIG{ALRM} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 0 warn "This smoke is aborted (@{[$self->option('killtime')]})\n";
58 0 exit;
59 2 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$timeout and local $SIG{"ALRM"} = sub { warn qq[This smoke is aborted (@{[$self->option("killtime")];})\n]; exit; } 0 2 2
60 2 ▶ $Config{d_alarm} and alarm $timeout;
Branch: 1 branch
BranchTrueFalseTotal
$Test::Smoke::App::RunSmoke::Config{"d_alarm"} and alarm $timeout 2 0 2
61  
62 2 ▶ if ($self->option('is_win32')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->option("is_win32")) 0 2 2
63 0 require Test::Smoke::Util::Win32ErrorMode;
64 0 $self->log_info("Changing ErrorMode settings to prevent popups");
65 0 Test::Smoke::Util::Win32ErrorMode::lower_error_settings();
66 }
67  
68 2 $self->run_smoke(@{ $self->option('pass_option') });
69 2 chdir $cwd;
70 }
71  
72 =head2 $smoker->run_smoke();
73  
74 =cut
75  
76 1 ▶sub run_smoke {
Subroutine run_smoke: called CC=11 SCAR=25.4
77 1 my $self = shift;
78  
79 1 my $BuildCFG = $self->{_BuildCFG} = $self->create_buildcfg(@_);
80  
81 1 ▶ my $mode = $self->option('continue') ? ">>" : ">";
Branch: 1 branch
BranchTrueFalseTotal
$self->option('continue') ? : 0 1 1
82 1 my $logfile = catfile($self->option('ddir'), $self->option('outfile'));
83 1 ▶ open my $log, $mode, $logfile or die "Cannot create($logfile): $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $log, $mode, $logfile or die "Cannot create($logfile): $!" 1 0 1
84  
85 1 my $policy = $self->{_policy} = $self->create_policy;
86  
87 1 my $smoker = $self->{_smoker} = $self->create_smoker($log);
88  
89 1 $smoker->mark_in;
90  
91 1 ▶ $self->log_info("Running smoke tests without \$ENV{PERLIO}")
Branch: 1 branch
BranchTrueFalseTotal
if $self->option("defaultenv") 0 1 1
92 if $self->option('defaultenv');
93 1 $self->log_harness_message();
94  
95 1 ▶ if (! chdir($self->option('ddir'))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (chdir $self->option("ddir")) 0 1 1
96 0 die sprintf("Cannot chdir(%s): %s", $self->option('ddir'), $!);
97 }
98  
99 1 my $patch = get_patch($self->option('ddir'));
100 1 $self->log_debug("[get_patch] found: '%s'", join("', '", @$patch));
101 1 ▶ if (!$self->option('continue')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->option("continue")) 1 0 1
102 1 $smoker->make_distclean();
103 1 ▶ $smoker->ttylog("Smoking patch $patch->[0] @{[$patch->[1]||'']}\n");
Condition50%1/2
$patch->[1] || ''
l!l
10
MC/DC0%0/1
$patch->[1] || ''
$patch->[1]
Truth table50%1/2
A
A= $patch->[1]
Aresult
11
00
104 1 ▶ $smoker->ttylog("Smoking branch $patch->[2]\n") if $patch->[2];
Branch: 1 branch
BranchTrueFalseTotal
if $patch->[2] 1 0 1
105 1 $self->do_manifest_check();
106 1 $self->add_smoke_patchlevel($patch->[0]);
107 }
108  
109 1 foreach my $this_cfg ( $BuildCFG->configurations ) {
110 8 $smoker->mark_out; $smoker->mark_in;
111 8 ▶ if ( skip_config( $this_cfg ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (skip_config($this_cfg)) 0 8 8
112 0 $smoker->ttylog( "Skipping: '$this_cfg'\n" );
113 0 next;
114 }
115  
116 8 $smoker->ttylog( join "\n",
117 "", "Configuration: $this_cfg", "-" x 78, "" );
118 8 $smoker->smoke( $this_cfg, $policy );
119 }
120  
121 1 $smoker->mark_out;
122 1 $smoker->ttylog("Finished smoking @$patch\n" );
123  
124 1 ▶ close $log or $self->log_warn("Error on closing logfile: $!");
Branch: 1 branch
BranchTrueFalseTotal
close $log or $self->log_warn("Error on closing logfile: $!") 1 0 1
125 }
126  
127 =head2 $smoker->log_harness_message()
128  
129 Log stuff about Test::Harness...
130  
131 =cut
132  
133 1 ▶sub log_harness_message {
Subroutine log_harness_message: called CC=4 SCAR=18.7
Pod documented
134 1 my $self = shift;
135 1 my $harness_msg;
136 1 ▶ if ( $self->option('harnessonly') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->option("harnessonly")) 0 1 1
137 0 $harness_msg = "Running test suite only with 'harness'";
138 0 ▶ if ($self->option('harness3opts')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->option("harness3opts")) 0 0 0
139 0 $harness_msg .= " with HARNESS_OPTIONS="
140 . $self->option('harness3opts');
141 }
142 }
143 1 ▶ $self->log_info($harness_msg) if $harness_msg;
Branch: 1 branch
BranchTrueFalseTotal
if $harness_msg 0 1 1
144 }
145  
146 =head2 $smoker->check_for_harness3()
147  
148 Determine the version of L<Test::Harness> shipped with this perl and set
149 B<hasharness3> accordingly.
150  
151 =cut
152  
153 1 ▶sub check_for_harness3 {
Subroutine check_for_harness3: called CC=5 SCAR=16.9
Pod documented
154 1 my $self = shift;
155  
156 1 my @mod_dirs = (
157 [qw/ ext Test-Harness lib Test /],
158 [qw/ cpan Test-Harness lib Test /],
159 [qw/ lib Test /],
160 );
161 my @harnesses = grep {
162 3 ▶ $self->log_debug("[filetest] %s: %s", $_, (-f $_ ? 'Y' : 'N'));
Branch: 1 branch
BranchTrueFalseTotal
-f $_ ? : 1 2 3
163 3 -f $_;
164 } map {
165 1 catfile(catdir($self->option('ddir'), @$_), 'Harness.pm')
166 } @mod_dirs;
167  
168 1 my $chk = Test::Smoke::Util::Execute->new(
169 command => $^X,
170 verbose => $self->option('verbose')
171 );
172  
173 1 ▶ if (!@harnesses) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@harnesses) 0 1 1
174 0 $self->log_warn("No Test::Harness found, incomplete source-tree, abandon!");
175 0 die "No Test::Harness found, incomplete sourc-tree, abandon!";
176 }
177  
178 1 my $version = '0.00';
179 1 for my $th_candidate (@harnesses) {
180 1 $self->log_debug("Test::Harness candidate '%s'", $th_candidate);
181 1 $version = eval {
182 1 $chk->run(
183 "-e",
184 "require q[$th_candidate];print Test::Harness->VERSION",
185 "2>&1",
186 );
187 };
188 1 ▶ if ($chk->exitcode != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chk->exitcode != 0) 0 1 1
189 0 $self->log_warn("Error with Test::Harness->VERSION: $version");
190 0 $version = '0.00';
191 0 next;
192 }
193 }
194 1 $self->log_info("Found: Test::Harness version %s.", $version);
195  
196 1 return $self->{_hasharness3} = (eval("$version") >= 3);
197 }
198  
199 =head2 $smoker->create_buildcfg()
200  
201 Returns an appropriate L<Test::Smoke::BuildCFG> instance.
202  
203 =cut
204  
205 1 ▶sub create_buildcfg {
Subroutine create_buildcfg: called CC=4 SCAR=14.5
Pod documented
206 1 my $self = shift;
207  
208 1 ▶ my @df_buildopts = @_ ? grep /^-[DUA]/ => @_ : ();
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 0 1
209 # We *always* want -Dusedevel!
210 1 ▶ push @df_buildopts, '-Dusedevel'
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^-Dusedevel$/, @df_buildopts 1 0 1
211 unless grep /^-Dusedevel$/ => @df_buildopts;
212  
213 1 Test::Smoke::BuildCFG->config(dfopts => join(" ", @df_buildopts));
214  
215 1 my $patch = Test::Smoke::Util::get_patch($self->option('ddir'));
216  
217 1 $self->check_for_harness3();
218  
219 1 my $logfile = catfile($self->option('ddir'), $self->option('outfile'));
220  
221 1 ▶ if ($self->option('continue')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->option("continue")) 0 1 1
222 0 return Test::Smoke::BuildCFG->continue(
223 $logfile,
224 $self->option('cfg'),
225 v => $self->option('verbose')
226 );
227 }
228 1 return Test::Smoke::BuildCFG->new(
229 $self->option('cfg'),
230 v => $self->option('verbose')
231 );
232 }
233  
234 =head2 $smoker->create_policy()
235  
236 Create the L<Test::Smoke::Policy> instance.
237  
238 =cut
239  
240 1 ▶sub create_policy {
Subroutine create_policy: called CC=1 SCAR=0.0
Pod documented
241 1 my $self = shift;
242 1 return Test::Smoke::Policy->new(
243 updir(),
244 $self->option('verbose'),
245 $self->BuildCFG->policy_targets
246 );
247 }
248  
249 =head2 $smoker->create_smoker($log_handle)
250  
251 Instantiate L<Test::Smoke::Smoker>.
252  
253 =cut
254  
255 1 ▶sub create_smoker {
Subroutine create_smoker: called CC=1 SCAR=0.0
Pod documented
256 1 my $self = shift;
257 1 my ($log_handle) = @_;
258  
259 1 return Test::Smoke::Smoker->new(
260 $log_handle,
261 {
262 $self->options,
263 v => $self->option('verbose')
264 }
265 );
266 }
267  
268 =head2 $smoker->do_manifest_check()
269  
270 Calls Test::Smoke::SourceTree->check_MANIFEST().
271  
272 =cut
273  
274 1 ▶sub do_manifest_check {
Subroutine do_manifest_check: called CC=4 SCAR=20.9
Pod documented
275 1 my $self = shift;
276  
277 1 my $tree = Test::Smoke::SourceTree->new(
278 $self->option('ddir'),
279 $self->option('verbose'),
280 );
281  
282 1 my $mani_check = $tree->check_MANIFEST(
283 $self->option('outfile'),
284 $self->option('rptfile'),
285 'patchlevel.bak',
286 );
287 1 foreach my $file ( sort keys %$mani_check ) {
288 0 ▶ if ( $mani_check->{ $file } == ST_MISSING ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mani_check->{$file} == 1) { } 0 0 0
elsif ($mani_check->{$file} == 0) { } 0 0 0
289 0 $self->smoker->log("MANIFEST declared '$file' but it is missing\n");
290 }
291 elsif ( $mani_check->{ $file } == ST_UNDECLARED ) {
292 0 $self->smoker->log( "MANIFEST did not declare '$file'\n" );
293 }
294 }
295 }
296  
297 =head2 $smoker->add_smoke_patchlevel()
298  
299 Calls L<Test::Smoke::Util::set_local_patch()> to add a patch-string.
300  
301 =cut
302  
303 1 ▶sub add_smoke_patchlevel {
Subroutine add_smoke_patchlevel: called CC=2 SCAR=7.0
Pod documented
304 1 my $self = shift;
305 1 my ($patch) = @_;
306  
307 1 my @smokereg = grep
308 /^SMOKE[a-fA-F0-9]+$/
309 , get_local_patches($self->option('ddir'), $self->option('verbose'));
310 1 ▶ if (!@smokereg) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @smokereg) 1 0 1
311 1 $self->log_info("Adding 'SMOKE$patch' to the registered patches.");
312 1 set_local_patch($self->option('ddir'), "SMOKE$patch");
313 }
314 }
315  
316 2 1;
317  
318 =head1 COPYRIGHT
319  
320 (c) 2002-2013, Abe Timmerman <abeltje@cpan.org> All rights reserved.
321  
322 With contributions from Jarkko Hietaniemi, Merijn Brand, Campo
323 Weijerman, Alan Burlison, Allen Smith, Alain Barbet, Dominic Dunlop,
324 Rich Rauenzahn, David Cantrell.
325  
326 This library is free software; you can redistribute it and/or modify
327 it under the same terms as Perl itself.
328  
329 See:
330  
331 =over 4
332  
333 =item * L<http://www.perl.com/perl/misc/Artistic.html>
334  
335 =item * L<http://www.gnu.org/copyleft/gpl.html>
336  
337 =back
338  
339 This program is distributed in the hope that it will be useful,
340 but WITHOUT ANY WARRANTY; without even the implied warranty of
341 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
342  
343 =cut
« blib/lib/Test/Smoke/Archiver.pm ↑ Summary blib/lib/Test/Smoke/App/ConfigSmoke/Reporter.pm »