blib/lib/Test/NewVersion.pm

filter: Statementstmt 95.8% 92 / 96 Branchbran 66.6% 20 / 30 Conditioncond 57.1% 12 / 21 MC/DCmcdc 25.0% 3 / 12 Subroutinesub 100% 22 / 22 Podpod 100% 2 / 2 totaltotal 82.5% 151 / 183 CC 25 SCAR 17.0
CC
25
Cov
84%
_version_is_bumped
12.7
END
7.5
new_version_ok
4.1
CRAP 5.5
↑ Summary
1 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Test::NewVersion; # git description: v0.002-7-g29dae93
4 # ABSTRACT: provides a test interface for checking that you are using a new $VERSION
5 # KEYWORDS: test distribution release author version unique new
6 # vim: set ts=8 sts=4 sw=4 tw=78 et :
7  
8 3 our $VERSION = '0.003';
9  
10 3 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 our @EXPORT = qw(all_new_version_ok new_version_ok);
12  
13 3 ▶use File::Find ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use version ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Module::Metadata;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use CPAN::Meta 2.120920;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use Test::Builder 0.88;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 3 my $no_plan;
25  
26 sub import
27 3 ▶{
Subroutine import: called CC=1 SCAR=0.0
28 # END block will check for this status
29 3 my @symbols = grep { $_ ne ':no_plan' } @_;
30 3 $no_plan = (@symbols != @_);
31  
32 3 __PACKAGE__->export_to_level(1, @symbols);
33 }
34  
35 # for testing this module only!
36 my $tb;
37 sub _builder(;$)
38 3 ▶{
Subroutine _builder: called CC=3 SCAR=13.3
39 3 ▶ if (not @_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 3 0 3
40 {
41 3 ▶ $tb ||= Test::Builder->new;
Condition33%1/3
$tb ||= "Test::Builder"->new
l!l&&r!l&&!r
030
MC/DC0%0/2
$tb ||= "Test::Builder"->new
$tb "Test::Builder"->new
Truth table33%1/3
A ||= B
A= $tbB= "Test::Builder"->new
ABresult
1X1
011
000
42 3 return $tb;
43 }
44  
45 0 $tb = shift;
46 }
47  
48 3 ▶END {
Subroutine END: called CC=4 SCAR=20.1
49 3 ▶ if (not $no_plan
Branch: 1 branch
BranchTrueFalseTotal
if (not $no_plan || &_builder()->expected_tests and &_builder()->current_test > 0) 0 3 3
Condition33%2/6
not $no_plan || &_builder()->expected_tests and &_builder()->current_test > 0
!ll&&!rl&&r
300
$no_plan || &_builder()->expected_tests
l!l&&r!l&&!r
030
MC/DC0%0/3
not $no_plan || &_builder()->expected_tests and &_builder()->current_test > 0
$no_plan &_builder()->expected_tests &_builder()->current_test > 0
Truth table25%1/4
not(A || B) and C
A= $no_planB= &_builder()->expected_testsC= &_builder()->current_test > 0
ABCresult
1XX0
01X0
0000
0011
50 and not _builder->expected_tests
51 # skip this if no tests have been run (e.g. compilation tests of this module!)
52 and (_builder->current_test > 0)
53 )
54 {
55 0 _builder->done_testing;
56 }
57 }
58  
59  
60 sub all_new_version_ok
61 3 ▶{
Subroutine all_new_version_ok: called CC=3 SCAR=11.1
Pod documented
62 # find all files in blib or lib
63 3 my @files;
64 3 my @lib_dirs = grep { -d } qw(blib/lib lib);
65  
66 File::Find::find(
67 {
68 16 ▶ wanted => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
69 16 ▶ push @files, File::Spec->no_upwards($File::Find::name)
Branch: 1 branch
BranchTrueFalseTotal
if -r $File::Find::name and $File::Find::name =~ /\.pm$/ or $File::Find::name =~ /\.pod$/ 9 7 16
Condition83%5/6
-r $File::Find::name and $File::Find::name =~ /\.pm$/ or $File::Find::name =~ /\.pod$/
l!l&&r!l&&!r
727
-r $File::Find::name and $File::Find::name =~ /\.pm$/
!ll&&!rl&&r
097
MC/DC66%2/3
-r $File::Find::name and $File::Find::name =~ /\.pm$/ or $File::Find::name =~ /\.pod$/
-r $File::Find::name $File::Find::name =~ /\.pm$/ $File::Find::name =~ /\.pod$/
Truth table60%3/5
A and B or C
A= -r $File::Find::nameB= $File::Find::name =~ /\.pm$/C= $File::Find::name =~ /\.pod$/
ABCresult
11X1
0X11
1011
0X00
1000
70 if -r $File::Find::name
71 and $File::Find::name =~ /\.pm$/ or $File::Find::name =~ /\.pod$/;
72 },
73 3 ▶ no_chdir => 1,
Branch: 1 branch
BranchTrueFalseTotal
if @lib_dirs 3 0 3
74 },
75 $lib_dirs[0],
76 ) if @lib_dirs;
77  
78 # also add .pod, .pm files in the top level directory
79 0 ▶ push @files, grep { -f } glob('*.pod'), glob('*.pm');
Subroutine BEGIN: called CC=1 SCAR=0.1
80  
81 3 new_version_ok($_) foreach sort @files;
82 }
83  
84 sub new_version_ok
85 9 ▶{
Subroutine new_version_ok: called CC=4 SCAR=14.0
Pod documented
86 9 my $filename = shift;
87  
88 9 my $builder = Test::Builder->new;
89  
90 9 my $module_metadata = Module::Metadata->new_from_file($filename);
91 9 foreach my $pkg ($module_metadata->packages_inside)
92 {
93 8 ▶ next if $pkg eq 'main';
Branch: 1 branch
BranchTrueFalseTotal
if $pkg eq "main" 0 8 8
94 8 my ($bumped, $message) = _version_is_bumped($module_metadata, $pkg);
95  
96 8 local $Test::Builder::Level = $Test::Builder::Level + 1;
97 8 ▶ $builder->ok($bumped, $pkg . ' (' . $filename . ') VERSION is ok'
Branch: 1 branch
BranchTrueFalseTotal
$message ? : 8 0 8
98 . ( $message ? (' (' . $message . ')') : '' )
99 );
100 }
101 }
102  
103 # 'provides' field from dist metadata, if needed
104 3 my $dist_provides;
105  
106 # returns bool, detailed message
107 sub _version_is_bumped
108 8 ▶{
Subroutine _version_is_bumped: called CC=12 SCAR=25.4
109 8 my ($module_metadata, $pkg) = @_;
110  
111 8 my $res = HTTP::Tiny->new->get("http://cpanidx.org/cpanidx/json/mod/$pkg");
112 8 ▶ return (0, 'index could not be queried?') if not $res->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"success"} 0 8 8
113  
114 8 my $data = $res->{content};
115  
116 8 require HTTP::Headers;
117 8 ▶ if (my $charset = HTTP::Headers->new(%{ $res->{headers} })->content_type_charset)
Branch: 1 branch
BranchTrueFalseTotal
if (my $charset = "HTTP::Headers"->new(%{$$res{"headers"};})->content_type_charset) 0 8 8
118 {
119 0 $data = Encode::decode($charset, $data, Encode::FB_CROAK);
120 }
121  
122 8 my $payload = JSON::MaybeXS::decode_json($data);
123 8 ▶ return (0, 'invalid payload returned') unless $payload;
Branch: 1 branch
BranchTrueFalseTotal
unless $payload 0 8 8
124 8 ▶ return (1, 'not indexed') if not defined $payload->[0]{mod_vers};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $payload->[0]{"mod_vers"} 4 4 8
125 4 ▶ return (1, 'VERSION is not set in index') if $payload->[0]{mod_vers} eq 'undef';
Branch: 1 branch
BranchTrueFalseTotal
if $payload->[0]{"mod_vers"} eq "undef" 1 3 4
126  
127 3 my $indexed_version = version->parse($payload->[0]{mod_vers});
128 3 my $current_version = $module_metadata->version($pkg);
129  
130 3 ▶ if (not defined $current_version)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $current_version) 2 1 3
131 {
132 2 ▶ $dist_provides ||= do {
Condition66%2/3
$dist_provides ||= do { my $metafile = &List::Util::first(sub { -e $_; } , "MYMETA.json", "MYMETA.yml", "META.json", "META.yml"); my $dist_metadata = $metafile ? "CPAN::Meta"->load_file($metafile) : undef; $dist_metadata->provides if $dist_metadata }
l!l&&r!l&&!r
110
MC/DC0%0/2
$dist_provides ||= do { my $metafile = &List::Util::first(sub { -e $_; } , "MYMETA.json", "MYMETA.yml", "META.json", "META.yml"); my $dist_metadata = $metafile ? "CPAN::Meta"->load_file($metafile) : undef; $dist_metadata->provides if $dist_metadata }
$dist_provides do { my $metafile = &List::Util::first(sub { -e $_; } , "MYMETA.json", "MYMETA.yml", "META.json", "META.yml"); my $dist_metadata = $metafile ? "CPAN::Meta"->load_file($metafile) : undef; $dist_metadata->provides if $dist_metadata }
Truth table66%2/3
A ||= B
A= $dist_providesB= do { my $metafile = &List::Util::first(sub { -e $_; } , "MYMETA.json", "MYMETA.yml", "META.json", "META.yml"); my $dist_metadata = $metafile ? "CPAN::Meta"->load_file($metafile) : undef; $dist_metadata->provides if $dist_metadata }
ABresult
1X1
011
000
133 1 ▶ my $metafile = List::Util::first { -e $_ } qw(MYMETA.json MYMETA.yml META.json META.yml);
Subroutine __ANON__: called CC=1 SCAR=0.0
134 1 ▶ my $dist_metadata = $metafile ? CPAN::Meta->load_file($metafile) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$metafile ? : 1 0 1
135 1 ▶ $dist_metadata->provides if $dist_metadata;
Branch: 1 branch
BranchTrueFalseTotal
if $dist_metadata 1 0 1
136 };
137  
138 2 $current_version = $dist_provides->{$pkg}{version};
139 2 ▶ return (0, 'VERSION is not set; indexed version is ' . $indexed_version)
Branch: 1 branch
BranchTrueFalseTotal
unless $dist_provides and $current_version 1 1 2
Condition66%2/3
$dist_provides and $current_version
!ll&&!rl&&r
011
MC/DC50%1/2
$dist_provides and $current_version
$dist_provides $current_version
Truth table66%2/3
A and B
A= $dist_providesB= $current_version
ABresult
0X0
100
111
140 if not $dist_provides or not $current_version;
141 }
142  
143 return (
144 2 $indexed_version < $current_version,
145 'indexed at ' . $indexed_version . '; local version is ' . $current_version,
146 );
147 }
148  
149 3 1;
150  
151 __END__
↑ Summary