Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression with implicit minimum value and multiple requirements #38

Merged
merged 3 commits into from May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/CPAN/Meta/Requirements/Range.pm
Expand Up @@ -193,7 +193,7 @@ sub with_string_requirement {
my ($op, $ver) = $part =~ m{\A\s*(==|>=|>|<=|<|!=)\s*(.*)\z};

if (! defined $op) {
return $self->with_minimum($part, $module, $bad_version_hook);
$self = $self->with_minimum($part, $module, $bad_version_hook);
} else {
Carp::croak("illegal requirement string: $req")
unless my $methods = $methods_for_op{ $op };
Expand Down
38 changes: 30 additions & 8 deletions t/strings.t
Expand Up @@ -46,10 +46,10 @@ ok($range->accepts('1.2'), 'lower version (<=)');
ok(!$range->accepts('1.4'), 'higher version (<=)');

# Test ""
$range = $base->with_string_requirement('>= 1.3');
ok($range->accepts('1.3'), 'exact version (>=)');
ok(!$range->accepts('1.2'), 'lower version (>=)');
ok($range->accepts('1.4'), 'higher version (>=)');
$range = $base->with_string_requirement('1.3');
ok($range->accepts('1.3'), 'exact version ("")');
ok(!$range->accepts('1.2'), 'lower version ("")');
ok($range->accepts('1.4'), 'higher version ("")');

# Test multiple requirements
$range = $base->with_string_requirement('>= 1.3, <= 2.0, != 1.6');
Expand All @@ -58,6 +58,13 @@ ok(!$range->accepts('1.2'), 'lower version (>=, <=, !)');
ok(!$range->accepts('2.1'), 'higher version (>=, <=, !)');
ok(!$range->accepts('1.6'), 'excluded version (>=, <=, !)');

# Test multiple requirements with implicit minimum
$range = $base->with_string_requirement('0.90, != 0.91');
ok(!$range->accepts('0.88'), 'lower version ("", !)');
ok($range->accepts('0.90'), 'exact version ("", !)');
ok($range->accepts('0.901'), 'middle version ("", !)');
ok(!$range->accepts('0.91'), 'excluded version ("", !)');
ok($range->accepts('0.92'), 'higher version ("", !)');

my $req = CPAN::Meta::Requirements->new;

Expand Down Expand Up @@ -86,10 +93,10 @@ ok($req->accepts_module('Foo::Graz' => '1.2'), 'lower version (<=)');
ok(!$req->accepts_module('Foo::Graz' => '1.4'), 'higher version (<=)');

# Test ""
$req->add_string_requirement('Foo::Blurb', '>= 1.3');
ok($req->accepts_module('Foo::Blurb' => '1.3'), 'exact version (>=)');
ok(!$req->accepts_module('Foo::Blurb' => '1.2'), 'lower version (>=)');
ok($req->accepts_module('Foo::Blurb' => '1.4'), 'higher version (>=)');
$req->add_string_requirement('Foo::Blurb', '1.3');
ok($req->accepts_module('Foo::Blurb' => '1.3'), 'exact version ("")');
ok(!$req->accepts_module('Foo::Blurb' => '1.2'), 'lower version ("")');
ok($req->accepts_module('Foo::Blurb' => '1.4'), 'higher version ("")');

# Test multiple requirements
$req->add_string_requirement('A::Tribe::Called', '>= 1.3, <= 2.0, != 1.6');
Expand All @@ -98,6 +105,21 @@ ok(!$req->accepts_module('A::Tribe::Called' => '1.2'), 'lower version (>=, <=, !
ok(!$req->accepts_module('A::Tribe::Called' => '2.1'), 'higher version (>=, <=, !)');
ok(!$req->accepts_module('A::Tribe::Called' => '1.6'), 'excluded version (>=, <=, !)');

# Test multiple requirements with implicit minimum
{
my $req = CPAN::Meta::Requirements->new;

$req->add_string_requirement('Foo::MyModule', '0.90, != 0.91');

is_deeply(
$req->as_string_hash,
{
'Foo::MyModule' => '>= 0.90, != 0.91'
},
"multiple requirements with implicit minimum",
);
}

# Test precision
{
my $req = CPAN::Meta::Requirements->new;
Expand Down