Skip to content

Commit a96c3e4

Browse files
committed
test: Add test about update --breaking on prerelease
1 parent b31577d commit a96c3e4

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

src/cargo/util/toml_mut/upgrade.rs

+5
Original file line numberDiff line numberDiff line change
@@ -217,5 +217,10 @@ mod test {
217217
assert_req_bump("1.1.1", "=1.0.0", "=1.1.1");
218218
assert_req_bump("2.0.0", "=1.0.0", "=2.0.0");
219219
}
220+
221+
#[test]
222+
fn caret_prerelease() {
223+
assert_req_bump("1.7.0", "2.0.0-beta.21", "1.7.0");
224+
}
220225
}
221226
}

tests/testsuite/update.rs

+94
Original file line numberDiff line numberDiff line change
@@ -2616,3 +2616,97 @@ fn update_breaking_mixed_pinning_renaming() {
26162616
"#]],
26172617
);
26182618
}
2619+
2620+
#[cargo_test]
2621+
fn update_breaking_pre_release_downgrade() {
2622+
Package::new("bar", "2.0.0-beta.21").publish();
2623+
2624+
let p = project()
2625+
.file(
2626+
"Cargo.toml",
2627+
r#"
2628+
[package]
2629+
name = "foo"
2630+
version = "0.0.1"
2631+
edition = "2015"
2632+
authors = []
2633+
2634+
[dependencies]
2635+
bar = "2.0.0-beta.21"
2636+
"#,
2637+
)
2638+
.file("src/lib.rs", "")
2639+
.build();
2640+
2641+
p.cargo("generate-lockfile").run();
2642+
2643+
// The purpose of this test is
2644+
// to demonstrate that `update --breaking` will not try to downgrade to the latest stable version (1.7.0),
2645+
// but will rather keep the latest pre-release (2.0.0-beta.21).
2646+
Package::new("bar", "1.7.0").publish();
2647+
p.cargo("update -Zunstable-options --breaking bar")
2648+
.masquerade_as_nightly_cargo(&["update-breaking"])
2649+
.with_stderr_data(str![[r#"
2650+
[UPDATING] `dummy-registry` index
2651+
[UPGRADING] bar ^2.0.0-beta.21 -> ^1.7.0
2652+
[LOCKING] 1 package to latest compatible version
2653+
[DOWNGRADING] bar v2.0.0-beta.21 -> v1.7.0
2654+
2655+
"#]])
2656+
.run();
2657+
}
2658+
2659+
#[cargo_test]
2660+
fn update_breaking_pre_release_upgrade() {
2661+
Package::new("bar", "2.0.0-beta.21").publish();
2662+
2663+
let p = project()
2664+
.file(
2665+
"Cargo.toml",
2666+
r#"
2667+
[package]
2668+
name = "foo"
2669+
version = "0.0.1"
2670+
edition = "2015"
2671+
authors = []
2672+
2673+
[dependencies]
2674+
bar = "2.0.0-beta.21"
2675+
"#,
2676+
)
2677+
.file("src/lib.rs", "")
2678+
.build();
2679+
2680+
p.cargo("generate-lockfile").run();
2681+
2682+
// TODO: `2.0.0-beta.21` can be upgraded to `2.0.0-beta.22`
2683+
Package::new("bar", "2.0.0-beta.22").publish();
2684+
p.cargo("update -Zunstable-options --breaking bar")
2685+
.masquerade_as_nightly_cargo(&["update-breaking"])
2686+
.with_stderr_data(str![[r#"
2687+
[UPDATING] `dummy-registry` index
2688+
2689+
"#]])
2690+
.run();
2691+
// TODO: `2.0.0-beta.21` can be upgraded to `2.0.0`
2692+
Package::new("bar", "2.0.0").publish();
2693+
p.cargo("update -Zunstable-options --breaking bar")
2694+
.masquerade_as_nightly_cargo(&["update-breaking"])
2695+
.with_stderr_data(str![[r#"
2696+
[UPDATING] `dummy-registry` index
2697+
2698+
"#]])
2699+
.run();
2700+
2701+
Package::new("bar", "3.0.0").publish();
2702+
p.cargo("update -Zunstable-options --breaking bar")
2703+
.masquerade_as_nightly_cargo(&["update-breaking"])
2704+
.with_stderr_data(str![[r#"
2705+
[UPDATING] `dummy-registry` index
2706+
[UPGRADING] bar ^2.0.0-beta.21 -> ^3.0.0
2707+
[LOCKING] 1 package to latest compatible version
2708+
[UPDATING] bar v2.0.0-beta.21 -> v3.0.0
2709+
2710+
"#]])
2711+
.run();
2712+
}

0 commit comments

Comments
 (0)