Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita240 committed Mar 5, 2024
1 parent 19141bd commit 7532074
Showing 1 changed file with 170 additions and 1 deletion.
171 changes: 170 additions & 1 deletion crates/resolver-tests/tests/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use cargo_util::is_ci;
use resolver_tests::{
assert_contains, assert_same, dep, dep_kind, dep_loc, dep_req, loc_names, names, pkg, pkg_id,
pkg_loc, registry, registry_strategy, remove_dep, resolve, resolve_and_validated,
resolve_with_global_context, PrettyPrintRegistry, SatResolve, ToDep, ToPkgId,
resolve_with_global_context, resolve_with_global_context_raw, PrettyPrintRegistry, SatResolve,
ToDep, ToPkgId,
};

use proptest::prelude::*;
Expand Down Expand Up @@ -425,6 +426,174 @@ fn test_resolving_maximum_version_with_transitive_deps() {
assert!(!res.contains(&("util", "1.1.1").to_pkgid()));
}

#[test]
fn test_wildcard_minor() {
let reg = registry(vec![
pkg!(("util", "0.1.0")),
pkg!(("util", "0.1.1")),
pkg!("foo" => [dep_req("util", "0.1.*")]),
]);

let res = resolve_and_validated(
vec![dep_req("util", "=0.1.0"), dep_req("foo", "1.0.0")],
&reg,
None,
)
.unwrap();

assert_same(
&res,
&names(&[("root", "1.0.0"), ("foo", "1.0.0"), ("util", "0.1.0")]),
);
}

#[test]
fn test_wildcard_major() {
let reg = registry(vec![
pkg!("foo" => [dep_req("util", "0.*")]),
pkg!(("util", "0.1.0")),
pkg!(("util", "0.2.0")),
]);

let res = resolve_and_validated(
vec![dep_req("foo", "1.0.0"), dep_req("util", "=0.1.0")],
&reg,
None,
)
.unwrap();

assert_same(
&res,
&names(&[("root", "1.0.0"), ("foo", "1.0.0"), ("util", "0.1.0")]),
);
}

#[test]
fn test_range_major() {
let reg = registry(vec![
pkg!("foo" => [dep_req("util", ">=0.1,<0.3")]),
pkg!(("util", "0.1.0")),
pkg!(("util", "0.2.0")),
]);

let res = resolve_and_validated(
vec![dep_req("foo", "1.0.0"), dep_req("util", "0.1.0")],
&reg,
None,
)
.unwrap();

assert_same(
&res,
&names(&[("root", "1.0.0"), ("foo", "1.0.0"), ("util", "0.1.0")]),
);
}

#[test]
fn test_wildcard_major_duplicate_selection() {
let reg = registry(vec![
pkg!("foo" => [dep_req("util", "0.*")]),
pkg!("bar" => [dep_req("util", "0.2")]),
pkg!("car" => [dep_req("util", "0.1")]),
pkg!(("util", "0.1.0")),
pkg!(("util", "0.2.0")),
]);

let res = resolve_with_global_context_raw(
vec![
dep_req("foo", "1.0.0"),
dep_req("bar", "1.0.0"),
dep_req("car", "1.0.0"),
],
&reg,
&GlobalContext::default().unwrap(),
)
.unwrap();

// In this case, both 0.1.0 and 0.2.0 satisfy foo. It should pick the highest
// version.
assert_eq!(
res.deps(pkg_id("foo")).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_wildcard_major_coerced_by_subdependency() {
let reg = registry(vec![
pkg!("foo" => [dep_req("util", "0.1")]),
pkg!(("util", "0.1.0")),
pkg!(("util", "0.2.0")),
]);

let res = resolve(vec![dep_req("foo", "1.0.0"), dep_req("util", "0.*")], &reg).unwrap();

// In this case, both 0.1.0 and 0.2.0 satisfy root, but it's being coerced
// by the subdependency of foo.
assert_same(
&res,
&names(&[("root", "1.0.0"), ("foo", "1.0.0"), ("util", "0.1.0")]),
);
}

#[test]
fn test_wildcard_major_coerced_by_indirect_subdependency() {
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.*"),
],
&reg,
&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_resolving_minimum_version_with_transitive_deps() {
let reg = registry(vec![
Expand Down

0 comments on commit 7532074

Please sign in to comment.