|
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 $req = CPAN::Meta::Requirements->new;
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
$req->add_minimum('Foo::Bar' => 10);
|
|
Packit |
f40462 |
$req->add_minimum('Foo::Bar' => 0);
|
|
Packit |
f40462 |
$req->add_minimum('Foo::Bar' => 2);
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
$req->add_minimum('Foo::Baz' => version->declare('v1.2.3'));
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
$req->add_minimum('Foo::Undef' => undef);
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
my $want = {
|
|
Packit |
f40462 |
'Foo::Bar' => 10,
|
|
Packit |
f40462 |
'Foo::Baz' => 'v1.2.3',
|
|
Packit |
f40462 |
'Foo::Undef' => 0,
|
|
Packit |
f40462 |
};
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
is_deeply(
|
|
Packit |
f40462 |
$req->as_string_hash,
|
|
Packit |
f40462 |
$want,
|
|
Packit |
f40462 |
"some basic minimums",
|
|
Packit |
f40462 |
);
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
$req->finalize;
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
$req->add_minimum('Foo::Bar', 2);
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
pass('we can add a Foo::Bar requirement with no effect post finalization');
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
dies_ok { $req->add_minimum('Foo::Bar', 12) }
|
|
Packit |
f40462 |
qr{finalized req},
|
|
Packit |
f40462 |
"can't add a higher Foo::Bar after finalization";
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
dies_ok { $req->add_minimum('Foo::New', 0) }
|
|
Packit |
f40462 |
qr{finalized req},
|
|
Packit |
f40462 |
"can't add a new module prereq after finalization";
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
dies_ok { $req->clear_requirement('Foo::Bar') }
|
|
Packit |
f40462 |
qr{finalized req},
|
|
Packit |
f40462 |
"can't clear an existing prereq after finalization";
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
$req->clear_requirement('Bogus::Req');
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
pass('we can clear a prereq that was not set to begin with');
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
is_deeply(
|
|
Packit |
f40462 |
$req->as_string_hash,
|
|
Packit |
f40462 |
$want,
|
|
Packit |
f40462 |
"none of our attempts to alter the object post-finalization worked",
|
|
Packit |
f40462 |
);
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
my $cloned = $req->clone;
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
$cloned->add_minimum('Foo::Bar', 12);
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
is_deeply(
|
|
Packit |
f40462 |
$cloned->as_string_hash,
|
|
Packit |
f40462 |
{
|
|
Packit |
f40462 |
%$want,
|
|
Packit |
f40462 |
'Foo::Bar' => 12,
|
|
Packit |
f40462 |
},
|
|
Packit |
f40462 |
"we can alter a cloned V:R (finalization does not survive cloning)",
|
|
Packit |
f40462 |
);
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
is_deeply(
|
|
Packit |
f40462 |
$req->as_string_hash,
|
|
Packit |
f40462 |
$want,
|
|
Packit |
f40462 |
"...and original requirements are untouched",
|
|
Packit |
f40462 |
);
|
|
Packit |
f40462 |
}
|
|
Packit |
f40462 |
|
|
Packit |
f40462 |
done_testing;
|