blib/lib/Module/Install/StandardTests.pm

filter: Statementstmt 29.7% 14 / 47 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 4 / 10 Podpod 100% 6 / 6 totaltotal 31.1% 24 / 77 CC 9 SCAR 32.0
CC
9
Cov
23%
use_standard_tests
56.0
write_test_file
12.0
write_standard_test_compile
2.0
CRAP 24.4
↑ Summary
1 package Module::Install::StandardTests;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use base 'Module::Install::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 1 our $VERSION = '0.05';
11  
12  
13 0 ▶sub use_standard_tests {
Subroutine use_standard_tests: not called CC=7 SCAR=40.3
Pod documented
14 0 my ($self, %specs) = @_;
15
16 0 my %with = map { $_ => 1 } qw/compile pod pod_coverage perl_critic/;
17 0 ▶ if (exists $specs{without}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $specs{"without"}) 0 0 0
18 0 ▶ $specs{without} = [ $specs{without} ] unless ref $specs{without};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $specs{"without"} 0 0 0
19 0 delete $with{$_} for @{ $specs{without} };
20 }
21  
22 0 $self->build_requires('Test::More');
23 0 $self->build_requires('UNIVERSAL::require');
24  
25 # Unlike other tests, this is mandatory.
26 0 $self->build_requires('Test::Compile');
27  
28 0 $self->write_standard_test_compile; # no if; this is mandatory
29 0 ▶ $self->write_standard_test_pod if $with{pod};
Branch: 1 branch
BranchTrueFalseTotal
if $with{"pod"} 0 0 0
30 0 ▶ $self->write_standard_test_pod_coverage if $with{pod_coverage};
Branch: 1 branch
BranchTrueFalseTotal
if $with{"pod_coverage"} 0 0 0
31 0 ▶ $self->write_standard_test_perl_critic if $with{perl_critic};
Branch: 1 branch
BranchTrueFalseTotal
if $with{"perl_critic"} 0 0 0
32 }
33  
34  
35 0 ▶sub write_test_file {
Subroutine write_test_file: not called CC=3 SCAR=24.8
Pod documented
36 0 my ($self, $filename, $code) = @_;
37 0 $filename = File::Spec->catfile('t', $filename);
38  
39 # Outdent the code somewhat. Remove first empty line, if any. Then
40 # determine the indent of the first line. Throw that amount of indenting
41 # away from any line. This allows you to indent the code so it's visually
42 # clearer (see methods below) while creating output that's indented more
43 # or less correctly. Smoke result HTML pages link to the .t files, so it
44 # looks neater.
45  
46 0 $code =~ s/^ *\n//;
47 0 (my $indent = $code) =~ s/^( *).*/$1/s;
48 0 $code =~ s/^$indent//gm;
49  
50 0 print "Creating $filename\n";
51 0 ▶ open(my $fh, ">$filename") or die "can't create $filename $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">$filename" or die "can't create $filename $!" 0 0 0
52  
53 0 my $perl = $^X;
54 0 print $fh <<TEST;
55 #!$perl -w
56  
57 use strict;
58 use warnings;
59  
60 $code
61 TEST
62  
63 0 ▶ close $fh or die "can't close $filename $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "can't close $filename $!\n" 0 0 0
64 0 $self->realclean_files($filename);
65 }
66  
67  
68 0 ▶sub write_standard_test_compile {
Subroutine write_standard_test_compile: not called CC=1 SCAR=6.9
Pod documented
69 0 my $self = shift;
70 0 $self->write_test_file('000_standard__compile.t', q/
71 BEGIN {
72 use Test::More;
73 eval "use Test::Compile";
74 Test::More->builder->BAIL_OUT(
75 "Test::Compile required for testing compilation") if $@;
76 all_pm_files_ok();
77 }
78 /);
79 }
80  
81  
82 0 ▶sub write_standard_test_pod {
Subroutine write_standard_test_pod: not called CC=1 SCAR=6.9
Pod documented
83 0 my $self = shift;
84 0 $self->write_test_file('000_standard__pod.t', q/
85 use Test::More;
86 eval "use Test::Pod";
87 plan skip_all => "Test::Pod required for testing POD" if $@;
88 all_pod_files_ok();
89 /);
90 }
91  
92  
93 0 ▶sub write_standard_test_pod_coverage {
Subroutine write_standard_test_pod_coverage: not called CC=1 SCAR=6.9
Pod documented
94 0 my $self = shift;
95 0 $self->write_test_file('000_standard__pod_coverage.t', q/
96 use Test::More;
97 eval "use Test::Pod::Coverage";
98 plan skip_all =>
99 "Test::Pod::Coverage required for testing POD coverage" if $@;
100 all_pod_coverage_ok();
101 /);
102 }
103  
104  
105 0 ▶sub write_standard_test_perl_critic {
Subroutine write_standard_test_perl_critic: not called CC=1 SCAR=6.9
Pod documented
106 0 my $self = shift;
107 0 $self->write_test_file('000_standard__perl_critic.t', q/
108 use FindBin '$Bin';
109 use File::Spec;
110 use UNIVERSAL::require;
111 use Test::More;
112  
113 plan skip_all =>
114 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.'
115 unless $ENV{TEST_AUTHOR};
116  
117 my %opt;
118 my $rc_file = File::Spec->catfile($Bin, 'perlcriticrc');
119 $opt{'-profile'} = $rc_file if -r $rc_file;
120  
121 if (Perl::Critic->require('1.078') &&
122 Test::Perl::Critic->require &&
123 Test::Perl::Critic->import(%opt)) {
124  
125 all_critic_ok("lib");
126 } else {
127 plan skip_all => $@;
128 }
129 /);
130 }
131  
132  
133 1 1;
134  
135 __END__
↑ Summary