#!perl -w
BEGIN {
eval
{
Capture::Tiny->
import
(
'capture'
);
Path::Class->
import
(
'dir'
);
};
if
(
my
$err
= $@) {
warn
"# $err"
;
plan
skip_all
=>
"Prerequisite needed for testing is missing"
;
exit
0;
};
};
my
@tests
;
if
(
@ARGV
) {
@tests
=
@ARGV
;
}
else
{
open
my
$manifest
,
'<'
,
'MANIFEST'
or
die
"Couldn't read MANIFEST: $!"
;
@tests
=
grep
{ -f
$_
}
grep
{ m!^(t/.*\.t|scripts/.*\.pl)$! }
map
{ s!\s*$!!;
$_
} <
$manifest
>
}
plan
tests
=> 0+
@tests
;
my
$meta
= Parse::CPAN::Meta->load_file(
'META.json'
);
my
$explicit_test_prereqs
= CPAN::Meta::Prereqs->new(
$meta
->{prereqs} )->merged_requirements->as_string_hash;
my
$minimum_perl
=
$meta
->{prereqs}->{runtime}->{requires}->{perl} || 5.006;
sub
distributed_packages {
my
@modules
;
for
(
@_
) {
dir(
$_
)->recurse(
callback
=>
sub
{
my
(
$child
) =
@_
;
if
( !
$child
->is_dir and
$child
=~ /\.pm$/) {
push
@modules
, ((
scalar
$child
->slurp()) =~ m/^\s
*package
\s+(?:
}
});
};
map
{
$_
=>
$_
}
@modules
;
}
my
%distribution
= distributed_packages(
'blib'
,
't'
);
my
$scanner
= Perl::PrereqScanner::Lite->new;
for
my
$test_file
(
@tests
) {
my
$implicit_test_prereqs
=
$scanner
->scan_file(
$test_file
)->as_string_hash;
my
%missing
= %{
$implicit_test_prereqs
};
for
my
$p
(
keys
%missing
) {
if
( Module::CoreList::is_core(
$p
,
undef
,
$minimum_perl
)) {
delete
$missing
{
$p
};
}
else
{
};
};
for
my
$k
(
keys
%$explicit_test_prereqs
) {
delete
$missing
{
$k
};
};
for
my
$k
(
keys
%distribution
) {
delete
$missing
{
$k
};
};
my
@missing
=
sort
keys
%missing
;
my
@failed
;
for
my
$candidate
(
@missing
) {
diag
"Checking that $candidate is not essential"
;
my
@cmd
= ($^X,
"-MTest::Without::Module=$candidate"
,
"-Mblib"
,
'-w'
,
$test_file
);
my
$cmd
=
join
" "
,
@cmd
;
my
(
$stdout
,
$stderr
,
$exit
) = capture {
system
(
@cmd
);
};
if
(
$exit
!= 0 ) {
push
@failed
, [
$candidate
, [
@cmd
]];
}
elsif
( $? != 0 ) {
push
@failed
, [
$candidate
, [
@cmd
]];
};
};
is 0+
@failed
, 0,
$test_file
or diag Dumper \
@failed
;
};
done_testing;