Skip to content

Allow ranges in spec #1232

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/src/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,12 @@ PkgB = "≥ 1.2.3" # [1.2.3, ∞)
PkgC = "= 1.2.3" # [1.2.3, 1.2.3]
PkgD = "< 1.2.3" # [0.0.0, 1.2.2]
```

### Range specifiers

Ranges can also be used to specify version ranges:

```toml
[compat]
PkgA = "0.1 - 0.2.3" # [0.1.0, 0.2.3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not what a range should mean: the second end-point should be inclusive, and any unspecified trailing numbers should be considered to be wildcards. I.e.

  • 0.1-0.2.3 means [0.1, 0.2.3]
  • 0.1-0.2 means [0.1, 0.3)
  • 0.1-0 means [0.1, 1.0)

This seems to be what you've implemented, but it would be good to have some tests and, of course, the comment here should be fixed.

Copy link
Contributor Author

@goretkin goretkin Jun 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look. I didn't notice the ) vs the ]. I just copied and pasted from the doc above.

Did you see the tests already in the commit? I am not really familiar with semver, so if you could recommend any additional tests, that would be helpful.

```
18 changes: 13 additions & 5 deletions src/versions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,19 @@ function semver_spec(s::String)
for ver in split(s, ',')
range = nothing
found_match = false
for (ver_reg, f) in ver_regs
if occursin(ver_reg, ver)
range = f(match(ver_reg, ver))
found_match = true
break
try
range = VersionRange(ver)
found_match = true
catch err
(err isa ArgumentError) || rethrow()
end
if !found_match
for (ver_reg, f) in ver_regs
if occursin(ver_reg, ver)
range = f(match(ver_reg, ver))
found_match = true
break
end
end
end
found_match || error("invalid version specifier: $s")
Expand Down
4 changes: 4 additions & 0 deletions test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ import Pkg.Types: semver_spec, VersionSpec
@test v"1.2.3" in semver_spec(">=1.2.3")
@test !(v"1.2.2" in semver_spec(">=1.2.3"))

@test semver_spec("0.1.0 - 0.2.2") == VersionSpec("0.1.0 - 0.2.2")
@test semver_spec("0.1.0 - 0.2.2, 1.2") == VersionSpec(["0.1.0 - 0.2.2", "1.2.0-1"])
@test semver_spec("0.1.0 - 0.2.2, >=1.2") == VersionSpec(["0.1.0 - 0.2.2", "1.2.0-*"])

@test_throws ErrorException semver_spec("^^0.2.3")
@test_throws ErrorException semver_spec("^^0.2.3.4")
@test_throws ErrorException semver_spec("0.0.0")
Expand Down