From 4a6bc6504ad0462b5f73200359575e64d27fddb0 Mon Sep 17 00:00:00 2001 From: Nikita Rushmanov Date: Tue, 5 Mar 2024 08:10:32 -0800 Subject: [PATCH] Test reverse coercion by indirect dep --- crates/resolver-tests/tests/resolve.rs | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/crates/resolver-tests/tests/resolve.rs b/crates/resolver-tests/tests/resolve.rs index b0d6abb66d1c..597f3ce590e5 100644 --- a/crates/resolver-tests/tests/resolve.rs +++ b/crates/resolver-tests/tests/resolve.rs @@ -529,6 +529,50 @@ fn test_wildcard_major_coerced_by_subdepdency() { ); } +#[test] +fn test_wildcard_major_coerced_by_indirect_subdepdency() { + let reg = registry(vec![ + pkg!("foo" => [dep_req("util", "0.1")]), + pkg!("bar" => [dep_req("car", "1.0.0")]), + pkg!("car" => [dep_req("util", "0.2")]), + pkg!(("util", "0.1.0")), + pkg!(("util", "0.2.0")), + pkg!(("util", "0.3.0")), + ]); + + let res = resolve_with_global_context_raw( + vec![ + dep_req("foo", "1.0.0"), + dep_req("bar", "1.0.0"), + dep_req("util", "0.*"), + ], + ®, + &GlobalContext::default().unwrap(), + ) + .unwrap(); + + // In this case, 0.1.0, 0.2.0 and 0.3.0 satisfy root. It should pick the highest + // version that exists in the dependency tree. + assert_eq!( + res.deps(pkg_id("root")).skip(2).next().unwrap().0, + ("util", "0.2.0").to_pkgid() + ); + + let res = res.sort(); + + assert_same( + &res, + &names(&[ + ("root", "1.0.0"), + ("foo", "1.0.0"), + ("bar", "1.0.0"), + ("car", "1.0.0"), + ("util", "0.1.0"), + ("util", "0.2.0"), + ]), + ); +} + #[test] fn test_range_major() { let reg = registry(vec![