|
0 |
#!perl
|
|
1 |
|
|
2 |
use strict;
|
|
3 |
use warnings;
|
|
4 |
|
|
5 |
# This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.020
|
|
6 |
# THEN modified with more info by Ed J for PDL project
|
|
7 |
|
|
8 |
use Test::More tests => 1;
|
|
9 |
|
|
10 |
use ExtUtils::MakeMaker;
|
|
11 |
use File::Spec;
|
|
12 |
|
|
13 |
# from $version::LAX
|
|
14 |
my $lax_version_re =
|
|
15 |
qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )?
|
|
16 |
|
|
|
17 |
(?:\.[0-9]+) (?:_[0-9]+)?
|
|
18 |
) | (?:
|
|
19 |
v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )?
|
|
20 |
|
|
|
21 |
(?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)?
|
|
22 |
)
|
|
23 |
)/x;
|
|
24 |
|
|
25 |
# hide optional CPAN::Meta modules from prereq scanner
|
|
26 |
# and check if they are available
|
|
27 |
my $cpan_meta = "CPAN::Meta";
|
|
28 |
my $cpan_meta_pre = "CPAN::Meta::Prereqs";
|
|
29 |
my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic
|
|
30 |
|
|
31 |
# Verify requirements?
|
|
32 |
my $DO_VERIFY_PREREQS = 1;
|
|
33 |
|
|
34 |
sub _max {
|
|
35 |
my $max = shift;
|
|
36 |
$max = ( $_ > $max ) ? $_ : $max for @_;
|
|
37 |
return $max;
|
|
38 |
}
|
|
39 |
|
|
40 |
sub _merge_prereqs {
|
|
41 |
my ($collector, $prereqs) = @_;
|
|
42 |
|
|
43 |
# CPAN::Meta::Prereqs object
|
|
44 |
if (ref $collector eq $cpan_meta_pre) {
|
|
45 |
return $collector->with_merged_prereqs(
|
|
46 |
CPAN::Meta::Prereqs->new( $prereqs )
|
|
47 |
);
|
|
48 |
}
|
|
49 |
|
|
50 |
# Raw hashrefs
|
|
51 |
for my $phase ( keys %$prereqs ) {
|
|
52 |
for my $type ( keys %{ $prereqs->{$phase} } ) {
|
|
53 |
for my $module ( keys %{ $prereqs->{$phase}{$type} } ) {
|
|
54 |
$collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module};
|
|
55 |
}
|
|
56 |
}
|
|
57 |
}
|
|
58 |
|
|
59 |
return $collector;
|
|
60 |
}
|
|
61 |
|
|
62 |
my @include = qw(
|
|
63 |
|
|
64 |
);
|
|
65 |
|
|
66 |
my @exclude = qw(
|
|
67 |
|
|
68 |
);
|
|
69 |
|
|
70 |
# Add static prereqs to the included modules list
|
|
71 |
my $static_prereqs = do 't/00-report-prereqs.dd';
|
|
72 |
|
|
73 |
# Merge all prereqs (either with ::Prereqs or a hashref)
|
|
74 |
my $full_prereqs = _merge_prereqs(
|
|
75 |
( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ),
|
|
76 |
$static_prereqs
|
|
77 |
);
|
|
78 |
|
|
79 |
# Add dynamic prereqs to the included modules list (if we can)
|
|
80 |
my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml';
|
|
81 |
if ( $source && $HAS_CPAN_META ) {
|
|
82 |
if ( my $meta = eval { CPAN::Meta->load_file($source) } ) {
|
|
83 |
$full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs);
|
|
84 |
}
|
|
85 |
}
|
|
86 |
else {
|
|
87 |
$source = 'static metadata';
|
|
88 |
}
|
|
89 |
|
|
90 |
my @full_reports;
|
|
91 |
my @dep_errors;
|
|
92 |
my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs;
|
|
93 |
|
|
94 |
# Add static includes into a fake section
|
|
95 |
for my $mod (@include) {
|
|
96 |
$req_hash->{other}{modules}{$mod} = 0;
|
|
97 |
}
|
|
98 |
|
|
99 |
for my $phase ( qw(configure build test runtime develop other) ) {
|
|
100 |
next unless $req_hash->{$phase};
|
|
101 |
next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING});
|
|
102 |
|
|
103 |
for my $type ( qw(requires recommends suggests conflicts modules) ) {
|
|
104 |
next unless $req_hash->{$phase}{$type};
|
|
105 |
|
|
106 |
my $title = ucfirst($phase).' '.ucfirst($type);
|
|
107 |
my @reports = [qw/Module Want Have Where Howbig/];
|
|
108 |
|
|
109 |
for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) {
|
|
110 |
next if $mod eq 'perl';
|
|
111 |
next if grep { $_ eq $mod } @exclude;
|
|
112 |
|
|
113 |
my $file = $mod;
|
|
114 |
$file =~ s{::}{/}g;
|
|
115 |
$file .= ".pm";
|
|
116 |
my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC;
|
|
117 |
|
|
118 |
my $want = $req_hash->{$phase}{$type}{$mod};
|
|
119 |
$want = "undef" unless defined $want;
|
|
120 |
$want = "any" if !$want && $want == 0;
|
|
121 |
|
|
122 |
my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required";
|
|
123 |
|
|
124 |
if ($prefix) {
|
|
125 |
my $filename = File::Spec->catfile($prefix, $file);
|
|
126 |
my $have = MM->parse_version( $filename );
|
|
127 |
$have = "undef" unless defined $have;
|
|
128 |
push @reports, [$mod, $want, $have, $prefix, (-s $filename)];
|
|
129 |
|
|
130 |
if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) {
|
|
131 |
if ( $have !~ /\A$lax_version_re\z/ ) {
|
|
132 |
push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)";
|
|
133 |
}
|
|
134 |
elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) {
|
|
135 |
push @dep_errors, "$mod version '$have' is not in required range '$want'";
|
|
136 |
}
|
|
137 |
}
|
|
138 |
}
|
|
139 |
else {
|
|
140 |
push @reports, [$mod, $want, "missing", '', 0];
|
|
141 |
|
|
142 |
if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) {
|
|
143 |
push @dep_errors, "$mod is not installed ($req_string)";
|
|
144 |
}
|
|
145 |
}
|
|
146 |
}
|
|
147 |
|
|
148 |
if ( @reports ) {
|
|
149 |
push @full_reports, "=== $title ===\n\n";
|
|
150 |
|
|
151 |
my $ml = _max( map { length $_->[0] } @reports );
|
|
152 |
my $wl = _max( map { length $_->[1] } @reports );
|
|
153 |
my $hl = _max( map { length $_->[2] } @reports );
|
|
154 |
my $ll = _max( map { length $_->[3] } @reports ); # location
|
|
155 |
my $sl = _max( map { length $_->[4] } @reports ); # size
|
|
156 |
|
|
157 |
if ($type eq 'modules') {
|
|
158 |
splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl, "-" x $ll, "-" x $sl];
|
|
159 |
push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports;
|
|
160 |
}
|
|
161 |
else {
|
|
162 |
splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl, "-" x $ll, "-" x $sl];
|
|
163 |
push @full_reports, map { sprintf(" %*s %*s %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2], -$ll, $_->[3], $sl, $_->[4]) } @reports;
|
|
164 |
}
|
|
165 |
|
|
166 |
push @full_reports, "\n";
|
|
167 |
}
|
|
168 |
}
|
|
169 |
}
|
|
170 |
|
|
171 |
if ( @full_reports ) {
|
|
172 |
diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports;
|
|
173 |
}
|
|
174 |
|
|
175 |
if ( @dep_errors ) {
|
|
176 |
diag join("\n",
|
|
177 |
"\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n",
|
|
178 |
"The following REQUIRED prerequisites were not satisfied:\n",
|
|
179 |
@dep_errors,
|
|
180 |
"\n"
|
|
181 |
);
|
|
182 |
}
|
|
183 |
|
|
184 |
pass;
|
|
185 |
|
|
186 |
# vim: ts=4 sts=4 sw=4 et:
|