Debian Codegraph @

t/00-report-prereqs.t

raw symbols SCIP
1 #!perl
2
3 use strictscip-perl cpan CPAN-Reporter 1.2020 strict/;
4 use warningsscip-perl cpan CPAN-Reporter 1.2020 warnings/;
5
6 # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.029
7
8 use Test::Morescip-perl cpan CPAN-Reporter 1.2020 Test/More/ tests => 1;
9
10 use ExtUtils::MakeMakerscip-perl cpan CPAN-Reporter 1.2020 ExtUtils/MakeMaker/;
11 use File::Specscip-perl cpan CPAN-Reporter 1.2020 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 _maxscip-perl cpan CPAN-Reporter 1.2020 main/_max(). {
35 my $max = shiftscip-perl cpan CPAN-Reporter 1.2020 main/shift().;
36 $max = ( $_scip-perl cpan CPAN-Reporter 1.2020 main/$_. > $max ) ? $_scip-perl cpan CPAN-Reporter 1.2020 main/$_. : $max for @_scip-perl cpan CPAN-Reporter 1.2020 main/`@_`.;
37 return $max;
38 }
39
40 sub _merge_prereqsscip-perl cpan CPAN-Reporter 1.2020 main/_merge_prereqs(). {
41 my ($collector, $prereqs) = @_scip-perl cpan CPAN-Reporter 1.2020 main/`@_`.;
42
43 # CPAN::Meta::Prereqs object
44 if (refscip-perl cpan CPAN-Reporter 1.2020 main/ref(). $collector eq $cpan_meta_pre) {
45 return $collector->with_merged_prereqsscip-perl cpan CPAN-Reporter 1.2020 main/with_merged_prereqs().(
46 CPAN::Meta::Prereqs->newscip-perl cpan CPAN-Reporter 1.2020 CPAN/Meta/Prereqs/new().( $prereqs )
47 );
48 }
49
50 # Raw hashrefs
51 for my $phase ( keysscip-perl cpan CPAN-Reporter 1.2020 main/keys(). %$prereqs ) {
52 for my $type ( keysscip-perl cpan CPAN-Reporter 1.2020 main/keys(). %{ $prereqs->{$phase} } ) {
53 for my $module ( keysscip-perl cpan CPAN-Reporter 1.2020 main/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_prereqsscip-perl cpan CPAN-Reporter 1.2020 main/_merge_prereqs().(
75 ( $HAS_CPAN_META ? $cpan_meta_pre->newscip-perl cpan CPAN-Reporter 1.2020 main/new(). : {} ),
76 $static_prereqs
77 );
78
79 # Add dynamic prereqs to the included modules list (if we can)
80 my ($source) = grepscip-perl cpan CPAN-Reporter 1.2020 main/grep(). { -f } 'MYMETA.json', 'MYMETA.yml';
81 my $cpan_meta_error;
82 if ( $source && $HAS_CPAN_META
83 && (my $meta = eval { CPAN::Meta->load_filescip-perl cpan CPAN-Reporter 1.2020 CPAN/Meta/load_file().($source) } )
84 ) {
85 $full_prereqs = _merge_prereqsscip-perl cpan CPAN-Reporter 1.2020 main/_merge_prereqs().($full_prereqs, $meta->prereqsscip-perl cpan CPAN-Reporter 1.2020 main/prereqs().);
86 }
87 else {
88 $cpan_meta_error = $@scip-perl cpan CPAN-Reporter 1.2020 main/`$@`.; # capture error from CPAN::Meta->load_file($source)
89 $source = 'static metadata';
90 }
91
92 my @full_reports;
93 my @dep_errors;
94 my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hashscip-perl cpan CPAN-Reporter 1.2020 main/as_string_hash(). : $full_prereqs;
95
96 # Add static includes into a fake section
97 for my $mod (@include) {
98 $req_hash->{other}{modules}{$mod} = 0;
99 }
100
101 for my $phase ( qw(configure build test runtime develop other) ) {
102 next unless $req_hash->{$phase};
103 next if ($phase eq 'develop' and not $ENVscip-perl cpan CPAN-Reporter 1.2020 main/`%ENV`.{AUTHOR_TESTING});
104
105 for my $type ( qw(requires recommends suggests conflicts modules) ) {
106 next unless $req_hash->{$phase}{$type};
107
108 my $title = ucfirstscip-perl cpan CPAN-Reporter 1.2020 main/ucfirst().($phase).' '.ucfirstscip-perl cpan CPAN-Reporter 1.2020 main/ucfirst().($type);
109 my @reports = [qw/Module Want Have/];
110
111 for my $mod ( sortscip-perl cpan CPAN-Reporter 1.2020 main/sort(). keysscip-perl cpan CPAN-Reporter 1.2020 main/keys(). %{ $req_hash->{$phase}{$type} } ) {
112 next if grepscip-perl cpan CPAN-Reporter 1.2020 main/grep(). { $_scip-perl cpan CPAN-Reporter 1.2020 main/$_. eq $mod } @exclude;
113
114 my $want = $req_hash->{$phase}{$type}{$mod};
115 $want = "undef" unless definedscip-perl cpan CPAN-Reporter 1.2020 main/defined(). $want;
116 $want = "any" if !$want && $want == 0;
117
118 if ($mod eq 'perl') {
119 pushscip-perl cpan CPAN-Reporter 1.2020 main/push(). @reports, ['perl', $want, $]scip-perl cpan CPAN-Reporter 1.2020 main/`$]`.];
120 next;
121 }
122
123 my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required";
124
125 my $file = $mod;
126 $file =~ s{::}{/}g;
127 $file .= ".pm";
128 my ($prefix) = grepscip-perl cpan CPAN-Reporter 1.2020 main/grep(). { -e File::Spec->catfilescip-perl cpan CPAN-Reporter 1.2020 File/Spec/catfile().($_scip-perl cpan CPAN-Reporter 1.2020 main/$_., $file) } @INCscip-perl cpan CPAN-Reporter 1.2020 main/`@INC`.;
129
130 if ($prefix) {
131 my $have = MM->parse_versionscip-perl cpan CPAN-Reporter 1.2020 MM/parse_version().( File::Spec->catfilescip-perl cpan CPAN-Reporter 1.2020 File/Spec/catfile().($prefix, $file) );
132 $have = "undef" unless definedscip-perl cpan CPAN-Reporter 1.2020 main/defined(). $have;
133 pushscip-perl cpan CPAN-Reporter 1.2020 main/push(). @reports, [$mod, $want, $have];
134
135 if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) {
136 if ( $have !~ /\A$lax_version_re\z/ ) {
137 pushscip-perl cpan CPAN-Reporter 1.2020 main/push(). @dep_errors, "$mod version '$have' cannot be parsed ($req_string)";
138 }
139 elsif ( ! $full_prereqs->requirements_forscip-perl cpan CPAN-Reporter 1.2020 main/requirements_for().( $phase, $type )->accepts_modulescip-perl cpan CPAN-Reporter 1.2020 main/accepts_module().( $mod => $have ) ) {
140 pushscip-perl cpan CPAN-Reporter 1.2020 main/push(). @dep_errors, "$mod version '$have' is not in required range '$want'";
141 }
142 }
143 }
144 else {
145 pushscip-perl cpan CPAN-Reporter 1.2020 main/push(). @reports, [$mod, $want, "missing"];
146
147 if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) {
148 pushscip-perl cpan CPAN-Reporter 1.2020 main/push(). @dep_errors, "$mod is not installed ($req_string)";
149 }
150 }
151 }
152
153 if ( @reports ) {
154 pushscip-perl cpan CPAN-Reporter 1.2020 main/push(). @full_reports, "=== $title ===\n\n";
155
156 my $ml = _maxscip-perl cpan CPAN-Reporter 1.2020 main/_max().( mapscip-perl cpan CPAN-Reporter 1.2020 main/map(). { lengthscip-perl cpan CPAN-Reporter 1.2020 main/length(). $_scip-perl cpan CPAN-Reporter 1.2020 main/$_.->[0] } @reports );
157 my $wl = _maxscip-perl cpan CPAN-Reporter 1.2020 main/_max().( mapscip-perl cpan CPAN-Reporter 1.2020 main/map(). { lengthscip-perl cpan CPAN-Reporter 1.2020 main/length(). $_scip-perl cpan CPAN-Reporter 1.2020 main/$_.->[1] } @reports );
158 my $hl = _maxscip-perl cpan CPAN-Reporter 1.2020 main/_max().( mapscip-perl cpan CPAN-Reporter 1.2020 main/map(). { lengthscip-perl cpan CPAN-Reporter 1.2020 main/length(). $_scip-perl cpan CPAN-Reporter 1.2020 main/$_.->[2] } @reports );
159
160 if ($type eq 'modules') {
161 splicescip-perl cpan CPAN-Reporter 1.2020 main/splice(). @reports, 1, 0, ["-" x $ml, "", "-" x $hl];
162 pushscip-perl cpan CPAN-Reporter 1.2020 main/push(). @full_reports, mapscip-perl cpan CPAN-Reporter 1.2020 main/map(). { sprintfscip-perl cpan CPAN-Reporter 1.2020 main/sprintf().(" %*s %*s\n", -$ml, $_scip-perl cpan CPAN-Reporter 1.2020 main/$_.->[0], $hl, $_scip-perl cpan CPAN-Reporter 1.2020 main/$_.->[2]) } @reports;
163 }
164 else {
165 splicescip-perl cpan CPAN-Reporter 1.2020 main/splice(). @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl];
166 pushscip-perl cpan CPAN-Reporter 1.2020 main/push(). @full_reports, mapscip-perl cpan CPAN-Reporter 1.2020 main/map(). { sprintfscip-perl cpan CPAN-Reporter 1.2020 main/sprintf().(" %*s %*s %*s\n", -$ml, $_scip-perl cpan CPAN-Reporter 1.2020 main/$_.->[0], $wl, $_scip-perl cpan CPAN-Reporter 1.2020 main/$_.->[1], $hl, $_scip-perl cpan CPAN-Reporter 1.2020 main/$_.->[2]) } @reports;
167 }
168
169 pushscip-perl cpan CPAN-Reporter 1.2020 main/push(). @full_reports, "\n";
170 }
171 }
172 }
173
174 if ( @full_reports ) {
175 diagscip-perl cpan CPAN-Reporter 1.2020 main/diag(). "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports;
176 }
177
178 if ( $cpan_meta_error || @dep_errors ) {
179 diagscip-perl cpan CPAN-Reporter 1.2020 main/diag(). "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n";
180 }
181
182 if ( $cpan_meta_error ) {
183 my ($orig_source) = grepscip-perl cpan CPAN-Reporter 1.2020 main/grep(). { -f } 'MYMETA.json', 'MYMETA.yml';
184 diagscip-perl cpan CPAN-Reporter 1.2020 main/diag(). "\nCPAN::Meta->load_file('$orig_source') failed with: $cpan_meta_error\n";
185 }
186
187 if ( @dep_errors ) {
188 diagscip-perl cpan CPAN-Reporter 1.2020 main/diag(). joinscip-perl cpan CPAN-Reporter 1.2020 main/join().("\n",
189 "\nThe following REQUIRED prerequisites were not satisfied:\n",
190 @dep_errors,
191 "\n"
192 );
193 }
194
195 passscip-perl cpan CPAN-Reporter 1.2020 main/pass().('Reported prereqs');
196
197 # vim: ts=4 sts=4 sw=4 et: