forked from andk/cpanpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04clean_load.t
55 lines (47 loc) · 1.06 KB
/
04clean_load.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# check if all the modules can load stand-alone
use strict;
eval 'use warnings';
my %has_deps = (
'blib/lib/CPAN/HTTP/Client.pm' => {
'HTTP::Tiny' => '0.005',
},
);
my @modules;
use File::Find;
find(\&list_modules, 'blib/lib');
use Test::More;
plan(tests => scalar @modules);
foreach my $file (@modules) {
#diag $file;
system("$^X -c $file >out 2>err");
my $fail;
if (open ERR, '<err') {
my $stderr = join('', <ERR>);
if ($stderr !~ /^$file syntax OK$/) {
$fail = $stderr;
}
} else {
$fail = "Could not open 'err' file after running $file";
}
ok(!$fail, "Loading $file") or diag $fail;
}
sub list_modules {
return if $_ !~ /\.pm$/;
return if _missing_deps($File::Find::name);
push @modules, $File::Find::name;
return;
}
sub _missing_deps {
my $file = shift;
if ( my $deps = $has_deps{$file} ) {
while ( my ($mod, $ver) = each %$deps ) {
eval "require $mod; $mod->VERSION($ver); 1"
or return 1;
}
}
return;
}
END {
unlink 'err';
unlink 'out';
}