diff --git a/tests/testsuite/lockfile_path.rs b/tests/testsuite/lockfile_path.rs index 2e04cdd744b..01465a3a266 100644 --- a/tests/testsuite/lockfile_path.rs +++ b/tests/testsuite/lockfile_path.rs @@ -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()); } @@ -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()); @@ -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()); } @@ -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()); @@ -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()); } @@ -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` @@ -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` @@ -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(); @@ -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(); @@ -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") @@ -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(); @@ -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(); @@ -272,7 +369,12 @@ 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()); @@ -280,7 +382,12 @@ bar = "0.1.0" 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() @@ -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) -}