Skip to content

Commit 7bdf956

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

File tree

1 file changed

+277
-8
lines changed

1 file changed

+277
-8
lines changed

tests/testsuite/update.rs

Lines changed: 277 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,8 +1923,7 @@ fn update_breaking() {
19231923
19241924
[workspace.dependencies]
19251925
ws = "2.0" # This line gets partially rewritten
1926-
1927-
"#]],
1926+
"#]],
19281927
);
19291928

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

0 commit comments

Comments
 (0)