mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Auto merge of #14417 - Ifropc:lockfile-path-tests, r=weihanglo
Lockfile path tests (follow-up) Addressing comments by [Weihang](https://github.com/rust-lang/cargo/pull/14326#issuecomment-2293664459) and [Ed](https://github.com/rust-lang/cargo/pull/14326#issuecomment-2293671992) from #14326
This commit is contained in:
commit
4494032dbc
@ -7,15 +7,64 @@ use snapbox::str;
|
|||||||
use cargo_test_support::compare::assert_e2e;
|
use cargo_test_support::compare::assert_e2e;
|
||||||
use cargo_test_support::registry::{Package, RegistryBuilder};
|
use cargo_test_support::registry::{Package, RegistryBuilder};
|
||||||
use cargo_test_support::{
|
use cargo_test_support::{
|
||||||
basic_bin_manifest, cargo_test, project, symlink_supported, Execs, ProjectBuilder,
|
basic_bin_manifest, cargo_test, project, symlink_supported, ProjectBuilder,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
///////////////////////////////
|
||||||
|
//// Unstable feature tests start
|
||||||
|
///////////////////////////////
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
fn must_have_unstable_options() {
|
||||||
|
let lockfile_path = "mylockfile/is/burried/Cargo.lock";
|
||||||
|
let p = make_project().build();
|
||||||
|
|
||||||
|
p.cargo("generate-lockfile")
|
||||||
|
.masquerade_as_nightly_cargo(&["lockfile-path"])
|
||||||
|
.arg("--lockfile-path")
|
||||||
|
.arg(lockfile_path)
|
||||||
|
.with_stderr_data(str![[
|
||||||
|
r#"[ERROR] the `--lockfile-path` flag is unstable, pass `-Z unstable-options` to enable it
|
||||||
|
See https://github.com/rust-lang/cargo/issues/5707 for more information about the `--lockfile-path` flag.
|
||||||
|
|
||||||
|
"#]])
|
||||||
|
.with_status(101)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
fn must_be_nightly() {
|
||||||
|
let lockfile_path = "mylockfile/is/burried/Cargo.lock";
|
||||||
|
let p = make_project().build();
|
||||||
|
|
||||||
|
p.cargo("generate-lockfile")
|
||||||
|
.arg("-Zunstable-options")
|
||||||
|
.arg("--lockfile-path")
|
||||||
|
.arg(lockfile_path)
|
||||||
|
.with_stderr_data(str![[
|
||||||
|
r#"[ERROR] the `-Z` flag is only accepted on the nightly channel of Cargo, but this is the `stable` channel
|
||||||
|
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
|
||||||
|
|
||||||
|
"#]])
|
||||||
|
.with_status(101)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////
|
||||||
|
//// Unstable feature tests end
|
||||||
|
///////////////////////////////
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
fn basic_lockfile_created() {
|
fn basic_lockfile_created() {
|
||||||
let lockfile_path = "mylockfile/is/burried/Cargo.lock";
|
let lockfile_path = "mylockfile/is/burried/Cargo.lock";
|
||||||
let p = make_project().build();
|
let p = make_project().build();
|
||||||
|
|
||||||
make_execs(&mut p.cargo("generate-lockfile"), lockfile_path).run();
|
p.cargo("generate-lockfile")
|
||||||
|
.masquerade_as_nightly_cargo(&["lockfile-path"])
|
||||||
|
.arg("-Zunstable-options")
|
||||||
|
.arg("--lockfile-path")
|
||||||
|
.arg(lockfile_path)
|
||||||
|
.run();
|
||||||
assert!(!p.root().join("Cargo.lock").exists());
|
assert!(!p.root().join("Cargo.lock").exists());
|
||||||
assert!(p.root().join(lockfile_path).is_file());
|
assert!(p.root().join(lockfile_path).is_file());
|
||||||
}
|
}
|
||||||
@ -25,7 +74,12 @@ fn basic_lockfile_read() {
|
|||||||
let lockfile_path = "mylockfile/Cargo.lock";
|
let lockfile_path = "mylockfile/Cargo.lock";
|
||||||
let p = make_project().file(lockfile_path, VALID_LOCKFILE).build();
|
let p = make_project().file(lockfile_path, VALID_LOCKFILE).build();
|
||||||
|
|
||||||
make_execs(&mut p.cargo("generate-lockfile"), lockfile_path).run();
|
p.cargo("generate-lockfile")
|
||||||
|
.masquerade_as_nightly_cargo(&["lockfile-path"])
|
||||||
|
.arg("-Zunstable-options")
|
||||||
|
.arg("--lockfile-path")
|
||||||
|
.arg(lockfile_path)
|
||||||
|
.run();
|
||||||
|
|
||||||
assert!(!p.root().join("Cargo.lock").exists());
|
assert!(!p.root().join("Cargo.lock").exists());
|
||||||
assert!(p.root().join(lockfile_path).is_file());
|
assert!(p.root().join(lockfile_path).is_file());
|
||||||
@ -38,7 +92,12 @@ fn basic_lockfile_override() {
|
|||||||
.file("Cargo.lock", "This is an invalid lock file!")
|
.file("Cargo.lock", "This is an invalid lock file!")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
make_execs(&mut p.cargo("generate-lockfile"), lockfile_path).run();
|
p.cargo("generate-lockfile")
|
||||||
|
.masquerade_as_nightly_cargo(&["lockfile-path"])
|
||||||
|
.arg("-Zunstable-options")
|
||||||
|
.arg("--lockfile-path")
|
||||||
|
.arg(lockfile_path)
|
||||||
|
.run();
|
||||||
|
|
||||||
assert!(p.root().join(lockfile_path).is_file());
|
assert!(p.root().join(lockfile_path).is_file());
|
||||||
}
|
}
|
||||||
@ -62,7 +121,12 @@ fn symlink_in_path() {
|
|||||||
fs::create_dir(p.root().join("dst")).unwrap();
|
fs::create_dir(p.root().join("dst")).unwrap();
|
||||||
assert!(p.root().join(src).is_dir());
|
assert!(p.root().join(src).is_dir());
|
||||||
|
|
||||||
make_execs(&mut p.cargo("generate-lockfile"), lockfile_path.as_str()).run();
|
p.cargo("generate-lockfile")
|
||||||
|
.masquerade_as_nightly_cargo(&["lockfile-path"])
|
||||||
|
.arg("-Zunstable-options")
|
||||||
|
.arg("--lockfile-path")
|
||||||
|
.arg(lockfile_path.as_str())
|
||||||
|
.run();
|
||||||
|
|
||||||
assert!(p.root().join(lockfile_path).is_file());
|
assert!(p.root().join(lockfile_path).is_file());
|
||||||
assert!(p.root().join(dst).join("Cargo.lock").is_file());
|
assert!(p.root().join(dst).join("Cargo.lock").is_file());
|
||||||
@ -85,7 +149,12 @@ fn symlink_lockfile() {
|
|||||||
|
|
||||||
assert!(p.root().join(src).is_file());
|
assert!(p.root().join(src).is_file());
|
||||||
|
|
||||||
make_execs(&mut p.cargo("generate-lockfile"), lockfile_path).run();
|
p.cargo("generate-lockfile")
|
||||||
|
.masquerade_as_nightly_cargo(&["lockfile-path"])
|
||||||
|
.arg("-Zunstable-options")
|
||||||
|
.arg("--lockfile-path")
|
||||||
|
.arg(lockfile_path)
|
||||||
|
.run();
|
||||||
|
|
||||||
assert!(!p.root().join("Cargo.lock").exists());
|
assert!(!p.root().join("Cargo.lock").exists());
|
||||||
}
|
}
|
||||||
@ -103,7 +172,11 @@ fn broken_symlink() {
|
|||||||
let p = make_project().symlink_dir(invalid_dst, src).build();
|
let p = make_project().symlink_dir(invalid_dst, src).build();
|
||||||
assert!(!p.root().join(src).is_dir());
|
assert!(!p.root().join(src).is_dir());
|
||||||
|
|
||||||
make_execs(&mut p.cargo("generate-lockfile"), lockfile_path.as_str())
|
p.cargo("generate-lockfile")
|
||||||
|
.masquerade_as_nightly_cargo(&["lockfile-path"])
|
||||||
|
.arg("-Zunstable-options")
|
||||||
|
.arg("--lockfile-path")
|
||||||
|
.arg(lockfile_path)
|
||||||
.with_status(101)
|
.with_status(101)
|
||||||
.with_stderr_data(str![[
|
.with_stderr_data(str![[
|
||||||
r#"[ERROR] failed to create directory `[ROOT]/foo/somedir/link`
|
r#"[ERROR] failed to create directory `[ROOT]/foo/somedir/link`
|
||||||
@ -131,7 +204,11 @@ fn loop_symlink() {
|
|||||||
.build();
|
.build();
|
||||||
assert!(!p.root().join(src).is_dir());
|
assert!(!p.root().join(src).is_dir());
|
||||||
|
|
||||||
make_execs(&mut p.cargo("generate-lockfile"), lockfile_path.as_str())
|
p.cargo("generate-lockfile")
|
||||||
|
.masquerade_as_nightly_cargo(&["lockfile-path"])
|
||||||
|
.arg("-Zunstable-options")
|
||||||
|
.arg("--lockfile-path")
|
||||||
|
.arg(lockfile_path)
|
||||||
.with_status(101)
|
.with_status(101)
|
||||||
.with_stderr_data(str![[
|
.with_stderr_data(str![[
|
||||||
r#"[ERROR] failed to create directory `[ROOT]/foo/somedir/link`
|
r#"[ERROR] failed to create directory `[ROOT]/foo/somedir/link`
|
||||||
@ -158,7 +235,11 @@ fn add_lockfile_override() {
|
|||||||
let p = make_project()
|
let p = make_project()
|
||||||
.file("Cargo.lock", "This is an invalid lock file!")
|
.file("Cargo.lock", "This is an invalid lock file!")
|
||||||
.build();
|
.build();
|
||||||
make_execs(&mut p.cargo("add"), lockfile_path)
|
p.cargo("add")
|
||||||
|
.masquerade_as_nightly_cargo(&["lockfile-path"])
|
||||||
|
.arg("-Zunstable-options")
|
||||||
|
.arg("--lockfile-path")
|
||||||
|
.arg(lockfile_path)
|
||||||
.arg("--path")
|
.arg("--path")
|
||||||
.arg("../bar")
|
.arg("../bar")
|
||||||
.run();
|
.run();
|
||||||
@ -172,7 +253,11 @@ fn clean_lockfile_override() {
|
|||||||
let p = make_project()
|
let p = make_project()
|
||||||
.file("Cargo.lock", "This is an invalid lock file!")
|
.file("Cargo.lock", "This is an invalid lock file!")
|
||||||
.build();
|
.build();
|
||||||
make_execs(&mut p.cargo("clean"), lockfile_path)
|
p.cargo("clean")
|
||||||
|
.masquerade_as_nightly_cargo(&["lockfile-path"])
|
||||||
|
.arg("-Zunstable-options")
|
||||||
|
.arg("--lockfile-path")
|
||||||
|
.arg(lockfile_path)
|
||||||
.arg("--package")
|
.arg("--package")
|
||||||
.arg("test_foo")
|
.arg("test_foo")
|
||||||
.run();
|
.run();
|
||||||
@ -186,7 +271,11 @@ fn fix_lockfile_override() {
|
|||||||
let p = make_project()
|
let p = make_project()
|
||||||
.file("Cargo.lock", "This is an invalid lock file!")
|
.file("Cargo.lock", "This is an invalid lock file!")
|
||||||
.build();
|
.build();
|
||||||
make_execs(&mut p.cargo("fix"), lockfile_path)
|
p.cargo("fix")
|
||||||
|
.masquerade_as_nightly_cargo(&["lockfile-path"])
|
||||||
|
.arg("-Zunstable-options")
|
||||||
|
.arg("--lockfile-path")
|
||||||
|
.arg(lockfile_path)
|
||||||
.arg("--package")
|
.arg("--package")
|
||||||
.arg("test_foo")
|
.arg("test_foo")
|
||||||
.arg("--allow-no-vcs")
|
.arg("--allow-no-vcs")
|
||||||
@ -201,7 +290,11 @@ fn publish_lockfile_read() {
|
|||||||
let p = make_project().file(lockfile_path, VALID_LOCKFILE).build();
|
let p = make_project().file(lockfile_path, VALID_LOCKFILE).build();
|
||||||
let registry = RegistryBuilder::new().http_api().http_index().build();
|
let registry = RegistryBuilder::new().http_api().http_index().build();
|
||||||
|
|
||||||
make_execs(&mut p.cargo("publish"), lockfile_path)
|
p.cargo("publish")
|
||||||
|
.masquerade_as_nightly_cargo(&["lockfile-path"])
|
||||||
|
.arg("-Zunstable-options")
|
||||||
|
.arg("--lockfile-path")
|
||||||
|
.arg(lockfile_path)
|
||||||
.replace_crates_io(registry.index_url())
|
.replace_crates_io(registry.index_url())
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
@ -239,7 +332,11 @@ fn remove_lockfile_override() {
|
|||||||
.file("src/main.rs", "fn main() {}")
|
.file("src/main.rs", "fn main() {}")
|
||||||
.file("Cargo.lock", "This is an invalid lock file!")
|
.file("Cargo.lock", "This is an invalid lock file!")
|
||||||
.build();
|
.build();
|
||||||
make_execs(&mut p.cargo("remove"), lockfile_path)
|
p.cargo("remove")
|
||||||
|
.masquerade_as_nightly_cargo(&["lockfile-path"])
|
||||||
|
.arg("-Zunstable-options")
|
||||||
|
.arg("--lockfile-path")
|
||||||
|
.arg(lockfile_path)
|
||||||
.arg("test_bar")
|
.arg("test_bar")
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
@ -272,7 +369,12 @@ bar = "0.1.0"
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
Package::new("bar", "0.1.0").publish();
|
Package::new("bar", "0.1.0").publish();
|
||||||
make_execs(&mut p.cargo("generate-lockfile"), lockfile_path).run();
|
p.cargo("generate-lockfile")
|
||||||
|
.masquerade_as_nightly_cargo(&["lockfile-path"])
|
||||||
|
.arg("-Zunstable-options")
|
||||||
|
.arg("--lockfile-path")
|
||||||
|
.arg(lockfile_path)
|
||||||
|
.run();
|
||||||
|
|
||||||
assert!(!p.root().join("Cargo.lock").exists());
|
assert!(!p.root().join("Cargo.lock").exists());
|
||||||
assert!(p.root().join(lockfile_path).is_file());
|
assert!(p.root().join(lockfile_path).is_file());
|
||||||
@ -280,7 +382,12 @@ bar = "0.1.0"
|
|||||||
let lockfile_original = fs::read_to_string(p.root().join(lockfile_path)).unwrap();
|
let lockfile_original = fs::read_to_string(p.root().join(lockfile_path)).unwrap();
|
||||||
|
|
||||||
Package::new("bar", "0.1.1").publish();
|
Package::new("bar", "0.1.1").publish();
|
||||||
make_execs(&mut p.cargo("package"), lockfile_path).run();
|
p.cargo("package")
|
||||||
|
.masquerade_as_nightly_cargo(&["lockfile-path"])
|
||||||
|
.arg("-Zunstable-options")
|
||||||
|
.arg("--lockfile-path")
|
||||||
|
.arg(lockfile_path)
|
||||||
|
.run();
|
||||||
|
|
||||||
assert!(p
|
assert!(p
|
||||||
.root()
|
.root()
|
||||||
@ -353,11 +460,3 @@ fn make_project() -> ProjectBuilder {
|
|||||||
.file("Cargo.toml", &basic_bin_manifest("test_foo"))
|
.file("Cargo.toml", &basic_bin_manifest("test_foo"))
|
||||||
.file("src/main.rs", "fn main() {}")
|
.file("src/main.rs", "fn main() {}")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_execs<'a>(execs: &'a mut Execs, lockfile_path_argument: &str) -> &'a mut Execs {
|
|
||||||
execs
|
|
||||||
.masquerade_as_nightly_cargo(&["lockfile-path"])
|
|
||||||
.arg("-Zunstable-options")
|
|
||||||
.arg("--lockfile-path")
|
|
||||||
.arg(lockfile_path_argument)
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user