blib/lib/Dist/Zilla/Plugin/Author/Plicease/Tests.pm

filter: Statementstmt 96.6% 86 / 89 Branchbran 83.3% 20 / 24 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 5 totaltotal 87.4% 125 / 143 CC 21 SCAR 21.8
CC
21
Cov
92%
setup_installer
16.0
test
8.1
gather_files
2.0
CRAP 8.8
« blib/lib/Dist/Zilla/Plugin/Author/Plicease/ReadmeAnyFromPod.pm ↑ Summary example/unbundle.pl »
1 2 package Dist::Zilla::Plugin::Author::Plicease::Tests 2.81 {
2  
3 2 ▶ use 5.022;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶ use File::chdir;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶ use File::Path qw( make_path );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶ use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶ use Sub::Exporter::ForMethods qw( method_installer );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶ use Data::Section { installer => method_installer }, -setup;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶ use experimental qw( postderef );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ABSTRACT: add author only release tests to xt/release
13  
14  
15 2 with 'Dist::Zilla::Role::FileGatherer';
16 2 with 'Dist::Zilla::Role::BeforeBuild';
17 2 with 'Dist::Zilla::Role::InstallTool';
18 2 with 'Dist::Zilla::Role::TestRunner';
19  
20 9 ▶ sub mvp_multivalue_args { qw( diag diag_preamble ) }
Subroutine mvp_multivalue_args: called CC=1 SCAR=0.0
Pod undocumented
21  
22 has diag => (
23 is => 'ro',
24 7 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
25 2 );
26  
27 has diag_preamble => (
28 is => 'ro',
29 8 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
30 2 );
31  
32 2 has _diag_content => (
33 is => 'rw',
34 isa => 'Str',
35 default => '',
36 );
37  
38 2 has test2_v0 => (
39 is => 'ro',
40 isa => 'Int',
41 default => 0,
42 );
43  
44 sub gather_files
45 9 ▶ {
Subroutine gather_files: called CC=2 SCAR=6.9
Pod undocumented
46 9 my($self) = @_;
47  
48 9 require Dist::Zilla::File::InMemory;
49  
50 $self->add_file(
51 Dist::Zilla::File::InMemory->new(
52 name => $_,
53 90 content => ${ $self->section_data($_) },
54 )
55 9 ) for qw( xt/author/strict.t
56 xt/author/eol.t
57 xt/author/pod.t
58 xt/author/no_tabs.t
59 xt/author/pod_coverage.t
60 xt/author/pod_spelling_common.t
61 xt/author/pod_spelling_system.t
62 xt/author/version.t
63 xt/release/changes.t
64 xt/release/fixme.t );
65 }
66  
67 sub before_build
68 9 ▶ {
Subroutine before_build: called CC=2 SCAR=6.9
Pod undocumented
69 9 my($self) = @_;
70 9 ▶ my $content = ${ $self->section_data( $self->test2_v0 ? 't/00_xdiag.t' : 't/00_diag.t' ) };
Branch: 1 branch
BranchTrueFalseTotal
$self->test2_v0 ? : 1 8 9
71 9 $content =~ s{## PREAMBLE ##}{join "\n", map { s/^\| //; $_ } $self->diag_preamble->@*}e;
72 9 $self->_diag_content($content);
73 }
74  
75 # not really an installer, but we have to create a list
76 # of the prereqs / suggested modules after the prereqs
77 # have been calculated
78 sub setup_installer
79 9 ▶ {
Subroutine setup_installer: called CC=16 SCAR=27.7
Pod undocumented
80 9 my($self) = @_;
81  
82 9 my %list;
83 9 my $prereqs = $self->zilla->prereqs->as_string_hash;
84 9 foreach my $phase (keys %$prereqs)
85 {
86 6 ▶ next if $phase eq 'develop';
Branch: 1 branch
BranchTrueFalseTotal
if $phase eq "develop" 1 5 6
87 5 foreach my $type (keys $prereqs->{$phase}->%*)
88 {
89 5 foreach my $module (keys $prereqs->{$phase}->{$type}->%*)
90 {
91 11 ▶ next if $module =~ /^(perl|strict|warnings|base)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $module =~ /^(perl|strict|warnings|base)$/u 4 7 11
92 7 $list{$module}++;
93 }
94 }
95 }
96  
97 9 ▶ if($list{'JSON::MaybeXS'})
Branch: 1 branch
BranchTrueFalseTotal
if ($list{"JSON::MaybeXS"}) 1 8 9
98 {
99 1 $list{'JSON::PP'}++;
100 1 $list{'JSON::XS'}++;
101 }
102  
103 9 ▶ if(my($alien) = grep { $_->isa('Dist::Zilla::Plugin::Alien') } $self->zilla->plugins->@*)
Branch: 1 branch
BranchTrueFalseTotal
if (my($alien) = grep({$_->isa("Dist::Zilla::Plugin::Alien");} @{$self->zilla->plugins})) 0 9 9
104 {
105 0 $list{$_}++ foreach keys $alien->module_build_args->{alien_bin_requires}->%*;
106 }
107  
108 9 foreach my $lib ($self->diag->@*)
109 {
110 4 ▶ if($lib =~ /^-(.*)$/)
Branch: 2 branches
BranchTrueFalseTotal
if ($lib =~ /^-(.*)$/u) { } 1 3 4
elsif ($lib =~ /^\+(.*)$/u) { } 2 1 3
111 {
112 1 delete $list{$1};
113 }
114 elsif($lib =~ /^\+(.*)$/)
115 {
116 2 $list{$1}++;
117 }
118 else
119 {
120 1 $self->log_fatal('diagnostic override must be prefixed with + or -');
121 }
122 }
123  
124 8 my $code = '';
125  
126 8 ▶ $code = "BEGIN { eval { require 'EV.pm'; } }\n" if $list{EV};
Branch: 1 branch
BranchTrueFalseTotal
if $list{"EV"} 1 7 8
127 8 $code .= '$modules{$_} = $_ for qw(' . "\n";
128 8 $code .= join "\n", map { " $_" } sort keys %list;
129 8 $code .= "\n);\n";
130 8 ▶ $code .= "eval { require 'Test/Tester.pm'; };" if $list{'Test::Builder'} && $list{'Test::Tester'};
Branch: 1 branch
BranchTrueFalseTotal
if $list{"Test::Builder"} and $list{"Test::Tester"} 1 7 8
Condition66%2/3
$list{"Test::Builder"} and $list{"Test::Tester"}
!ll&&!rl&&r
701
MC/DC50%1/2
$list{"Test::Builder"} and $list{"Test::Tester"}
$list{"Test::Builder"} $list{"Test::Tester"}
Truth table66%2/3
A and B
A= $list{"Test::Builder"}B= $list{"Test::Tester"}
ABresult
0X0
100
111
131  
132 8 my($file) = grep { $_->name eq 't/00_diag.t' } $self->zilla->files->@*;
133  
134 8 my $content = $self->_diag_content;
135 8 $content =~ s{## GENERATE ##}{$code};
136  
137 8 ▶ if($file)
Branch: 1 branch
BranchTrueFalseTotal
if ($file) { } 1 7 8
138 {
139 1 $file->content($content);
140 }
141 else
142 {
143 7 $file = Dist::Zilla::File::InMemory->new({
144 name => 't/00_diag.t',
145 content => $content
146 });
147 7 $self->add_file($file);
148 }
149  
150 8 $self->zilla->root->child(qw( t 00_diag.t ))->touchpath->spew_raw($content);
151 }
152  
153 sub test
154 1 ▶ {
Subroutine test: called CC=4 SCAR=20.9
Pod undocumented
155 1 my($self, $target) = @_;
156 1 ▶ return if defined $ENV{CI} && $ENV{CI} =~ /^true$/i;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"CI"} and $ENV{"CI"} =~ /^true$/iu 1 0 1
Condition33%1/3
defined $ENV{"CI"} and $ENV{"CI"} =~ /^true$/iu
!ll&&!rl&&r
001
MC/DC0%0/2
defined $ENV{"CI"} and $ENV{"CI"} =~ /^true$/iu
defined $ENV{"CI"} $ENV{"CI"} =~ /^true$/iu
Truth table33%1/3
A and B
A= defined $ENV{"CI"}B= $ENV{"CI"} =~ /^true$/iu
ABresult
0X0
100
111
157 0 system 'prove', '-br', 'xt';
158 0 ▶ $self->log_fatal('release test failure') unless $? == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $? == 0 0 0 0
159 }
160  
161 2 __PACKAGE__->meta->make_immutable;
162  
163 }
164  
165 2 1;
166  
167  
168 package Dist::Zilla::Plugin::Author::Plicease::Tests;
169  
170 =pod
171  
172 =encoding UTF-8
173  
174 =head1 NAME
175  
176 Dist::Zilla::Plugin::Author::Plicease::Tests - add author only release tests to xt/release
177  
178 =head1 VERSION
179  
180 version 2.81
181  
182 =head1 SYNOPSIS
183  
184 [Author::Plicease::Tests]
185 diag = +Acme::Override::INET
186 diag = +IO::Socket::INET
187 diag = +IO::SOCKET::IP
188 diag = -EV
189  
190 =head1 SEE ALSO
191  
192 =over 4
193  
194 =item L<Dist::Zilla>
195  
196 =item L<Dist::Zilla::PluginBundle::Author::Plicease>
197  
198 =back
199  
200 =head1 AUTHOR
201  
202 Graham Ollis <plicease@cpan.org>
203  
204 =head1 COPYRIGHT AND LICENSE
205  
206 This software is copyright (c) 2012-2024 by Graham Ollis.
207  
208 This is free software; you can redistribute it and/or modify it under
209 the same terms as the Perl 5 programming language system itself.
210  
211 =cut
212  
213 __DATA__
« blib/lib/Dist/Zilla/Plugin/Author/Plicease/ReadmeAnyFromPod.pm ↑ Summary example/unbundle.pl »