Skip to content

Commit 89b0119

Browse files
committed
test: Add test about update --breaking on prerelease
1 parent 7f20798 commit 89b0119

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

src/cargo/util/toml_mut/upgrade.rs

Lines changed: 5 additions & 0 deletions
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

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

0 commit comments

Comments
 (0)