Skip to content

Commit 41de826

Browse files
authored
Support ..= for --version-range (#198)
1 parent 18dfd62 commit 41de826

File tree

7 files changed

+48
-17
lines changed

7 files changed

+48
-17
lines changed

README.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,14 @@ OPTIONS:
163163

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

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

169-
If the given range is unclosed, the latest stable compiler is treated as the upper
170-
bound.
169+
If the upper bound of the range is omitted, the latest stable compiler is used as the
170+
upper bound.
171+
172+
If the lower bound of the range is omitted, the value of the `rust-version` field in
173+
`Cargo.toml` is used as the lower bound.
171174

172175
Note that ranges are always inclusive ranges.
173176

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

309312
```console
310-
$ cargo hack check --version-range 1.46..1.47
313+
$ cargo hack check --version-range 1.46..=1.47
311314
info: running `cargo +1.46 check` on cargo-hack (1/2)
312315
...
313316
info: running `cargo +1.47 check` on cargo-hack (2/2)

src/cli.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -731,11 +731,13 @@ const HELP: &[HelpText<'_>] = &[
731731
(
732732
"",
733733
"--version-range",
734-
"<START>..[END]",
734+
"[START]..[=END]",
735735
"Perform commands on a specified (inclusive) range of Rust versions",
736736
&[
737-
"If the given range is unclosed, the latest stable compiler is treated as the upper \
738-
bound.",
737+
"If the upper bound of the range is omitted, the latest stable compiler is used as the \
738+
upper bound.",
739+
"If the lower bound of the range is omitted, the value of the `rust-version` field in \
740+
`Cargo.toml` is used as the lower bound.",
739741
"Note that ranges are always inclusive ranges.",
740742
],
741743
),

src/rustup.rs

+10
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ pub(crate) fn version_range(
6666
cargo::minor_version(cmd!("cargo", "+stable"))?
6767
}
6868
Some(end) => {
69+
let end = match end.strip_prefix('=') {
70+
Some(end) => end,
71+
None => {
72+
warn!(
73+
"using `..` for inclusive range is deprecated; consider using `{}`",
74+
range.replace("..", "..=")
75+
);
76+
end
77+
}
78+
};
6979
let end = end.parse()?;
7080
check(&end)?;
7181
end.minor

tests/auxiliary/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn cargo_hack<O: AsRef<OsStr>>(args: impl AsRef<[O]>) -> Command {
6262
cmd.arg("hack");
6363
if let Some(toolchain) = test_version() {
6464
if !args.iter().any(|a| a.as_ref().to_str().unwrap().starts_with("--version-range")) {
65-
cmd.arg(format!("--version-range=1.{toolchain}..1.{toolchain}"));
65+
cmd.arg(format!("--version-range=1.{toolchain}..=1.{toolchain}"));
6666
}
6767
}
6868
cmd.args(args);

tests/long-help.txt

+6-3
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,14 @@ OPTIONS:
134134

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

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

140-
If the given range is unclosed, the latest stable compiler is treated as the upper
141-
bound.
140+
If the upper bound of the range is omitted, the latest stable compiler is used as the
141+
upper bound.
142+
143+
If the lower bound of the range is omitted, the value of the `rust-version` field in
144+
`Cargo.toml` is used as the lower bound.
142145

143146
Note that ranges are always inclusive ranges.
144147

tests/short-help.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ OPTIONS:
3434
--ignore-private Skip to perform on `publish = false` packages
3535
--ignore-unknown-features Skip passing --features flag to `cargo` if that feature
3636
does not exist in the package
37-
--version-range <START>..[END] Perform commands on a specified (inclusive) range of Rust
37+
--version-range [START]..[=END] Perform commands on a specified (inclusive) range of Rust
3838
versions
3939
--version-step <NUM> Specify the version interval of --version-range (default
4040
to `1`)

tests/test.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -1318,14 +1318,24 @@ fn default_feature_behavior() {
13181318
#[cfg_attr(windows, ignore)] // rustup bug: https://github.com/rust-lang/rustup/issues/3036
13191319
#[test]
13201320
fn version_range() {
1321-
cargo_hack(["check", "--version-range", "1.63..1.64"]).assert_success("real").stderr_contains(
1321+
cargo_hack(["check", "--version-range", "1.63..=1.64"]).assert_success("real").stderr_contains(
13221322
"
13231323
running `cargo +1.63 check` on real (1/2)
13241324
running `cargo +1.64 check` on real (2/2)
13251325
",
13261326
);
13271327

1328-
cargo_hack(["check", "--version-range", "1.63..1.64", "--target", TARGET])
1328+
cargo_hack(["check", "--version-range", "1.63..1.64"])
1329+
.assert_failure("real") // warn
1330+
.stderr_contains(
1331+
"
1332+
warning: using `..` for inclusive range is deprecated; consider using `1.63..=1.64`
1333+
running `cargo +1.63 check` on real (1/2)
1334+
running `cargo +1.64 check` on real (2/2)
1335+
",
1336+
);
1337+
1338+
cargo_hack(["check", "--version-range", "1.63..=1.64", "--target", TARGET])
13291339
.assert_success("real")
13301340
.stderr_contains(format!(
13311341
"
@@ -1349,7 +1359,7 @@ fn multi_target() {
13491359
cargo_hack([
13501360
"check",
13511361
"--version-range",
1352-
"1.63..1.64",
1362+
"1.63..=1.64",
13531363
"--target",
13541364
&format!("aarch64{target_suffix}"),
13551365
])
@@ -1364,7 +1374,7 @@ fn multi_target() {
13641374
cargo_hack([
13651375
"check",
13661376
"--version-range",
1367-
"1.63..1.64",
1377+
"1.63..=1.64",
13681378
"--target",
13691379
&format!("x86_64{target_suffix}"),
13701380
"--target",
@@ -1382,7 +1392,7 @@ fn multi_target() {
13821392
cargo_hack([
13831393
"check",
13841394
"--version-range",
1385-
"1.63..1.64",
1395+
"1.63..=1.64",
13861396
"--target",
13871397
&format!("x86_64{target_suffix}"),
13881398
"--target",
@@ -1409,6 +1419,9 @@ fn version_range_failure() {
14091419
cargo_hack(["check", "--version-range", "1.45..1.44"])
14101420
.assert_failure("real")
14111421
.stderr_contains("specified version range `1.45..1.44` is empty");
1422+
cargo_hack(["check", "--version-range", "1.45..=1.44"])
1423+
.assert_failure("real")
1424+
.stderr_contains("specified version range `1.45..=1.44` is empty");
14121425

14131426
// v0
14141427
cargo_hack(["check", "--version-range", "0.45.."])

0 commit comments

Comments
 (0)