Skip to content

Commit

Permalink
test: lockfile path unstable feature tests and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifropc committed Aug 17, 2024
1 parent ba8b394 commit 97fb258
Showing 1 changed file with 122 additions and 23 deletions.
145 changes: 122 additions & 23 deletions tests/testsuite/lockfile_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,64 @@ use snapbox::str;
use cargo_test_support::compare::assert_e2e;
use cargo_test_support::registry::{Package, RegistryBuilder};
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]
fn basic_lockfile_created() {
let lockfile_path = "mylockfile/is/burried/Cargo.lock";
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(lockfile_path).is_file());
}
Expand All @@ -25,7 +74,12 @@ fn basic_lockfile_read() {
let lockfile_path = "mylockfile/Cargo.lock";
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(lockfile_path).is_file());
Expand All @@ -38,7 +92,12 @@ fn basic_lockfile_override() {
.file("Cargo.lock", "This is an invalid lock file!")
.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());
}
Expand All @@ -62,7 +121,12 @@ fn symlink_in_path() {
fs::create_dir(p.root().join("dst")).unwrap();
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(dst).join("Cargo.lock").is_file());
Expand All @@ -85,7 +149,12 @@ fn symlink_lockfile() {

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());
}
Expand All @@ -103,7 +172,11 @@ fn broken_symlink() {
let p = make_project().symlink_dir(invalid_dst, src).build();
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_stderr_data(str![[
r#"[ERROR] failed to create directory `[ROOT]/foo/somedir/link`
Expand Down Expand Up @@ -131,7 +204,11 @@ fn loop_symlink() {
.build();
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_stderr_data(str![[
r#"[ERROR] failed to create directory `[ROOT]/foo/somedir/link`
Expand All @@ -158,7 +235,11 @@ fn add_lockfile_override() {
let p = make_project()
.file("Cargo.lock", "This is an invalid lock file!")
.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("../bar")
.run();
Expand All @@ -172,7 +253,11 @@ fn clean_lockfile_override() {
let p = make_project()
.file("Cargo.lock", "This is an invalid lock file!")
.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("test_foo")
.run();
Expand All @@ -186,7 +271,11 @@ fn fix_lockfile_override() {
let p = make_project()
.file("Cargo.lock", "This is an invalid lock file!")
.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("test_foo")
.arg("--allow-no-vcs")
Expand All @@ -201,7 +290,11 @@ fn publish_lockfile_read() {
let p = make_project().file(lockfile_path, VALID_LOCKFILE).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())
.run();

Expand Down Expand Up @@ -239,7 +332,11 @@ fn remove_lockfile_override() {
.file("src/main.rs", "fn main() {}")
.file("Cargo.lock", "This is an invalid lock file!")
.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")
.run();

Expand Down Expand Up @@ -272,15 +369,25 @@ bar = "0.1.0"
.build();

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(lockfile_path).is_file());

let lockfile_original = fs::read_to_string(p.root().join(lockfile_path)).unwrap();

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
.root()
Expand Down Expand Up @@ -353,11 +460,3 @@ fn make_project() -> ProjectBuilder {
.file("Cargo.toml", &basic_bin_manifest("test_foo"))
.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)
}

0 comments on commit 97fb258

Please sign in to comment.