Skip to content

Commit

Permalink
test(resolver): Additional direct minimal version tests
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Feb 14, 2023
1 parent 12000a9 commit c07f067
Showing 1 changed file with 214 additions and 4 deletions.
218 changes: 214 additions & 4 deletions tests/testsuite/direct_minimal_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
use cargo_test_support::project;
use cargo_test_support::registry::Package;

// Ensure that the "-Z minimal-versions" CLI option works and the minimal
// version of a dependency ends up in the lock file.
#[cargo_test]
fn minimal_version_cli() {
fn simple() {
Package::new("dep", "1.0.0").publish();
Package::new("dep", "1.1.0").publish();

Expand All @@ -34,5 +32,217 @@ fn minimal_version_cli() {

let lock = p.read_lockfile();

assert!(!lock.contains("1.1.0"));
assert!(
lock.contains("1.0.0"),
"dep minimal version must be present"
);
assert!(
!lock.contains("1.1.0"),
"dep maximimal version cannot be present"
);
}

#[cargo_test]
fn mixed_dependencies() {
Package::new("dep", "1.0.0").publish();
Package::new("dep", "1.1.0").publish();
Package::new("dep", "1.2.0").publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
authors = []
version = "0.0.1"
[dependencies]
dep = "1.0"
[dev-dependencies]
dep = "1.1"
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("generate-lockfile -Zminimal-versions")
.masquerade_as_nightly_cargo(&["minimal-versions"])
.run();

let lock = p.read_lockfile();

assert!(
!lock.contains("1.0.0"),
"dep incompatible version cannot be present"
);
assert!(
lock.contains("1.1.0"),
"dep minimal version must be present"
);
assert!(
!lock.contains("1.2.0"),
"dep maximimal version cannot be present"
);
}

#[cargo_test]
fn yanked() {
Package::new("dep", "1.0.0").yanked(true).publish();
Package::new("dep", "1.1.0").publish();
Package::new("dep", "1.2.0").publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
authors = []
version = "0.0.1"
[dependencies]
dep = "1.0"
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("generate-lockfile -Zminimal-versions")
.masquerade_as_nightly_cargo(&["minimal-versions"])
.run();

let lock = p.read_lockfile();

assert!(
lock.contains("1.1.0"),
"dep minimal version must be present"
);
assert!(
!lock.contains("1.0.0"),
"yanked minimal version must be skipped"
);
assert!(
!lock.contains("1.2.0"),
"dep maximimal version cannot be present"
);
}

#[cargo_test]
fn indirect() {
Package::new("indirect", "2.0.0").publish();
Package::new("indirect", "2.1.0").publish();
Package::new("indirect", "2.2.0").publish();
Package::new("direct", "1.0.0")
.dep("indirect", "2.1")
.publish();
Package::new("direct", "1.1.0")
.dep("indirect", "2.1")
.publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
authors = []
version = "0.0.1"
[dependencies]
direct = "1.0"
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("generate-lockfile -Zminimal-versions")
.masquerade_as_nightly_cargo(&["minimal-versions"])
.run();

let lock = p.read_lockfile();

assert!(
lock.contains("1.0.0"),
"direct minimal version must be present"
);
assert!(
!lock.contains("1.1.0"),
"direct maximimal version cannot be present"
);
assert!(
!lock.contains("2.0.0"),
"indirect unmatched version cannot be present"
);
assert!(
lock.contains("2.1.0"),
"indirect minimal version must be present"
);
assert!(
!lock.contains("2.2.0"),
"indirect maximimal version cannot be present"
);
}

#[cargo_test]
fn indirect_conflict() {
Package::new("indirect", "2.0.0").publish();
Package::new("indirect", "2.1.0").publish();
Package::new("indirect", "2.2.0").publish();
Package::new("direct", "1.0.0")
.dep("indirect", "2.1")
.publish();
Package::new("direct", "1.1.0")
.dep("indirect", "2.1")
.publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
authors = []
version = "0.0.1"
[dependencies]
direct = "1.0"
indirect = "2.0"
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("generate-lockfile -Zminimal-versions")
.masquerade_as_nightly_cargo(&["minimal-versions"])
.with_stderr(
"\
[UPDATING] [..]
",
)
.run();

let lock = p.read_lockfile();

assert!(
lock.contains("1.0.0"),
"direct minimal version must be present"
);
assert!(
!lock.contains("1.1.0"),
"direct maximimal version cannot be present"
);
assert!(
!lock.contains("2.0.0"),
"indirect unmatched version cannot be present"
);
assert!(
lock.contains("2.1.0"),
"indirect minimal version must be present"
);
assert!(
!lock.contains("2.2.0"),
"indirect maximimal version cannot be present"
);
}

0 comments on commit c07f067

Please sign in to comment.