Skip to content

Commit

Permalink
fix(cargo): handle version range using Less Than Equal
Browse files Browse the repository at this point in the history
When a version range with a '<' character is found, the range is updated to the (latest version + 1). However for a range using "<=" this is invalid. Add a special case for a range using Less Than Equal which is updated to simply the latest version.
  • Loading branch information
caspermeijn committed May 27, 2024
1 parent b8605c0 commit 72f1102
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ def update_range_requirements(string_reqs)
raise UnfixableRequirement if req.start_with?(">")

req.sub(VERSION_REGEX) do |old_version|
update_greatest_version(old_version, target_version)
if req.start_with?("<=")
target_version
else
update_greatest_version(old_version, target_version)
end
end
end.join(", ")
rescue UnfixableRequirement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,40 @@
end

context "when there were multiple range specifications" do
let(:req_string) { "> 1.0.0, < 1.2.0" }
context "with `less than`" do
let(:req_string) { "> 1.0.0, < 1.2.0" }

its([:requirement]) { is_expected.to eq("> 1.0.0, < 1.6.0") }
its([:requirement]) { is_expected.to eq("> 1.0.0, < 1.6.0") }

context "when already valid" do
let(:req_string) { "> 1.0.0, < 1.7.0" }
context "when already valid" do
let(:req_string) { "> 1.0.0, < 1.7.0" }

its([:requirement]) { is_expected.to eq(req_string) }
its([:requirement]) { is_expected.to eq(req_string) }
end

context "when including a pre-release" do
let(:req_string) { ">=1.2.0, <1.4.0-dev" }

its([:requirement]) { is_expected.to eq(">=1.2.0, <1.6.0") }
end
end

context "when including a pre-release" do
let(:req_string) { ">=1.2.0, <1.4.0-dev" }
context "with `less than equal`" do
let(:req_string) { "> 1.0.0, <= 1.2.0" }

its([:requirement]) { is_expected.to eq(">=1.2.0, <1.6.0") }
its([:requirement]) { is_expected.to eq("> 1.0.0, <= 1.5.0") }

context "when already valid" do
let(:req_string) { "> 1.0.0, <= 1.7.0" }

its([:requirement]) { is_expected.to eq(req_string) }
end

context "when including a pre-release" do
let(:req_string) { ">=1.2.0, <=1.4.0-dev" }

its([:requirement]) { is_expected.to eq(">=1.2.0, <=1.5.0") }
end
end
end

Expand Down

0 comments on commit 72f1102

Please sign in to comment.