blib/lib/Dist/Zilla/Tester.pm

filter: Statementstmt 91.4% 204 / 223 Branchbran 60.4% 29 / 48 Conditioncond 55.5% 5 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 89.3% 42 / 47 Podpod 8.3% 1 / 12 totaltotal 81.7% 282 / 345 CC 28 SCAR 17.0
CC
28
Cov
85%
__ANON__
15.4
unix_path_seems_portable
14.4
__ANON__
7.6
CRAP 5.5
« blib/lib/Dist/Zilla/Role/FileFinderUser.pm ↑ Summary blib/lib/Dist/Zilla/Role/PPI.pm »
1 package Dist::Zilla::Tester 6.040;
2 # ABSTRACT: a testing-enabling stand-in for Dist::Zilla
3  
4 50 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 50 extends 'Dist::Zilla::Dist::Builder';
6  
7 50 ▶use Dist::Zilla::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 50 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 50 ▶use Dist::Zilla::Chrome::Test;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 50 ▶use File::pushd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 50 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 50 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 50 ▶use Dist::Zilla::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 50 ▶use Sub::Exporter::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 50 ▶use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
18 exports => [
19 1 ▶ Builder => sub { $_[0]->can('builder') },
Subroutine __ANON__: called CC=1 SCAR=0.0
20 1 ▶ Minter => sub { $_[0]->can('minter') },
Subroutine __ANON__: called CC=1 SCAR=0.0
21 50 ],
22  
23 groups => [ default => [ qw(Builder Minter) ] ],
24 50 };
25  
26 50 ▶use namespace::autoclean -except => 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 1 ▶sub from_config {
Subroutine from_config: called CC=1 SCAR=0.0
Pod documented
29 1 my ($self, @arg) = @_;
30  
31 # The only thing using a local time zone should be NextRelease. Normally it
32 # defaults to "local," but since some users won't have an automatically
33 # determinable time zone, we'll switch to not-local times for testing.
34 # -- rjbs, 2015-11-26
35 1 local $Dist::Zilla::Plugin::NextRelease::DEFAULT_TIME_ZONE = 'GMT';
36  
37 1 return $self->builder->from_config(@arg);
38 }
39  
40 178 ▶sub builder { 'Dist::Zilla::Tester::_Builder' }
Subroutine builder: called CC=1 SCAR=0.0
Pod undocumented
41  
42 1 ▶sub minter { 'Dist::Zilla::Tester::_Minter' }
Subroutine minter: called CC=1 SCAR=0.0
Pod undocumented
43  
44 {
45 package
46 Dist::Zilla::Tester::_Role;
47  
48 50 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 # The rmdir in DEMOLISH is expected to fail while other testers still have
51 # tempdirs under the shared root; only the last one out succeeds.
52 50 ▶ use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 50 ▶ no autodie qw(rmdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 50 has tempdir_root => (
56 is => 'rw', isa => 'Str|Undef',
57 writer => '_set_tempdir_root',
58 );
59 50 has tempdir_obj => (
60 is => 'ro', isa => 'File::Temp::Dir',
61 clearer => '_clear_tempdir_obj',
62 writer => '_set_tempdir_obj',
63 );
64  
65 10 ▶ sub DEMOLISH {}
Subroutine DEMOLISH: called CC=1 SCAR=0.0
Pod undocumented
66 10 ▶ around DEMOLISH => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
67 10 my $orig = shift;
68 10 my $self = shift;
69  
70 # File::Temp deletes the directory when it goes out of scope
71 10 $self->_clear_tempdir_obj;
72  
73 10 ▶ rmdir $self->tempdir_root if $self->tempdir_root;
Branch: 1 branch
BranchTrueFalseTotal
if $self->tempdir_root 0 10 10
74 10 return $self->$orig(@_);
75 50 };
76  
77 50 has tempdir => (
78 is => 'ro',
79 writer => '_set_tempdir',
80 init_arg => undef,
81 );
82  
83 0 ▶ sub clear_log_events {
Subroutine clear_log_events: not called CC=1 SCAR=6.9
Pod undocumented
84 0 my ($self) = @_;
85 0 $self->chrome->logger->clear_events;
86 }
87  
88 0 ▶ sub log_events {
Subroutine log_events: not called CC=1 SCAR=6.9
Pod undocumented
89 0 my ($self) = @_;
90 0 $self->chrome->logger->events;
91 }
92  
93 28 ▶ sub log_messages {
Subroutine log_messages: called CC=1 SCAR=0.0
Pod undocumented
94 28 my ($self) = @_;
95 28 [ map {; $_->{message} } @{ $self->chrome->logger->events } ];
96 }
97  
98 113 ▶ sub slurp_file {
Subroutine slurp_file: called CC=1 SCAR=0.0
Pod undocumented
99 113 my ($self, $filename) = @_;
100  
101 113 Dist::Zilla::Path::path(
102 $self->tempdir->child($filename)
103 )->slurp_utf8;
104 }
105  
106 0 ▶ sub slurp_file_raw {
Subroutine slurp_file_raw: not called CC=1 SCAR=6.9
Pod undocumented
107 0 my ($self, $filename) = @_;
108  
109 0 Dist::Zilla::Path::path(
110 $self->tempdir->child($filename)
111 )->slurp_raw;
112 }
113  
114 151 ▶ sub _metadata_generator_id { 'Dist::Zilla::Tester' }
Subroutine _metadata_generator_id: called CC=1 SCAR=0.0
115  
116 50 ▶ no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
117 }
118  
119 {
120 50 package Dist::Zilla::Tester::_Builder 6.040;
121  
122 50 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
123 50 ▶ use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
124 50 extends 'Dist::Zilla::Dist::Builder';
125 50 with 'Dist::Zilla::Tester::_Role';
126  
127 50 ▶ use File::Copy::Recursive 0.41 qw(dircopy);
Subroutine BEGIN: called CC=1 SCAR=0.0
128 50 ▶ use Dist::Zilla::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
129  
130 50 our $Log_Events = [];
131 0 ▶ sub most_recent_log_events {
Subroutine most_recent_log_events: not called CC=1 SCAR=6.9
Pod undocumented
132 0 return @{ $Log_Events }
133 }
134  
135 177 ▶ around from_config => sub {
Subroutine __ANON__: called CC=15 SCAR=27.3
136 177 my ($orig, $self, $arg, $tester_arg) = @_;
137  
138 177 ▶ confess "dist_root required for from_config" unless $arg->{dist_root};
Branch: 1 branch
BranchTrueFalseTotal
unless $arg->{"dist_root"} 0 177 177
139  
140 177 my $source = $arg->{dist_root};
141  
142 my $tempdir_root = exists $tester_arg->{tempdir_root}
143 ? $tester_arg->{tempdir_root}
144 177 ▶ : 'tmp';
Branch: 1 branch
BranchTrueFalseTotal
exists $tester_arg->{'tempdir_root'} ? : 1 176 177
145  
146 177 ▶ mkdir $tempdir_root if defined $tempdir_root and not -d $tempdir_root;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tempdir_root and not -d $tempdir_root 48 129 177
Condition66%2/3
defined $tempdir_root and not -d $tempdir_root
!ll&&!rl&&r
012948
MC/DC50%1/2
defined $tempdir_root and not -d $tempdir_root
defined $tempdir_root not -d $tempdir_root
Truth table66%2/3
A and not(B)
A= defined $tempdir_rootB= not -d $tempdir_root
ABresult
0X0
100
111
147  
148 177 ▶ my $tempdir_obj = File::Temp->newdir(
Branch: 1 branch
BranchTrueFalseTotal
defined $tempdir_root ? : 177 0 177
149 CLEANUP => 1,
150 (defined $tempdir_root ? (DIR => $tempdir_root) : ()),
151 );
152  
153 177 my $tempdir = path( path($tempdir_obj)->absolute) ;
154  
155 177 my $root = $tempdir->child('source');
156 177 $root->mkpath;
157  
158 177 dircopy($source, $root);
159  
160 177 ▶ if ($tester_arg->{also_copy}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tester_arg->{"also_copy"}) 9 168 177
161 9 ▶ while (my ($src, $dest) = each %{ $tester_arg->{also_copy} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$tester_arg{"also_copy"};}) 12 9 21
162 12 dircopy($src, $tempdir->child($dest));
163 }
164 }
165  
166 177 ▶ if (my $files = $tester_arg->{add_files}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $files = $tester_arg->{"add_files"}) 171 6 177
167 171 ▶ while (my ($name, $content) = each %$files) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$files) 312 171 483
168 312 ▶ die "Unix path '$name' does not seem to be portable to the current OS"
Branch: 1 branch
BranchTrueFalseTotal
unless unix_path_seems_portable($name) 0 312 312
169 if !unix_path_seems_portable($name);
170 312 my $fn = $tempdir->child($name);
171 312 $fn->parent->mkpath;
172 312 Dist::Zilla::Path::path($fn)->spew_utf8($content);
173 }
174 }
175  
176 177 local $arg->{dist_root} = "$root";
177 177 local $arg->{chrome} = Dist::Zilla::Chrome::Test->new;
178  
179 177 $Log_Events = $arg->{chrome}->logger->events;
180  
181 177 local @INC = @INC;
182  
183 177 my $had_dot;
184 177 ▶ if ($INC[-1] eq '.') {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC[-1] eq ".") 177 0 177
185 177 $had_dot = 1;
186 177 pop @INC;
187 }
188  
189 177 ▶ @INC = map {; ref($_) ? $_ : File::Spec->rel2abs($_) } @INC;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 1239 1239
190  
191 177 ▶ push @INC, '.' if $had_dot;
Branch: 1 branch
BranchTrueFalseTotal
if $had_dot 177 0 177
192  
193 # We do this so that . in @INC will find plugins like [=inc::YourFace]
194 # -- rjbs, 2016-04-24
195 177 my $wd = File::pushd::pushd($arg->{dist_root});
196  
197  
198 177 local $ENV{DZIL_GLOBAL_CONFIG_ROOT};
199 $ENV{DZIL_GLOBAL_CONFIG_ROOT} = $tester_arg->{global_config_root}
200 177 ▶ if defined $tester_arg->{global_config_root};
Branch: 1 branch
BranchTrueFalseTotal
if defined $tester_arg->{"global_config_root"} 0 177 177
201  
202 177 my $zilla = $self->$orig($arg);
203  
204 167 $zilla->_set_tempdir_root($tempdir_root);
205 167 $zilla->_set_tempdir_obj($tempdir_obj);
206 167 $zilla->_set_tempdir($tempdir);
207  
208 167 return $zilla;
209 50 };
210  
211 154 ▶ around build_in => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
212 154 my ($orig, $self, $target) = @_;
213  
214 # Sometimes, we can't get a local time zone. When that happens, we're just
215 # going to pretend to be in UTC. We don't do this during actual runtime
216 # because the user can fix their own environment, but we'll let them do
217 # that after they get the software installed. -- rjbs, 2020-01-26
218 154 my $ok = eval { DateTime::TimeZone->new(name => 'local'); 1 };
219 154 ▶ local $ENV{TZ} = $ok ? $ENV{TZ} : 'UTC';
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 11 143 154
220  
221 # XXX: We *must eliminate* the need for this! It's only here because right
222 # now building a dist with (root <> cwd) doesn't work. -- rjbs, 2010-03-08
223 154 my $wd = File::pushd::pushd($self->root);
224  
225 154 ▶ $target ||= do {
Condition66%2/3
$target ||= do { my $target = path($self->tempdir)->child("build"); $target->mkpath; $target }
l!l&&r!l&&!r
11530
MC/DC0%0/2
$target ||= do { my $target = path($self->tempdir)->child("build"); $target->mkpath; $target }
$target do { my $target = path($self->tempdir)->child("build"); $target->mkpath; $target }
Truth table66%2/3
A ||= B
A= $targetB= do { my $target = path($self->tempdir)->child("build"); $target->mkpath; $target }
ABresult
1X1
011
000
226 153 my $target = path($self->tempdir)->child('build');
227 153 $target->mkpath;
228 153 $target;
229 };
230  
231 154 return $self->$orig($target);
232 50 };
233  
234 22 ▶ around ['test', 'release'] => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
235 22 my ($orig, $self) = @_;
236  
237 # XXX: We *must eliminate* the need for this! It's only here because right
238 # now building a dist with (root <> cwd) doesn't work. -- rjbs, 2010-03-08
239 22 my $wd = File::pushd::pushd($self->root);
240  
241 22 return $self->$orig;
242 50 };
243  
244 50 ▶ no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
245  
246 312 ▶ sub unix_path_seems_portable {
Subroutine unix_path_seems_portable: called CC=4 SCAR=26.7
Pod undocumented
247 312 ▶ return 1 if $^O eq "linux"; # this check only makes sense on non-unixes
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "linux" 312 0 312
248  
249 0 my ($unix_path) = @_;
250  
251 # split the $unix_path into 3 strings: $volume, $directories, $file; with:
252 0 my @native_parts = File::Spec->splitpath($unix_path); # current OS rules
253 0 my @unix_parts = File::Spec::Unix->splitpath($unix_path); # unix rules
254 0 ▶ return unless join(qq{\0}, @native_parts) eq join(qq{\0}, @unix_parts);
Branch: 1 branch
BranchTrueFalseTotal
unless join("\0", @native_parts) eq join("\0", @unix_parts) 0 0 0
255  
256 # split the $directories string into a list of the sub-directories; with:
257 0 my @native_dirs = File::Spec->splitdir($native_parts[1]); # current OS rules
258 0 my @unix_dirs = File::Spec::Unix->splitdir($unix_parts[1]); # unix rules
259 0 ▶ return unless join(qq{\0}, @native_dirs) eq join(qq{\0}, @unix_dirs);
Branch: 1 branch
BranchTrueFalseTotal
unless join("\0", @native_dirs) eq join("\0", @unix_dirs) 0 0 0
260  
261 0 return 1;
262 }
263 }
264  
265 {
266 50 package Dist::Zilla::Tester::_Minter 6.040;
267  
268 50 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
269 50 ▶ use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
270 50 extends 'Dist::Zilla::Dist::Minter';
271 50 with 'Dist::Zilla::Tester::_Role';
272  
273 50 ▶ use File::Copy::Recursive 0.41 qw(dircopy);
Subroutine BEGIN: called CC=1 SCAR=0.0
274 50 ▶ use Dist::Zilla::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
275  
276 50 our $Log_Events = [];
277 0 ▶ sub most_recent_log_events {
Subroutine most_recent_log_events: not called CC=1 SCAR=6.9
Pod undocumented
278 0 return @{ $Log_Events }
279 }
280  
281 1 ▶ sub _mint_target_dir {
Subroutine _mint_target_dir: called CC=2 SCAR=7.0
282 1 my ($self) = @_;
283  
284 1 my $name = $self->name;
285 1 my $dir = $self->tempdir->child('mint')->absolute;
286  
287 1 ▶ $self->log_fatal("$dir already exists") if -e $dir;
Branch: 1 branch
BranchTrueFalseTotal
if -e $dir 0 1 1
288  
289 1 return $dir;
290 }
291  
292 1 ▶ sub _setup_global_config {
Subroutine _setup_global_config: called CC=1 SCAR=0.0
293 1 my ($self, $dir, $arg) = @_;
294  
295 1 my $config_base = path($dir)->child('config');
296  
297 1 my $stash_registry = {};
298  
299 1 require Dist::Zilla::MVP::Assembler::GlobalConfig;
300 1 require Dist::Zilla::MVP::Section;
301 my $assembler = Dist::Zilla::MVP::Assembler::GlobalConfig->new({
302 chrome => $arg->{chrome},
303 1 stash_registry => $stash_registry,
304 section_class => 'Dist::Zilla::MVP::Section', # make this DZMA default
305 });
306  
307 1 require Dist::Zilla::MVP::Reader::Finder;
308 1 my $reader = Dist::Zilla::MVP::Reader::Finder->new;
309  
310 1 my $seq = $reader->read_config($config_base, { assembler => $assembler });
311  
312 1 return $stash_registry;
313 }
314  
315 1 ▶ around _new_from_profile => sub {
Subroutine __ANON__: called CC=7 SCAR=20.3
316 1 my ($orig, $self, $profile_data, $arg, $tester_arg) = @_;
317  
318 # Sometimes, we can't get a local time zone. When that happens, we're just
319 # going to pretend to be in UTC. We don't do this during actual runtime
320 # because the user can fix their own environment, but we'll let them do
321 # that after they get the software installed. -- rjbs, 2020-01-26
322 0 my $ok = eval { DateTime::TimeZone->new(name => 'local'); 1 };
323 1 ▶ local $ENV{TZ} = $ok ? $ENV{TZ} : 'UTC';
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 0 1 1
324  
325 my $tempdir_root = exists $tester_arg->{tempdir_root}
326 ? $tester_arg->{tempdir_root}
327 1 ▶ : 'tmp';
Branch: 1 branch
BranchTrueFalseTotal
exists $tester_arg->{'tempdir_root'} ? : 0 1 1
328  
329 1 ▶ mkdir $tempdir_root if defined $tempdir_root and not -d $tempdir_root;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tempdir_root and not -d $tempdir_root 0 1 1
Condition33%1/3
defined $tempdir_root and not -d $tempdir_root
!ll&&!rl&&r
010
MC/DC0%0/2
defined $tempdir_root and not -d $tempdir_root
defined $tempdir_root not -d $tempdir_root
Truth table33%1/3
A and not(B)
A= defined $tempdir_rootB= not -d $tempdir_root
ABresult
0X0
100
111
330  
331 1 ▶ my $tempdir_obj = File::Temp->newdir(
Branch: 1 branch
BranchTrueFalseTotal
defined $tempdir_root ? : 1 0 1
332 CLEANUP => 1,
333 (defined $tempdir_root ? (DIR => $tempdir_root) : ()),
334 );
335 1 my $tempdir = path($tempdir_obj)->absolute;
336  
337 1 local $arg->{chrome} = Dist::Zilla::Chrome::Test->new;
338 1 $Log_Events = $arg->{chrome}->logger->events;
339  
340 1 ▶ local @INC = map {; ref($_) ? $_ : File::Spec->rel2abs($_) } @INC;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 9 9
341  
342 1 my $global_config_root = path($tester_arg->{global_config_root})->absolute;
343  
344 1 local $ENV{DZIL_GLOBAL_CONFIG_ROOT} = $global_config_root;
345  
346 my $global_stashes = $self->_setup_global_config(
347 $global_config_root,
348 { chrome => $arg->{chrome} },
349 1 );
350  
351 1 local $arg->{_global_stashes} = $global_stashes;
352  
353 1 my $zilla = $self->$orig($profile_data, $arg);
354  
355 1 $zilla->_set_tempdir_root($tempdir_root);
356 1 $zilla->_set_tempdir_obj($tempdir_obj);
357 1 $zilla->_set_tempdir($tempdir);
358  
359 1 return $zilla;
360 50 };
361 }
362  
363 50 ▶no Moose; # XXX: namespace::autoclean caused problems -- rjbs, 2011-08-19
Subroutine BEGIN: called CC=1 SCAR=0.0
364 50 __PACKAGE__->meta->make_immutable;
365 50 1;
366  
367 __END__
« blib/lib/Dist/Zilla/Role/FileFinderUser.pm ↑ Summary blib/lib/Dist/Zilla/Role/PPI.pm »