Skip to content

Commit 372ff8f

Browse files
committed
test: More update --breaking tests.
1 parent 4dcbca1 commit 372ff8f

File tree

1 file changed

+274
-4
lines changed

1 file changed

+274
-4
lines changed

tests/testsuite/update.rs

Lines changed: 274 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,11 +2014,11 @@ fn update_breaking_specific_packages() {
20142014
.file(
20152015
"Cargo.toml",
20162016
r#"
2017-
[workspace]
2018-
members = ["foo", "bar"]
2017+
[workspace]
2018+
members = ["foo", "bar"]
20192019
2020-
[workspace.dependencies]
2021-
ws = "1.0"
2020+
[workspace.dependencies]
2021+
ws = "1.0"
20222022
"#,
20232023
)
20242024
.file(
@@ -2096,3 +2096,273 @@ fn update_breaking_specific_packages() {
20962096
)
20972097
.run();
20982098
}
2099+
2100+
#[cargo_test]
2101+
fn update_breaking_specific_packages_that_wont_update() {
2102+
Package::new("compatible", "1.0.0").publish();
2103+
Package::new("renamed-from", "1.0.0").publish();
2104+
Package::new("non-semver", "1.0.0").publish();
2105+
Package::new("bar", "1.0.0")
2106+
.add_dep(Dependency::new("transitive-compatible", "1.0.0").build())
2107+
.add_dep(Dependency::new("transitive-incompatible", "1.0.0").build())
2108+
.publish();
2109+
Package::new("transitive-compatible", "1.0.0").publish();
2110+
Package::new("transitive-incompatible", "1.0.0").publish();
2111+
2112+
let crate_manifest = r#"
2113+
# Check if formatting is preserved
2114+
2115+
[package]
2116+
name = "foo"
2117+
version = "0.0.1"
2118+
edition = "2015"
2119+
authors = []
2120+
2121+
[dependencies]
2122+
compatible = "1.0" # Comment
2123+
renamed-to = { package = "renamed-from", version = "1.0" } # Comment
2124+
non-semver = "~1.0" # Comment
2125+
bar = "1.0" # Comment
2126+
"#;
2127+
2128+
let p = project()
2129+
.file("Cargo.toml", crate_manifest)
2130+
.file("src/lib.rs", "")
2131+
.build();
2132+
2133+
p.cargo("generate-lockfile").run();
2134+
let lock_file = p.read_file("Cargo.lock");
2135+
2136+
Package::new("compatible", "1.0.1").publish();
2137+
Package::new("renamed-from", "1.0.1").publish();
2138+
Package::new("non-semver", "1.0.1").publish();
2139+
Package::new("transitive-compatible", "1.0.1").publish();
2140+
Package::new("transitive-incompatible", "1.0.1").publish();
2141+
2142+
Package::new("renamed-from", "2.0.0").publish();
2143+
Package::new("non-semver", "2.0.0").publish();
2144+
Package::new("transitive-incompatible", "2.0.0").publish();
2145+
2146+
p.cargo("update -Zunstable-options --breaking compatible renamed-from non-semver transitive-compatible transitive-incompatible")
2147+
.masquerade_as_nightly_cargo(&["update-breaking"])
2148+
.with_stderr(
2149+
"\
2150+
[UPDATING] `[..]` index
2151+
",
2152+
)
2153+
.run();
2154+
2155+
let crate_manifest_after = p.read_file("Cargo.toml");
2156+
assert_e2e().eq(&crate_manifest_after, crate_manifest);
2157+
2158+
let lock_file_after = p.read_file("Cargo.lock");
2159+
assert_e2e().eq(&lock_file_after, lock_file);
2160+
2161+
p.cargo(
2162+
"update compatible renamed-from non-semver transitive-compatible transitive-incompatible",
2163+
)
2164+
.with_stderr(
2165+
"\
2166+
[UPDATING] `[..]` index
2167+
[LOCKING] 5 packages to latest compatible versions
2168+
[UPDATING] compatible v1.0.0 -> v1.0.1
2169+
[UPDATING] non-semver v1.0.0 -> v1.0.1 (latest: v2.0.0)
2170+
[UPDATING] renamed-from v1.0.0 -> v1.0.1 (latest: v2.0.0)
2171+
[UPDATING] transitive-compatible v1.0.0 -> v1.0.1
2172+
[UPDATING] transitive-incompatible v1.0.0 -> v1.0.1 (latest: v2.0.0)
2173+
",
2174+
)
2175+
.run();
2176+
}
2177+
2178+
#[cargo_test]
2179+
fn update_breaking_without_lock_file() {
2180+
Package::new("compatible", "1.0.0").publish();
2181+
Package::new("incompatible", "1.0.0").publish();
2182+
2183+
let p = project()
2184+
.file(
2185+
"Cargo.toml",
2186+
r#"
2187+
[package]
2188+
name = "foo"
2189+
version = "0.0.1"
2190+
edition = "2015"
2191+
authors = []
2192+
2193+
[dependencies]
2194+
compatible = "1.0" # Comment
2195+
incompatible = "1.0" # Comment
2196+
"#,
2197+
)
2198+
.file("src/lib.rs", "")
2199+
.build();
2200+
2201+
Package::new("compatible", "1.0.1").publish();
2202+
Package::new("incompatible", "1.0.1").publish();
2203+
2204+
Package::new("incompatible", "2.0.0").publish();
2205+
2206+
p.cargo("update -Zunstable-options --breaking")
2207+
.masquerade_as_nightly_cargo(&["update-breaking"])
2208+
.with_stderr(
2209+
"\
2210+
[UPDATING] `[..]` index
2211+
[UPGRADING] incompatible ^1.0 -> ^2.0
2212+
[LOCKING] 3 packages to latest compatible versions
2213+
",
2214+
)
2215+
.run();
2216+
}
2217+
2218+
#[cargo_test]
2219+
fn update_breaking_mixed_compatibility() {
2220+
Package::new("mixed-compatibility", "1.0.0").publish();
2221+
Package::new("mixed-compatibility", "2.0.0").publish();
2222+
2223+
let p = project()
2224+
.file(
2225+
"Cargo.toml",
2226+
r#"
2227+
[workspace]
2228+
members = ["foo", "bar"]
2229+
"#,
2230+
)
2231+
.file(
2232+
"foo/Cargo.toml",
2233+
r#"
2234+
[package]
2235+
name = "foo"
2236+
version = "0.0.1"
2237+
edition = "2015"
2238+
authors = []
2239+
2240+
[dependencies]
2241+
mixed-compatibility = "1.0"
2242+
"#,
2243+
)
2244+
.file("foo/src/lib.rs", "")
2245+
.file(
2246+
"bar/Cargo.toml",
2247+
r#"
2248+
[package]
2249+
name = "bar"
2250+
version = "0.0.1"
2251+
edition = "2015"
2252+
authors = []
2253+
2254+
[dependencies]
2255+
mixed-compatibility = "2.0"
2256+
"#,
2257+
)
2258+
.file("bar/src/lib.rs", "")
2259+
.build();
2260+
2261+
p.cargo("generate-lockfile").run();
2262+
2263+
Package::new("mixed-compatibility", "2.0.1").publish();
2264+
2265+
p.cargo("update -Zunstable-options --breaking")
2266+
.masquerade_as_nightly_cargo(&["update-breaking"])
2267+
.with_stderr(
2268+
"\
2269+
[UPDATING] `[..]` index
2270+
[UPGRADING] mixed-compatibility ^1.0 -> ^2.0
2271+
[LOCKING] 1 package to latest compatible version
2272+
[ADDING] mixed-compatibility v2.0.1
2273+
",
2274+
)
2275+
.run();
2276+
}
2277+
2278+
#[cargo_test]
2279+
fn update_breaking_mixed_renaming() {
2280+
Package::new("renamed-from", "1.0.0").publish();
2281+
2282+
let p = project()
2283+
.file(
2284+
"Cargo.toml",
2285+
r#"
2286+
[workspace]
2287+
members = ["foo", "bar"]
2288+
"#,
2289+
)
2290+
.file(
2291+
"foo/Cargo.toml",
2292+
r#"
2293+
[package]
2294+
name = "foo"
2295+
version = "0.0.1"
2296+
edition = "2015"
2297+
authors = []
2298+
2299+
[dependencies]
2300+
renamed-to = { package = "renamed-from", version = "1.0" }
2301+
"#,
2302+
)
2303+
.file("foo/src/lib.rs", "")
2304+
.file(
2305+
"bar/Cargo.toml",
2306+
r#"
2307+
[package]
2308+
name = "bar"
2309+
version = "0.0.1"
2310+
edition = "2015"
2311+
authors = []
2312+
2313+
[dependencies]
2314+
renamed-from = "1.0"
2315+
"#,
2316+
)
2317+
.file("bar/src/lib.rs", "")
2318+
.build();
2319+
2320+
p.cargo("generate-lockfile").run();
2321+
2322+
Package::new("renamed-from", "2.0.0").publish();
2323+
2324+
p.cargo("update -Zunstable-options --breaking")
2325+
.masquerade_as_nightly_cargo(&["update-breaking"])
2326+
.with_stderr(
2327+
"\
2328+
[UPDATING] `[..]` index
2329+
[UPGRADING] renamed-from ^1.0 -> ^2.0
2330+
[LOCKING] 1 package to latest compatible version
2331+
[ADDING] renamed-from v2.0.0
2332+
",
2333+
)
2334+
.run();
2335+
2336+
let foo_manifest = p.read_file("foo/Cargo.toml");
2337+
let bar_manifest = p.read_file("bar/Cargo.toml");
2338+
2339+
assert_e2e().eq(
2340+
&foo_manifest,
2341+
str![[r#"
2342+
2343+
[package]
2344+
name = "foo"
2345+
version = "0.0.1"
2346+
edition = "2015"
2347+
authors = []
2348+
2349+
[dependencies]
2350+
renamed-to = { package = "renamed-from", version = "2.0" }
2351+
"#]],
2352+
);
2353+
2354+
assert_e2e().eq(
2355+
&bar_manifest,
2356+
str![[r#"
2357+
2358+
[package]
2359+
name = "bar"
2360+
version = "0.0.1"
2361+
edition = "2015"
2362+
authors = []
2363+
2364+
[dependencies]
2365+
renamed-from = "2.0"
2366+
"#]],
2367+
);
2368+
}

0 commit comments

Comments
 (0)