Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 7621e70

Browse files
committed
CPAN: parse all distroprefs/*.yml
for possible syntax errors
1 parent deca904 commit 7621e70

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

Porting/Maintainers.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ package Maintainers;
369369
t/30shell.coverage
370370
t/30shell.t
371371
t/31sessions.t
372+
t/42distroprefs.t
372373
t/44cpanmeta.t
373374
t/50pod.t
374375
t/52podcover.t

cpan/CPAN/t/42distroprefs.t

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,49 @@ use Config;
55
use CPAN::Distroprefs;
66
use File::Spec;
77

8-
my $yamlclass = $^V =~ /c$/ ? 'YAML::Safe' : 'YAML';
8+
my $yamlclass = $^V =~ /c$/
9+
? ($] >= 5.030 ? 'YAML::Safe' : 'YAML::XS')
10+
: 'YAML';
911
my %ext = (
1012
yml => $yamlclass,
1113
);
1214
eval "require $ext{yml}; 1"
1315
or plan skip_all => "$ext{yml} required";
14-
plan tests => 3;
16+
plan tests => 4;
1517

1618
my $finder = CPAN::Distroprefs->find(
1719
'./distroprefs', \%ext,
1820
);
21+
my $LoadFile = sub {
22+
no strict 'refs';
23+
my $m = "${yamlclass}::LoadFile";
24+
if ($yamlclass eq 'YAML::Safe') {
25+
my $c = $yamlclass;
26+
my $o = $c->new->nonstrict;
27+
$o->SafeLoadFile(@_);
28+
} elsif ($^V =~ /c$/ && $yamlclass eq 'YAML::XS') { # only the cperl variant
29+
local $YAML::XS::NonStrict = 1;
30+
$m->LoadFile(@_);
31+
} else {
32+
$m->(@_);
33+
}
34+
};
1935

2036
my $last = '0';
21-
my @errors;
37+
my (@errors, @ymlerrors);
2238
while (my $next = $finder->next) {
2339
if ( $next->file lt $last ) {
2440
push @errors, $next->file . " lt $last\n";
2541
}
2642
$last = $next->file;
43+
if ($last =~ /\.ya?ml/) {
44+
my $result;
45+
eval { $result = $LoadFile->("distroprefs/$last") };
46+
push @ymlerrors, $next->file . " $@\n" if !$result or $@;
47+
}
2748
}
2849
is(scalar @errors, 0, "finder traversed alphabetically") or diag @errors;
50+
is(scalar @ymlerrors, 0, "all yml parsed") or diag @ymlerrors;
2951

3052
sub find_ok {
3153
my ($arg, $expect, $label) = @_;
@@ -62,11 +84,6 @@ sub find_ok {
6284
);
6385
}
6486

65-
my $LoadFile = sub {
66-
no strict 'refs';
67-
my $m = "${yamlclass}::LoadFile";
68-
$m->(@_)
69-
};
7087
find_ok(
7188
{
7289
distribution => 'HDP/Perl-Version-1',
@@ -86,7 +103,7 @@ find_ok(
86103
distribution => 'INGY/YAML-0.66',
87104
},
88105
{
89-
prefs => do 'distroprefs/INGY.YAML.dd',
106+
prefs => do './distroprefs/INGY.YAML.dd',
90107
prefs_file => File::Spec->catfile(qw/distroprefs INGY.YAML.dd/),
91108
},
92109
'match .dd',

0 commit comments

Comments
 (0)