|
Packit |
f40462 |
use strict;
|
|
Packit |
f40462 |
use warnings;
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
use CPAN::Meta::Requirements;
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
use Test::More 0.88;
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
sub dies_ok (&@) {
|
|
Packit |
f40462 |
my ($code, $qr, $comment) = @_;
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
no warnings 'redefine';
|
|
Packit |
f40462 |
local *Regexp::CARP_TRACE = sub { "<regexp>" };
|
|
Packit |
f40462 |
my $lived = eval { $code->(); 1 };
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
if ($lived) {
|
|
Packit |
f40462 |
fail("$comment: did not die");
|
|
Packit |
f40462 |
} else {
|
|
Packit |
f40462 |
like($@, $qr, $comment);
|
|
Packit |
f40462 |
}
|
|
Packit |
f40462 |
}
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
{
|
|
Packit |
f40462 |
my $string_hash = {
|
|
Packit |
f40462 |
Left => 10,
|
|
Packit |
f40462 |
Shared => '>= 2, <= 9, != 7',
|
|
Packit |
f40462 |
Right => 18,
|
|
Packit |
f40462 |
};
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
my $req = CPAN::Meta::Requirements->from_string_hash($string_hash);
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
is_deeply(
|
|
Packit |
f40462 |
$req->as_string_hash,
|
|
Packit |
f40462 |
$string_hash,
|
|
Packit |
f40462 |
"we can load from a string hash",
|
|
Packit |
f40462 |
);
|
|
Packit |
f40462 |
}
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
SKIP: {
|
|
Packit |
f40462 |
skip "Can't tell v-strings from strings until 5.8.1", 1
|
|
Packit |
f40462 |
unless $] gt '5.008';
|
|
Packit |
f40462 |
my $string_hash = {
|
|
Packit |
f40462 |
Left => 10,
|
|
Packit |
f40462 |
Shared => '= 2',
|
|
Packit |
f40462 |
Right => 18,
|
|
Packit |
f40462 |
};
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
dies_ok { CPAN::Meta::Requirements->from_string_hash($string_hash) }
|
|
Packit |
f40462 |
qr/Can't convert/,
|
|
Packit |
f40462 |
"we die when we can't understand a version spec";
|
|
Packit |
f40462 |
}
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
{
|
|
Packit |
f40462 |
my $undef_hash = { Undef => undef };
|
|
Packit |
f40462 |
my $z_hash = { ZeroLength => '' };
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
my $warning;
|
|
Packit |
f40462 |
local $SIG{__WARN__} = sub { $warning = join("\n",@_) };
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
my $req = CPAN::Meta::Requirements->from_string_hash($undef_hash);
|
|
Packit |
f40462 |
like ($warning, qr/Undefined requirement.*treated as '0'/, "undef requirement warns");
|
|
Packit |
f40462 |
$req->add_string_requirement(%$z_hash);
|
|
Packit |
f40462 |
like ($warning, qr/Undefined requirement.*treated as '0'/, "'' requirement warns");
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
is_deeply(
|
|
Packit |
f40462 |
$req->as_string_hash,
|
|
Packit |
f40462 |
{ map { ($_ => 0) } keys(%$undef_hash), keys(%$z_hash) },
|
|
Packit |
f40462 |
"undef/'' requirements treated as '0'",
|
|
Packit |
f40462 |
);
|
|
Packit |
f40462 |
}
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
SKIP: {
|
|
Packit |
f40462 |
skip "Can't tell v-strings from strings until 5.8.1", 2
|
|
Packit |
f40462 |
unless $] gt '5.008';
|
|
Packit |
f40462 |
my $string_hash = {
|
|
Packit |
f40462 |
Left => 10,
|
|
Packit |
f40462 |
Shared => v50.44.60,
|
|
Packit |
f40462 |
Right => 18,
|
|
Packit |
f40462 |
};
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
my $warning;
|
|
Packit |
f40462 |
local $SIG{__WARN__} = sub { $warning = join("\n",@_) };
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
my $req = eval { CPAN::Meta::Requirements->from_string_hash($string_hash); };
|
|
Packit |
f40462 |
is( $@, '', "vstring in string hash lives" );
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
ok(
|
|
Packit |
f40462 |
$req->accepts_module(Shared => 'v50.44.60'),
|
|
Packit |
f40462 |
"vstring treated as if string",
|
|
Packit |
f40462 |
);
|
|
Packit |
f40462 |
}
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
{
|
|
Packit |
f40462 |
my $req = CPAN::Meta::Requirements->from_string_hash(
|
|
Packit |
f40462 |
{ Bad => 'invalid', },
|
|
Packit |
f40462 |
{ bad_version_hook => sub { version->new(42) } },
|
|
Packit |
f40462 |
);
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
ok(
|
|
Packit |
f40462 |
$req->accepts_module(Bad => 42),
|
|
Packit |
f40462 |
"options work 2nd arg to f_s_h",
|
|
Packit |
f40462 |
);
|
|
Packit |
f40462 |
}
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
done_testing;
|