Skip to content

Commit

Permalink
test: More update --breaking tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
torhovland committed Jun 12, 2024
1 parent 4dcbca1 commit 7bdf956
Showing 1 changed file with 277 additions and 8 deletions.
285 changes: 277 additions & 8 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1923,8 +1923,7 @@ fn update_breaking() {
[workspace.dependencies]
ws = "2.0" # This line gets partially rewritten
"#]],
"#]],
);

let foo_manifest = p.read_file("foo/Cargo.toml");
Expand Down Expand Up @@ -2014,12 +2013,12 @@ fn update_breaking_specific_packages() {
.file(
"Cargo.toml",
r#"
[workspace]
members = ["foo", "bar"]
[workspace]
members = ["foo", "bar"]
[workspace.dependencies]
ws = "1.0"
"#,
[workspace.dependencies]
ws = "1.0"
"#,
)
.file(
"foo/Cargo.toml",
Expand Down Expand Up @@ -2050,7 +2049,7 @@ fn update_breaking_specific_packages() {
just-bar = "1.0"
shared = "1.0"
ws.workspace = true
"#,
"#,
)
.file("bar/src/lib.rs", "")
.build();
Expand Down Expand Up @@ -2096,3 +2095,273 @@ fn update_breaking_specific_packages() {
)
.run();
}

#[cargo_test]
fn update_breaking_specific_packages_that_wont_update() {
Package::new("compatible", "1.0.0").publish();
Package::new("renamed-from", "1.0.0").publish();
Package::new("non-semver", "1.0.0").publish();
Package::new("bar", "1.0.0")
.add_dep(Dependency::new("transitive-compatible", "1.0.0").build())
.add_dep(Dependency::new("transitive-incompatible", "1.0.0").build())
.publish();
Package::new("transitive-compatible", "1.0.0").publish();
Package::new("transitive-incompatible", "1.0.0").publish();

let crate_manifest = r#"
# Check if formatting is preserved
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
[dependencies]
compatible = "1.0" # Comment
renamed-to = { package = "renamed-from", version = "1.0" } # Comment
non-semver = "~1.0" # Comment
bar = "1.0" # Comment
"#;

let p = project()
.file("Cargo.toml", crate_manifest)
.file("src/lib.rs", "")
.build();

p.cargo("generate-lockfile").run();
let lock_file = p.read_file("Cargo.lock");

Package::new("compatible", "1.0.1").publish();
Package::new("renamed-from", "1.0.1").publish();
Package::new("non-semver", "1.0.1").publish();
Package::new("transitive-compatible", "1.0.1").publish();
Package::new("transitive-incompatible", "1.0.1").publish();

Package::new("renamed-from", "2.0.0").publish();
Package::new("non-semver", "2.0.0").publish();
Package::new("transitive-incompatible", "2.0.0").publish();

p.cargo("update -Zunstable-options --breaking compatible renamed-from non-semver transitive-compatible transitive-incompatible")
.masquerade_as_nightly_cargo(&["update-breaking"])
.with_stderr(
"\
[UPDATING] `[..]` index
",
)
.run();

let crate_manifest_after = p.read_file("Cargo.toml");
assert_e2e().eq(&crate_manifest_after, crate_manifest);

let lock_file_after = p.read_file("Cargo.lock");
assert_e2e().eq(&lock_file_after, lock_file);

p.cargo(
"update compatible renamed-from non-semver transitive-compatible transitive-incompatible",
)
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 5 packages to latest compatible versions
[UPDATING] compatible v1.0.0 -> v1.0.1
[UPDATING] non-semver v1.0.0 -> v1.0.1 (latest: v2.0.0)
[UPDATING] renamed-from v1.0.0 -> v1.0.1 (latest: v2.0.0)
[UPDATING] transitive-compatible v1.0.0 -> v1.0.1
[UPDATING] transitive-incompatible v1.0.0 -> v1.0.1 (latest: v2.0.0)
",
)
.run();
}

#[cargo_test]
fn update_breaking_without_lock_file() {
Package::new("compatible", "1.0.0").publish();
Package::new("incompatible", "1.0.0").publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
[dependencies]
compatible = "1.0" # Comment
incompatible = "1.0" # Comment
"#,
)
.file("src/lib.rs", "")
.build();

Package::new("compatible", "1.0.1").publish();
Package::new("incompatible", "1.0.1").publish();

Package::new("incompatible", "2.0.0").publish();

p.cargo("update -Zunstable-options --breaking")
.masquerade_as_nightly_cargo(&["update-breaking"])
.with_stderr(
"\
[UPDATING] `[..]` index
[UPGRADING] incompatible ^1.0 -> ^2.0
[LOCKING] 3 packages to latest compatible versions
",
)
.run();
}

#[cargo_test]
fn update_breaking_mixed_compatibility() {
Package::new("mixed-compatibility", "1.0.0").publish();
Package::new("mixed-compatibility", "2.0.0").publish();

let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["foo", "bar"]
"#,
)
.file(
"foo/Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
[dependencies]
mixed-compatibility = "1.0"
"#,
)
.file("foo/src/lib.rs", "")
.file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
edition = "2015"
authors = []
[dependencies]
mixed-compatibility = "2.0"
"#,
)
.file("bar/src/lib.rs", "")
.build();

p.cargo("generate-lockfile").run();

Package::new("mixed-compatibility", "2.0.1").publish();

p.cargo("update -Zunstable-options --breaking")
.masquerade_as_nightly_cargo(&["update-breaking"])
.with_stderr(
"\
[UPDATING] `[..]` index
[UPGRADING] mixed-compatibility ^1.0 -> ^2.0
[LOCKING] 1 package to latest compatible version
[ADDING] mixed-compatibility v2.0.1
",
)
.run();
}

#[cargo_test]
fn update_breaking_mixed_renaming() {
Package::new("renamed-from", "1.0.0").publish();

let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["foo", "bar"]
"#,
)
.file(
"foo/Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
[dependencies]
renamed-to = { package = "renamed-from", version = "1.0" }
"#,
)
.file("foo/src/lib.rs", "")
.file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
edition = "2015"
authors = []
[dependencies]
renamed-from = "1.0"
"#,
)
.file("bar/src/lib.rs", "")
.build();

p.cargo("generate-lockfile").run();

Package::new("renamed-from", "2.0.0").publish();

p.cargo("update -Zunstable-options --breaking")
.masquerade_as_nightly_cargo(&["update-breaking"])
.with_stderr(
"\
[UPDATING] `[..]` index
[UPGRADING] renamed-from ^1.0 -> ^2.0
[LOCKING] 1 package to latest compatible version
[ADDING] renamed-from v2.0.0
",
)
.run();

let foo_manifest = p.read_file("foo/Cargo.toml");
let bar_manifest = p.read_file("bar/Cargo.toml");

assert_e2e().eq(
&foo_manifest,
str![[r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
[dependencies]
renamed-to = { package = "renamed-from", version = "2.0" }
"#]],
);

assert_e2e().eq(
&bar_manifest,
str![[r#"
[package]
name = "bar"
version = "0.0.1"
edition = "2015"
authors = []
[dependencies]
renamed-from = "2.0"
"#]],
);
}

0 comments on commit 7bdf956

Please sign in to comment.