Skip to content

Commit

Permalink
Support ..= for --version-range
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Sep 5, 2023
1 parent 18dfd62 commit 46cb714
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 17 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,14 @@ OPTIONS:

This flag can only be used together with either --features or --include-features.

--version-range <START>..[END]
--version-range [START]..[=END]
Perform commands on a specified (inclusive) range of Rust versions.

If the given range is unclosed, the latest stable compiler is treated as the upper
bound.
If the upper bound of the range is omitted, the latest stable compiler is used as the
upper bound.

If the lower bound of the range is omitted, the value of the `rust-version` field in
`Cargo.toml` is used as the lower bound.

Note that ranges are always inclusive ranges.

Expand Down Expand Up @@ -307,7 +310,7 @@ To specify multiple groups, use this option multiple times:
Perform commands on a specified (inclusive) range of Rust versions.

```console
$ cargo hack check --version-range 1.46..1.47
$ cargo hack check --version-range 1.46..=1.47
info: running `cargo +1.46 check` on cargo-hack (1/2)
...
info: running `cargo +1.47 check` on cargo-hack (2/2)
Expand Down
8 changes: 5 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,11 +731,13 @@ const HELP: &[HelpText<'_>] = &[
(
"",
"--version-range",
"<START>..[END]",
"[START]..[=END]",
"Perform commands on a specified (inclusive) range of Rust versions",
&[
"If the given range is unclosed, the latest stable compiler is treated as the upper \
bound.",
"If the upper bound of the range is omitted, the latest stable compiler is used as the \
upper bound.",
"If the lower bound of the range is omitted, the value of the `rust-version` field in \
`Cargo.toml` is used as the lower bound.",
"Note that ranges are always inclusive ranges.",
],
),
Expand Down
10 changes: 10 additions & 0 deletions src/rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ pub(crate) fn version_range(
cargo::minor_version(cmd!("cargo", "+stable"))?
}
Some(end) => {
let end = match end.strip_prefix('=') {
Some(end) => end,
None => {
warn!(
"using `..` for inclusive range is deprecated; consider using `{}`",
range.replace("..", "..=")
);
end
}
};
let end = end.parse()?;
check(&end)?;
end.minor
Expand Down
2 changes: 1 addition & 1 deletion tests/auxiliary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn cargo_hack<O: AsRef<OsStr>>(args: impl AsRef<[O]>) -> Command {
cmd.arg("hack");
if let Some(toolchain) = test_version() {
if !args.iter().any(|a| a.as_ref().to_str().unwrap().starts_with("--version-range")) {
cmd.arg(format!("--version-range=1.{toolchain}..1.{toolchain}"));
cmd.arg(format!("--version-range=1.{toolchain}..=1.{toolchain}"));
}
}
cmd.args(args);
Expand Down
9 changes: 6 additions & 3 deletions tests/long-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,14 @@ OPTIONS:

This flag can only be used together with either --features or --include-features.

--version-range <START>..[END]
--version-range [START]..[=END]
Perform commands on a specified (inclusive) range of Rust versions.

If the given range is unclosed, the latest stable compiler is treated as the upper
bound.
If the upper bound of the range is omitted, the latest stable compiler is used as the
upper bound.

If the lower bound of the range is omitted, the value of the `rust-version` field in
`Cargo.toml` is used as the lower bound.

Note that ranges are always inclusive ranges.

Expand Down
2 changes: 1 addition & 1 deletion tests/short-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ OPTIONS:
--ignore-private Skip to perform on `publish = false` packages
--ignore-unknown-features Skip passing --features flag to `cargo` if that feature
does not exist in the package
--version-range <START>..[END] Perform commands on a specified (inclusive) range of Rust
--version-range [START]..[=END] Perform commands on a specified (inclusive) range of Rust
versions
--version-step <NUM> Specify the version interval of --version-range (default
to `1`)
Expand Down
23 changes: 18 additions & 5 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,14 +1318,24 @@ fn default_feature_behavior() {
#[cfg_attr(windows, ignore)] // rustup bug: https://github.com/rust-lang/rustup/issues/3036
#[test]
fn version_range() {
cargo_hack(["check", "--version-range", "1.63..1.64"]).assert_success("real").stderr_contains(
cargo_hack(["check", "--version-range", "1.63..=1.64"]).assert_success("real").stderr_contains(
"
running `cargo +1.63 check` on real (1/2)
running `cargo +1.64 check` on real (2/2)
",
);

cargo_hack(["check", "--version-range", "1.63..1.64", "--target", TARGET])
cargo_hack(["check", "--version-range", "1.63..1.64"])
.assert_failure("real") // warn
.stderr_contains(
"
warning: using `..` for inclusive range is deprecated; consider using `1.63..=1.64`
running `cargo +1.63 check` on real (1/2)
running `cargo +1.64 check` on real (2/2)
",
);

cargo_hack(["check", "--version-range", "1.63..=1.64", "--target", TARGET])
.assert_success("real")
.stderr_contains(format!(
"
Expand All @@ -1349,7 +1359,7 @@ fn multi_target() {
cargo_hack([
"check",
"--version-range",
"1.63..1.64",
"1.63..=1.64",
"--target",
&format!("aarch64{target_suffix}"),
])
Expand All @@ -1364,7 +1374,7 @@ fn multi_target() {
cargo_hack([
"check",
"--version-range",
"1.63..1.64",
"1.63..=1.64",
"--target",
&format!("x86_64{target_suffix}"),
"--target",
Expand All @@ -1382,7 +1392,7 @@ fn multi_target() {
cargo_hack([
"check",
"--version-range",
"1.63..1.64",
"1.63..=1.64",
"--target",
&format!("x86_64{target_suffix}"),
"--target",
Expand All @@ -1409,6 +1419,9 @@ fn version_range_failure() {
cargo_hack(["check", "--version-range", "1.45..1.44"])
.assert_failure("real")
.stderr_contains("specified version range `1.45..1.44` is empty");
cargo_hack(["check", "--version-range", "1.45..=1.44"])
.assert_failure("real")
.stderr_contains("specified version range `1.45..=1.44` is empty");

// v0
cargo_hack(["check", "--version-range", "0.45.."])
Expand Down

0 comments on commit 46cb714

Please sign in to comment.