blib/lib/Dist/Zilla/Plugin/ExtraTests.pm

filter: Statementstmt 100% 30 / 30 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 95.3% 41 / 43 CC 3 SCAR 3.4
CC
3
Cov
97%
_rewrite
2.0
munge_file
2.0
BEGIN
1.0
CRAP 1.4
« blib/lib/Dist/Zilla/Plugin/Manifest.pm ↑ Summary blib/lib/Dist/Zilla/Types.pm »
1 package Dist::Zilla::Plugin::ExtraTests 6.040;
2 # ABSTRACT: rewrite ./xt tests to ./t tests with skips
3  
4 11 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 with 'Dist::Zilla::Role::FileMunger';
6  
7 11 ▶use Dist::Zilla::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 11 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 #pod =head1 DESCRIPTION
12 #pod
13 #pod This plugin rewrites tests found in the following directories:
14 #pod
15 #pod ./xt/author - tests for author testing (env AUTHOR_TESTING is true)
16 #pod ./xt/release - tests for pre-release testers (env RELEASE_TESTING is true)
17 #pod ./xt/smoke - tests for automated testers (env AUTOMATED_TESTING is true)
18 #pod
19 #pod The tests are renamed and moved to F<./t>, and they are rewritten to include
20 #pod some simple Perl code to skip all included tests if the correct env vars are
21 #pod not set.
22 #pod
23 #pod =cut
24  
25 84 ▶sub munge_file {
Subroutine munge_file: called CC=2 SCAR=6.9
Pod undocumented
26 84 my ($self, $file) = @_;
27  
28 84 ▶ return unless $file->name =~ m{\Axt/(smoke|author|release)/.+\.t\z};
Branch: 1 branch
BranchTrueFalseTotal
unless $file->name =~ m[\Axt/(smoke|author|release)/.+\.t\z]u 64 20 84
29 20 my $method = "_rewrite_$1\_test";
30  
31 20 $self->log("rewriting $1 test " . $file->name);
32  
33 20 $self->$method($file);
34 }
35  
36 1 ▶sub _rewrite_smoke_test {
Subroutine _rewrite_smoke_test: called CC=1 SCAR=0.0
37 1 my ($self, $file) = @_;
38 1 $self->_rewrite($file, 'AUTOMATED_TESTING', '"smoke bot" testing');
39 }
40  
41 18 ▶sub _rewrite_author_test {
Subroutine _rewrite_author_test: called CC=1 SCAR=0.0
42 18 my ($self, $file) = @_;
43 18 $self->_rewrite($file, 'AUTHOR_TESTING', 'testing by the author');
44 }
45  
46 1 ▶sub _rewrite_release_test {
Subroutine _rewrite_release_test: called CC=1 SCAR=0.0
47 1 my ($self, $file) = @_;
48 1 $self->_rewrite($file, 'RELEASE_TESTING', 'release candidate testing');
49 }
50  
51 20 ▶sub _rewrite {
Subroutine _rewrite: called CC=2 SCAR=7.0
52 20 my ($self, $file, $env, $msg) = @_;
53  
54 20 my $name = $file->name =~ s{^xt/([^/]+)/}{t/$1-}r;
55  
56 20 $file->name($name);
57  
58 20 my @lines = split /\n/, $file->content;
59 20 ▶ my $after = $lines[0] =~ /\A#!/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$lines[0] =~ /\A#!/u ? : 20 0 20
60 20 splice @lines, $after, 0, qq|
61 BEGIN {
62 unless (\$ENV{$env}) {
63 print qq{1..0 # SKIP these tests are for $msg\\n};
64 exit
65 }
66 }
67 |;
68  
69 20 $file->content(join "\n", @lines, '');
70 }
71  
72 11 __PACKAGE__->meta->make_immutable;
73 11 1;
74  
75 __END__
« blib/lib/Dist/Zilla/Plugin/Manifest.pm ↑ Summary blib/lib/Dist/Zilla/Types.pm »