diff options
Diffstat (limited to 'src/tools/cargo/tests')
148 files changed, 3000 insertions, 866 deletions
diff --git a/src/tools/cargo/tests/testsuite/artifact_dep.rs b/src/tools/cargo/tests/testsuite/artifact_dep.rs index 64aa9d8af..c51298735 100644 --- a/src/tools/cargo/tests/testsuite/artifact_dep.rs +++ b/src/tools/cargo/tests/testsuite/artifact_dep.rs @@ -2152,6 +2152,7 @@ fn doc_lib_true() { [DOCUMENTING] bar v0.0.1 ([CWD]/bar) [DOCUMENTING] foo v0.0.1 ([CWD]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -2227,6 +2228,7 @@ fn rustdoc_works_on_libs_with_artifacts_and_lib_false() { [COMPILING] bar v0.5.0 ([CWD]/bar) [DOCUMENTING] foo v0.0.1 ([CWD]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); diff --git a/src/tools/cargo/tests/testsuite/bad_config.rs b/src/tools/cargo/tests/testsuite/bad_config.rs index 82da880ea..1d3bb9ee1 100644 --- a/src/tools/cargo/tests/testsuite/bad_config.rs +++ b/src/tools/cargo/tests/testsuite/bad_config.rs @@ -373,7 +373,7 @@ Caused by: failed to clone into: [..] Caused by: - URLs need to specify the path to the repository + URL \"git://host.xz\" does not specify a path to a repository " } else { "\ @@ -1664,3 +1664,37 @@ note: Sources are not allowed to be defined multiple times. ) .run(); } + +#[cargo_test] +fn bad_trim_paths() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.0" + + [profile.dev] + trim-paths = "split-debuginfo" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check -Ztrim-paths") + .masquerade_as_nightly_cargo(&["trim-paths"]) + .with_status(101) + .with_stderr( + r#"error: failed to parse manifest at `[..]` + +Caused by: + TOML parse error at line 7, column 30 + | + 7 | trim-paths = "split-debuginfo" + | ^^^^^^^^^^^^^^^^^ + expected a boolean, "none", "diagnostics", "macro", "object", "all", or an array with these options +"#, + ) + .run(); +} diff --git a/src/tools/cargo/tests/testsuite/build.rs b/src/tools/cargo/tests/testsuite/build.rs index 1afa83918..23840ad9a 100644 --- a/src/tools/cargo/tests/testsuite/build.rs +++ b/src/tools/cargo/tests/testsuite/build.rs @@ -159,6 +159,29 @@ For more information, try '--help'. } #[cargo_test] +fn cargo_compile_with_unsupported_short_config_flag() { + let p = project() + .file("Cargo.toml", &basic_bin_manifest("foo")) + .file("src/foo.rs", &main_file(r#""i am foo""#, &[])) + .build(); + + p.cargo("build -c net.git-fetch-with-cli=true") + .with_stderr( + "\ +error: unexpected argument '-c' found + + tip: a similar argument exists: '--config' + +Usage: cargo[EXE] build [OPTIONS] + +For more information, try '--help'. +", + ) + .with_status(1) + .run(); +} + +#[cargo_test] fn cargo_compile_with_workspace_excluded() { let p = project().file("src/main.rs", "fn main() {}").build(); @@ -183,6 +206,30 @@ fn cargo_compile_manifest_path() { } #[cargo_test] +fn cargo_compile_with_wrong_manifest_path_flag() { + let p = project() + .file("Cargo.toml", &basic_bin_manifest("foo")) + .file("src/foo.rs", &main_file(r#""i am foo""#, &[])) + .build(); + + p.cargo("build --path foo/Cargo.toml") + .cwd(p.root().parent().unwrap()) + .with_stderr( + "\ +error: unexpected argument '--path' found + + tip: a similar argument exists: '--manifest-path' + +Usage: cargo[EXE] build [OPTIONS] + +For more information, try '--help'. +", + ) + .with_status(1) + .run(); +} + +#[cargo_test] fn chdir_gated() { let p = project() .file("Cargo.toml", &basic_bin_manifest("foo")) @@ -222,6 +269,33 @@ fn cargo_compile_directory_not_cwd() { } #[cargo_test] +fn cargo_compile_with_unsupported_short_unstable_feature_flag() { + let p = project() + .file("Cargo.toml", &basic_bin_manifest("foo")) + .file("src/foo.rs", &main_file(r#""i am foo""#, &[])) + .file(".cargo/config.toml", &"") + .build(); + + p.cargo("-zunstable-options -C foo build") + .masquerade_as_nightly_cargo(&["chdir"]) + .cwd(p.root().parent().unwrap()) + .with_stderr( + "\ +error: unexpected argument '-z' found + + tip: a similar argument exists: '-Z' + +Usage: cargo [..][OPTIONS] [COMMAND] + cargo [..][OPTIONS] -Zscript <MANIFEST_RS> [ARGS]... + +For more information, try '--help'. +", + ) + .with_status(1) + .run(); +} + +#[cargo_test] fn cargo_compile_directory_not_cwd_with_invalid_config() { let p = project() .file("Cargo.toml", &basic_bin_manifest("foo")) @@ -465,7 +539,7 @@ fn cargo_compile_with_forbidden_bin_target_name() { [ERROR] failed to parse manifest at `[..]` Caused by: - the binary target name `build` is forbidden, it conflicts with with cargo's build directory names + the binary target name `build` is forbidden, it conflicts with cargo's build directory names ", ) .run(); @@ -4190,6 +4264,30 @@ fn cargo_build_empty_target() { } #[cargo_test] +fn cargo_build_with_unsupported_short_target_flag() { + let p = project() + .file("Cargo.toml", &basic_bin_manifest("foo")) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("build -t") + .arg("") + .with_stderr( + "\ +error: unexpected argument '-t' found + + tip: a similar argument exists: '--target' + +Usage: cargo[EXE] build [OPTIONS] + +For more information, try '--help'. +", + ) + .with_status(1) + .run(); +} + +#[cargo_test] fn build_all_workspace() { let p = project() .file( @@ -4255,6 +4353,43 @@ fn build_all_exclude() { } #[cargo_test] +fn cargo_build_with_unsupported_short_exclude_flag() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + + [workspace] + members = ["bar", "baz"] + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") + .file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0")) + .file("baz/src/lib.rs", "pub fn baz() { break_the_build(); }") + .build(); + + p.cargo("build --workspace -x baz") + .with_stderr( + "\ +error: unexpected argument '-x' found + + tip: a similar argument exists: '--exclude' + +Usage: cargo[EXE] build [OPTIONS] + +For more information, try '--help'. +", + ) + .with_status(1) + .run(); +} + +#[cargo_test] fn build_all_exclude_not_found() { let p = project() .file( diff --git a/src/tools/cargo/tests/testsuite/build_script.rs b/src/tools/cargo/tests/testsuite/build_script.rs index 0ccbb4e27..408ce6457 100644 --- a/src/tools/cargo/tests/testsuite/build_script.rs +++ b/src/tools/cargo/tests/testsuite/build_script.rs @@ -1471,6 +1471,7 @@ fn testing_and_such() { [DOCUMENTING] foo v0.5.0 ([CWD]) [RUNNING] `rustdoc [..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -3778,8 +3779,8 @@ fn warnings_emitted() { [COMPILING] foo v0.5.0 ([..]) [RUNNING] `rustc [..]` [RUNNING] `[..]` -warning: foo -warning: bar +warning: foo@0.5.0: foo +warning: foo@0.5.0: bar [RUNNING] `rustc [..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] ", @@ -3816,7 +3817,7 @@ fn warnings_emitted_when_build_script_panics() { p.cargo("build") .with_status(101) .with_stdout("") - .with_stderr_contains("warning: foo\nwarning: bar") + .with_stderr_contains("warning: foo@0.5.0: foo\nwarning: foo@0.5.0: bar") .run(); } @@ -3929,8 +3930,8 @@ fn warnings_printed_on_vv() { [COMPILING] bar v0.1.0 [RUNNING] `[..] rustc [..]` [RUNNING] `[..]` -warning: foo -warning: bar +warning: bar@0.1.0: foo +warning: bar@0.1.0: bar [RUNNING] `[..] rustc [..]` [COMPILING] foo v0.5.0 ([..]) [RUNNING] `[..] rustc [..]` diff --git a/src/tools/cargo/tests/testsuite/build_script_env.rs b/src/tools/cargo/tests/testsuite/build_script_env.rs index df574600c..afa2925f1 100644 --- a/src/tools/cargo/tests/testsuite/build_script_env.rs +++ b/src/tools/cargo/tests/testsuite/build_script_env.rs @@ -137,12 +137,12 @@ fn rustc_bootstrap() { // NOTE: uses RUSTC_BOOTSTRAP so it will be propagated to rustc // (this matters when tests are being run with a beta or stable cargo) .env("RUSTC_BOOTSTRAP", "1") - .with_stderr_contains("warning: Cannot set `RUSTC_BOOTSTRAP=1` [..]") + .with_stderr_contains("warning: has-dashes@0.0.1: Cannot set `RUSTC_BOOTSTRAP=1` [..]") .run(); // RUSTC_BOOTSTRAP set to the name of the library should warn p.cargo("check") .env("RUSTC_BOOTSTRAP", "has_dashes") - .with_stderr_contains("warning: Cannot set `RUSTC_BOOTSTRAP=1` [..]") + .with_stderr_contains("warning: has-dashes@0.0.1: Cannot set `RUSTC_BOOTSTRAP=1` [..]") .run(); // RUSTC_BOOTSTRAP set to some random value should error p.cargo("check") @@ -169,7 +169,7 @@ fn rustc_bootstrap() { // NOTE: uses RUSTC_BOOTSTRAP so it will be propagated to rustc // (this matters when tests are being run with a beta or stable cargo) .env("RUSTC_BOOTSTRAP", "1") - .with_stderr_contains("warning: Cannot set `RUSTC_BOOTSTRAP=1` [..]") + .with_stderr_contains("warning: foo@0.0.1: Cannot set `RUSTC_BOOTSTRAP=1` [..]") .run(); // RUSTC_BOOTSTRAP conditionally set when there's no library should error (regardless of the value) p.cargo("check") @@ -181,6 +181,22 @@ fn rustc_bootstrap() { } #[cargo_test] +fn build_script_env_verbose() { + let build_rs = r#" + fn main() {} + "#; + let p = project() + .file("Cargo.toml", &basic_manifest("verbose-build", "0.0.1")) + .file("src/lib.rs", "") + .file("build.rs", build_rs) + .build(); + + p.cargo("check -vv") + .with_stderr_contains("[RUNNING] `[..]CARGO=[..]build-script-build`") + .run(); +} + +#[cargo_test] #[cfg(target_arch = "x86_64")] fn build_script_sees_cfg_target_feature() { let build_rs = r#" diff --git a/src/tools/cargo/tests/testsuite/build_script_extra_link_arg.rs b/src/tools/cargo/tests/testsuite/build_script_extra_link_arg.rs index ade262fec..964a55e97 100644 --- a/src/tools/cargo/tests/testsuite/build_script_extra_link_arg.rs +++ b/src/tools/cargo/tests/testsuite/build_script_extra_link_arg.rs @@ -204,7 +204,7 @@ fn cdylib_link_arg_transitive() { [COMPILING] bar v1.0.0 [..] [RUNNING] `rustc --crate-name build_script_build bar/build.rs [..] [RUNNING] `[..]build-script-build[..] -warning: cargo:rustc-link-arg-cdylib was specified in the build script of bar v1.0.0 \ +warning: bar@1.0.0: cargo:rustc-link-arg-cdylib was specified in the build script of bar v1.0.0 \ ([ROOT]/foo/bar), but that package does not contain a cdylib target Allowing this was an unintended change in the 1.50 release, and may become an error in \ diff --git a/src/tools/cargo/tests/testsuite/cache_lock.rs b/src/tools/cargo/tests/testsuite/cache_lock.rs new file mode 100644 index 000000000..f5b681f3a --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cache_lock.rs @@ -0,0 +1,304 @@ +//! Tests for `CacheLock`. + +use crate::config::ConfigBuilder; +use cargo::util::cache_lock::{CacheLockMode, CacheLocker}; +use cargo_test_support::paths::{self, CargoPathExt}; +use cargo_test_support::{retry, thread_wait_timeout, threaded_timeout}; +use std::thread::JoinHandle; + +/// Helper to verify that it is OK to acquire the given lock (it shouldn't block). +fn verify_lock_is_ok(mode: CacheLockMode) { + let root = paths::root(); + threaded_timeout(10, move || { + let config = ConfigBuilder::new().root(root).build(); + let locker = CacheLocker::new(); + // This would block if it is held. + let _lock = locker.lock(&config, mode).unwrap(); + assert!(locker.is_locked(mode)); + }); +} + +/// Helper to acquire two locks from the same locker. +fn a_b_nested(a: CacheLockMode, b: CacheLockMode) { + let config = ConfigBuilder::new().build(); + let locker = CacheLocker::new(); + let lock1 = locker.lock(&config, a).unwrap(); + assert!(locker.is_locked(a)); + let lock2 = locker.lock(&config, b).unwrap(); + assert!(locker.is_locked(b)); + drop(lock2); + drop(lock1); + // Verify locks were unlocked. + verify_lock_is_ok(CacheLockMode::Shared); + verify_lock_is_ok(CacheLockMode::DownloadExclusive); + verify_lock_is_ok(CacheLockMode::MutateExclusive); +} + +/// Helper to acquire two locks from separate lockers, verifying that they +/// don't block each other. +fn a_then_b_separate_not_blocked(a: CacheLockMode, b: CacheLockMode, verify: CacheLockMode) { + let config = ConfigBuilder::new().build(); + let locker1 = CacheLocker::new(); + let lock1 = locker1.lock(&config, a).unwrap(); + assert!(locker1.is_locked(a)); + let locker2 = CacheLocker::new(); + let lock2 = locker2.lock(&config, b).unwrap(); + assert!(locker2.is_locked(b)); + let thread = verify_lock_would_block(verify); + // Unblock the thread. + drop(lock1); + drop(lock2); + // Verify the thread is unblocked. + thread_wait_timeout::<()>(100, thread); +} + +/// Helper to acquire two locks from separate lockers, verifying that the +/// second one blocks. +fn a_then_b_separate_blocked(a: CacheLockMode, b: CacheLockMode) { + let config = ConfigBuilder::new().build(); + let locker = CacheLocker::new(); + let lock = locker.lock(&config, a).unwrap(); + assert!(locker.is_locked(a)); + let thread = verify_lock_would_block(b); + // Unblock the thread. + drop(lock); + // Verify the thread is unblocked. + thread_wait_timeout::<()>(100, thread); +} + +/// Helper to verify that acquiring the given mode would block. +/// +/// Always call `thread_wait_timeout` on the result. +#[must_use] +fn verify_lock_would_block(mode: CacheLockMode) -> JoinHandle<()> { + let root = paths::root(); + // Spawn a thread that will block on the lock. + let thread = std::thread::spawn(move || { + let config = ConfigBuilder::new().root(root).build(); + let locker2 = CacheLocker::new(); + let lock2 = locker2.lock(&config, mode).unwrap(); + assert!(locker2.is_locked(mode)); + drop(lock2); + }); + // Verify that it blocked. + retry(100, || { + if let Ok(s) = std::fs::read_to_string(paths::root().join("shell.out")) { + if s.trim().starts_with("Blocking waiting for file lock on") { + return Some(()); + } else { + eprintln!("unexpected output: {s}"); + // Try again, it might have been partially written. + } + } + None + }); + thread +} + +#[test] +fn new_is_unlocked() { + let locker = CacheLocker::new(); + assert!(!locker.is_locked(CacheLockMode::Shared)); + assert!(!locker.is_locked(CacheLockMode::DownloadExclusive)); + assert!(!locker.is_locked(CacheLockMode::MutateExclusive)); +} + +#[cargo_test] +fn multiple_shared() { + // Test that two nested shared locks from the same locker are safe to acquire. + a_b_nested(CacheLockMode::Shared, CacheLockMode::Shared); +} + +#[cargo_test] +fn multiple_shared_separate() { + // Test that two independent shared locks are safe to acquire at the same time. + a_then_b_separate_not_blocked( + CacheLockMode::Shared, + CacheLockMode::Shared, + CacheLockMode::MutateExclusive, + ); +} + +#[cargo_test] +fn multiple_download() { + // That that two nested download locks from the same locker are safe to acquire. + a_b_nested( + CacheLockMode::DownloadExclusive, + CacheLockMode::DownloadExclusive, + ); +} + +#[cargo_test] +fn multiple_mutate() { + // That that two nested mutate locks from the same locker are safe to acquire. + a_b_nested( + CacheLockMode::MutateExclusive, + CacheLockMode::MutateExclusive, + ); +} + +#[cargo_test] +#[should_panic(expected = "lock is not allowed")] +fn download_then_shared() { + // This sequence is not supported. + a_b_nested(CacheLockMode::DownloadExclusive, CacheLockMode::Shared); +} + +#[cargo_test] +#[should_panic(expected = "lock upgrade from shared to exclusive not supported")] +fn shared_then_mutate() { + // This sequence is not supported. + a_b_nested(CacheLockMode::Shared, CacheLockMode::MutateExclusive); +} + +#[cargo_test] +fn shared_then_download() { + a_b_nested(CacheLockMode::Shared, CacheLockMode::DownloadExclusive); + // Verify drop actually unlocked. + verify_lock_is_ok(CacheLockMode::DownloadExclusive); + verify_lock_is_ok(CacheLockMode::MutateExclusive); +} + +#[cargo_test] +fn mutate_then_shared() { + a_b_nested(CacheLockMode::MutateExclusive, CacheLockMode::Shared); + // Verify drop actually unlocked. + verify_lock_is_ok(CacheLockMode::MutateExclusive); +} + +#[cargo_test] +fn download_then_mutate() { + a_b_nested( + CacheLockMode::DownloadExclusive, + CacheLockMode::MutateExclusive, + ); + // Verify drop actually unlocked. + verify_lock_is_ok(CacheLockMode::DownloadExclusive); + verify_lock_is_ok(CacheLockMode::MutateExclusive); +} + +#[cargo_test] +fn mutate_then_download() { + a_b_nested( + CacheLockMode::MutateExclusive, + CacheLockMode::DownloadExclusive, + ); + // Verify drop actually unlocked. + verify_lock_is_ok(CacheLockMode::MutateExclusive); + verify_lock_is_ok(CacheLockMode::DownloadExclusive); +} + +#[cargo_test] +fn readonly() { + // In a permission denied situation, it should still allow a lock. It just + // silently behaves as-if it was locked. + let cargo_home = paths::home().join(".cargo"); + std::fs::create_dir_all(&cargo_home).unwrap(); + let mut perms = std::fs::metadata(&cargo_home).unwrap().permissions(); + perms.set_readonly(true); + std::fs::set_permissions(&cargo_home, perms).unwrap(); + let config = ConfigBuilder::new().build(); + let locker = CacheLocker::new(); + for mode in [ + CacheLockMode::Shared, + CacheLockMode::DownloadExclusive, + CacheLockMode::MutateExclusive, + ] { + let _lock1 = locker.lock(&config, mode).unwrap(); + // Make sure it can recursively acquire the lock, too. + let _lock2 = locker.lock(&config, mode).unwrap(); + } +} + +#[cargo_test] +fn download_then_shared_separate() { + a_then_b_separate_not_blocked( + CacheLockMode::DownloadExclusive, + CacheLockMode::Shared, + CacheLockMode::MutateExclusive, + ); +} + +#[cargo_test] +fn shared_then_download_separate() { + a_then_b_separate_not_blocked( + CacheLockMode::Shared, + CacheLockMode::DownloadExclusive, + CacheLockMode::MutateExclusive, + ); +} + +#[cargo_test] +fn multiple_download_separate() { + // Test that with two independent download locks, the second blocks until + // the first is released. + a_then_b_separate_blocked( + CacheLockMode::DownloadExclusive, + CacheLockMode::DownloadExclusive, + ); +} + +#[cargo_test] +fn multiple_mutate_separate() { + // Test that with two independent mutate locks, the second blocks until + // the first is released. + a_then_b_separate_blocked( + CacheLockMode::MutateExclusive, + CacheLockMode::MutateExclusive, + ); +} + +#[cargo_test] +fn shared_then_mutate_separate() { + a_then_b_separate_blocked(CacheLockMode::Shared, CacheLockMode::MutateExclusive); +} + +#[cargo_test] +fn download_then_mutate_separate() { + a_then_b_separate_blocked( + CacheLockMode::DownloadExclusive, + CacheLockMode::MutateExclusive, + ); +} + +#[cargo_test] +fn mutate_then_download_separate() { + a_then_b_separate_blocked( + CacheLockMode::MutateExclusive, + CacheLockMode::DownloadExclusive, + ); +} + +#[cargo_test] +fn mutate_then_shared_separate() { + a_then_b_separate_blocked(CacheLockMode::MutateExclusive, CacheLockMode::Shared); +} + +#[cargo_test(ignore_windows = "no method to prevent creating or locking a file")] +fn mutate_err_is_atomic() { + // Verifies that when getting a mutate lock, that if the first lock + // succeeds, but the second one fails, that the first lock is released. + let config = ConfigBuilder::new().build(); + let locker = CacheLocker::new(); + let cargo_home = config.home().as_path_unlocked(); + let cache_path = cargo_home.join(".package-cache"); + // This is a hacky way to force an error acquiring the download lock. By + // making it a directory, it is unable to open it. + // TODO: Unfortunately this doesn't work on Windows. I don't have any + // ideas on how to simulate an error on Windows. + cache_path.mkdir_p(); + match locker.lock(&config, CacheLockMode::MutateExclusive) { + Ok(_) => panic!("did not expect lock to succeed"), + Err(e) => { + let msg = format!("{e:?}"); + assert!(msg.contains("failed to open:"), "{msg}"); + } + } + assert!(!locker.is_locked(CacheLockMode::MutateExclusive)); + assert!(!locker.is_locked(CacheLockMode::DownloadExclusive)); + assert!(!locker.is_locked(CacheLockMode::Shared)); + cache_path.rm_rf(); + verify_lock_is_ok(CacheLockMode::DownloadExclusive); + verify_lock_is_ok(CacheLockMode::Shared); + verify_lock_is_ok(CacheLockMode::MutateExclusive); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_add/mod.rs b/src/tools/cargo/tests/testsuite/cargo_add/mod.rs index 8c03b30dc..e8633b0c4 100644 --- a/src/tools/cargo/tests/testsuite/cargo_add/mod.rs +++ b/src/tools/cargo/tests/testsuite/cargo_add/mod.rs @@ -99,6 +99,7 @@ mod path_dev; mod path_inferred_name; mod path_inferred_name_conflicts_full_feature; mod path_normalized_name; +mod preserve_dep_std_table; mod preserve_features_table; mod preserve_sorted; mod preserve_unsorted; diff --git a/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/in/Cargo.toml new file mode 100644 index 000000000..aa8584ff4 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/in/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "xxx" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies.your-face] +# Leading version +version = "99999.0.0" # Trailing version +# Leading optional +optional = true # Trailing optional +# Leading features +features = [] # Trailing features diff --git a/src/tools/cargo/tests/testsuite/cargo_init/empty_dir/.keep b/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/in/src/lib.rs index e69de29bb..e69de29bb 100644 --- a/src/tools/cargo/tests/testsuite/cargo_init/empty_dir/.keep +++ b/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/in/src/lib.rs diff --git a/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/mod.rs b/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/mod.rs new file mode 100644 index 000000000..1998fa742 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/mod.rs @@ -0,0 +1,31 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::prelude::*; +use cargo_test_support::Project; + +use cargo_test_support::curr_dir; + +#[cargo_test] +fn case() { + cargo_test_support::registry::init(); + cargo_test_support::registry::Package::new("your-face", "99999.0.0+my-package") + .feature("nose", &[]) + .feature("mouth", &[]) + .feature("eyes", &[]) + .feature("ears", &[]) + .publish(); + + let project = Project::from_template(curr_dir!().join("in")); + let project_root = project.root(); + let cwd = &project_root; + + snapbox::cmd::Command::cargo_ui() + .arg("add") + .arg_line("your-face --no-optional") + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); + + assert_ui().subset_matches(curr_dir!().join("out"), &project_root); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/out/Cargo.toml new file mode 100644 index 000000000..76e50ce37 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/out/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "xxx" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies.your-face] +# Leading version +version = "99999.0.0" # Trailing version +# Leading features +features = [] # Trailing features diff --git a/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/stderr.log b/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/stderr.log new file mode 100644 index 000000000..796b9601b --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/stderr.log @@ -0,0 +1,7 @@ + Updating `dummy-registry` index + Adding your-face v99999.0.0 to dependencies. + Features: + - ears + - eyes + - mouth + - nose diff --git a/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/stdout.log b/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/stdout.log new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_add/preserve_dep_std_table/stdout.log diff --git a/src/tools/cargo/tests/testsuite/cargo_bench/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_bench/help/stdout.log index 430d8be42..95546b4a3 100644 --- a/src/tools/cargo/tests/testsuite/cargo_bench/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_bench/help/stdout.log @@ -1,10 +1,10 @@ Execute all benchmarks of a local package -Usage: cargo[EXE] bench [OPTIONS] [BENCHNAME] [-- [args]...] +Usage: cargo[EXE] bench [OPTIONS] [BENCHNAME] [-- [ARGS]...] Arguments: [BENCHNAME] If specified, only run benches containing this string in their names - [args]... Arguments for the bench binary + [ARGS]... Arguments for the bench binary Options: --no-run Compile, but don't run benchmarks @@ -31,9 +31,9 @@ Target Selection: --bin [<NAME>] Benchmark only the specified binary --examples Benchmark all examples --example [<NAME>] Benchmark only the specified example - --tests Benchmark all tests + --tests Benchmark all test targets --test [<NAME>] Benchmark only the specified test target - --benches Benchmark all benches + --benches Benchmark all bench targets --bench [<NAME>] Benchmark only the specified bench target --all-targets Benchmark all targets diff --git a/src/tools/cargo/tests/testsuite/cargo_bench/no_keep_going/stderr.log b/src/tools/cargo/tests/testsuite/cargo_bench/no_keep_going/stderr.log index 7b94abbc4..daaa8f093 100644 --- a/src/tools/cargo/tests/testsuite/cargo_bench/no_keep_going/stderr.log +++ b/src/tools/cargo/tests/testsuite/cargo_bench/no_keep_going/stderr.log @@ -2,6 +2,6 @@ error: unexpected argument '--keep-going' found tip: use `--no-fail-fast` to run as many tests as possible regardless of failure -Usage: cargo[EXE] bench [OPTIONS] [BENCHNAME] [-- [args]...] +Usage: cargo[EXE] bench [OPTIONS] [BENCHNAME] [-- [ARGS]...] For more information, try '--help'. diff --git a/src/tools/cargo/tests/testsuite/cargo_build/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_build/help/stdout.log index 56b934cd1..58b12cdcd 100644 --- a/src/tools/cargo/tests/testsuite/cargo_build/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_build/help/stdout.log @@ -26,9 +26,9 @@ Target Selection: --bin [<NAME>] Build only the specified binary --examples Build all examples --example [<NAME>] Build only the specified example - --tests Build all tests + --tests Build all test targets --test [<NAME>] Build only the specified test target - --benches Build all benches + --benches Build all bench targets --bench [<NAME>] Build only the specified bench target --all-targets Build all targets diff --git a/src/tools/cargo/tests/testsuite/cargo_check/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_check/help/stdout.log index 92d44a6de..bbf090d1d 100644 --- a/src/tools/cargo/tests/testsuite/cargo_check/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_check/help/stdout.log @@ -26,9 +26,9 @@ Target Selection: --bin [<NAME>] Check only the specified binary --examples Check all examples --example [<NAME>] Check only the specified example - --tests Check all tests + --tests Check all test targets --test [<NAME>] Check only the specified test target - --benches Check all benches + --benches Check all bench targets --bench [<NAME>] Check only the specified bench target --all-targets Check all targets diff --git a/src/tools/cargo/tests/testsuite/cargo_command.rs b/src/tools/cargo/tests/testsuite/cargo_command.rs index 62869387f..80885805b 100644 --- a/src/tools/cargo/tests/testsuite/cargo_command.rs +++ b/src/tools/cargo/tests/testsuite/cargo_command.rs @@ -294,7 +294,9 @@ fn find_closest_dont_correct_nonsense() { "\ [ERROR] no such command: `there-is-no-way-that-there-is-a-command-close-to-this` -<tab>View all installed commands with `cargo --list`", +<tab>View all installed commands with `cargo --list` +<tab>Find a package to install `there-is-no-way-that-there-is-a-command-close-to-this` with `cargo search cargo-there-is-no-way-that-there-is-a-command-close-to-this` +", ) .run(); } @@ -307,7 +309,9 @@ fn displays_subcommand_on_error() { "\ [ERROR] no such command: `invalid-command` -<tab>View all installed commands with `cargo --list`", +<tab>View all installed commands with `cargo --list` +<tab>Find a package to install `invalid-command` with `cargo search cargo-invalid-command` +", ) .run(); } @@ -529,7 +533,9 @@ error: no such command: `bluid` <tab>Did you mean `build`? -<tab>View all installed commands with `cargo --list`", +<tab>View all installed commands with `cargo --list` +<tab>Find a package to install `bluid` with `cargo search cargo-bluid` +", ) .run(); } diff --git a/src/tools/cargo/tests/testsuite/cargo_features.rs b/src/tools/cargo/tests/testsuite/cargo_features.rs index cf7ef0190..d319ed686 100644 --- a/src/tools/cargo/tests/testsuite/cargo_features.rs +++ b/src/tools/cargo/tests/testsuite/cargo_features.rs @@ -594,7 +594,13 @@ fn z_flags_rejected() { p.cargo("check -Zarg") .masquerade_as_nightly_cargo(&["test-dummy-unstable"]) .with_status(101) - .with_stderr("error: unknown `-Z` flag specified: arg") + .with_stderr( + r#"error: unknown `-Z` flag specified: arg + +For available unstable features, see https://doc.rust-lang.org/nightly/cargo/reference/unstable.html +If you intended to use an unstable rustc feature, try setting `RUSTFLAGS="-Zarg"` +"#, + ) .run(); p.cargo("check -Zprint-im-a-teapot") diff --git a/src/tools/cargo/tests/testsuite/cargo_fix/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_fix/help/stdout.log index dbbd11b77..3e8b1427f 100644 --- a/src/tools/cargo/tests/testsuite/cargo_fix/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_fix/help/stdout.log @@ -31,9 +31,9 @@ Target Selection: --bin [<NAME>] Fix only the specified binary --examples Fix all examples --example [<NAME>] Fix only the specified example - --tests Fix all tests + --tests Fix all test targets --test [<NAME>] Fix only the specified test target - --benches Fix all benches + --benches Fix all bench targets --bench [<NAME>] Fix only the specified bench target --all-targets Fix all targets (default) diff --git a/src/tools/cargo/tests/testsuite/cargo_init/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_init/help/stdout.log index 0eb4c976b..588b45ccf 100644 --- a/src/tools/cargo/tests/testsuite/cargo_init/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_init/help/stdout.log @@ -1,9 +1,9 @@ Create a new cargo package in an existing directory -Usage: cargo[EXE] init [OPTIONS] [path] +Usage: cargo[EXE] init [OPTIONS] [PATH] Arguments: - [path] [default: .] + [PATH] [default: .] Options: --vcs <VCS> Initialize a new repository for the given version control system, @@ -12,7 +12,7 @@ Options: --bin Use a binary (application) template [default] --lib Use a library template --edition <YEAR> Edition to set for the crate generated [possible values: 2015, 2018, - 2021] + 2021, 2024] --name <NAME> Set the resulting package name, defaults to the directory name --registry <REGISTRY> Registry to use -q, --quiet Do not print cargo log messages diff --git a/src/tools/cargo/tests/testsuite/cargo_init/mod.rs b/src/tools/cargo/tests/testsuite/cargo_init/mod.rs index a1988a06a..0b397111e 100644 --- a/src/tools/cargo/tests/testsuite/cargo_init/mod.rs +++ b/src/tools/cargo/tests/testsuite/cargo_init/mod.rs @@ -42,3 +42,4 @@ mod simple_hg_ignore_exists; mod simple_lib; mod unknown_flags; mod with_argument; +mod workspace_add_member; diff --git a/src/tools/cargo/tests/testsuite/cargo_init/unknown_flags/stderr.log b/src/tools/cargo/tests/testsuite/cargo_init/unknown_flags/stderr.log index 980e8acd8..04a3c3ff0 100644 --- a/src/tools/cargo/tests/testsuite/cargo_init/unknown_flags/stderr.log +++ b/src/tools/cargo/tests/testsuite/cargo_init/unknown_flags/stderr.log @@ -2,6 +2,6 @@ error: unexpected argument '--flag' found tip: to pass '--flag' as a value, use '-- --flag' -Usage: cargo[EXE] init <path> +Usage: cargo[EXE] init <PATH> For more information, try '--help'. diff --git a/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/in/Cargo.toml new file mode 100644 index 000000000..61bdb9cbf --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/in/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +resolver = "2" diff --git a/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/in/crates/foo/.keep b/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/in/crates/foo/.keep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/in/crates/foo/.keep diff --git a/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/mod.rs b/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/mod.rs new file mode 100644 index 000000000..87e2af0e5 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/mod.rs @@ -0,0 +1,21 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::prelude::*; +use cargo_test_support::Project; + +use cargo_test_support::curr_dir; + +#[cargo_test] +fn case() { + let project = Project::from_template(curr_dir!().join("in")); + let project_root = &project.root(); + + snapbox::cmd::Command::cargo_ui() + .arg_line("init --bin --vcs none") + .current_dir(project_root.join("crates").join("foo")) + .assert() + .success() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); + + assert_ui().subset_matches(curr_dir!().join("out"), &project_root); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/out/Cargo.toml new file mode 100644 index 000000000..18a4e7cf2 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/out/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "2" +members = ["crates/foo"] diff --git a/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/out/crates/foo/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/out/crates/foo/Cargo.toml new file mode 100644 index 000000000..1d9cfe317 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/out/crates/foo/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "foo" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/out/crates/foo/src/main.rs b/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/out/crates/foo/src/main.rs new file mode 100644 index 000000000..e7a11a969 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/out/crates/foo/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/stderr.log b/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/stderr.log new file mode 100644 index 000000000..3847e4e4a --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/stderr.log @@ -0,0 +1 @@ + Created binary (application) package diff --git a/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/stdout.log b/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/stdout.log new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_init/workspace_add_member/stdout.log diff --git a/src/tools/cargo/tests/testsuite/cargo_install/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_install/help/stdout.log index 2267c5f6b..5e3458d37 100644 --- a/src/tools/cargo/tests/testsuite/cargo_install/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_install/help/stdout.log @@ -1,9 +1,9 @@ Install a Rust binary. Default location is $HOME/.cargo/bin -Usage: cargo[EXE] install [OPTIONS] [crate]... +Usage: cargo[EXE] install [OPTIONS] [CRATE[@<VER>]]... Arguments: - [crate]... + [CRATE[@<VER>]]... Select the package from the given source Options: --version <VERSION> Specify a version to install diff --git a/src/tools/cargo/tests/testsuite/cargo_login/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_login/help/stdout.log index fd0f3eb3d..e0d5e7e69 100644 --- a/src/tools/cargo/tests/testsuite/cargo_login/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_login/help/stdout.log @@ -1,9 +1,9 @@ Log in to a registry. -Usage: cargo[EXE] login [OPTIONS] [token] [-- [args]...] +Usage: cargo[EXE] login [OPTIONS] [TOKEN] [-- [args]...] Arguments: - [token] + [TOKEN] [args]... Additional arguments for the credential provider Options: diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/in/Cargo.toml new file mode 100644 index 000000000..0614e21f7 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/in/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] +resolver = "2" + +[workspace.package] +authors = ["Rustaceans"] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/mod.rs b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/mod.rs new file mode 100644 index 000000000..9b9642468 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/mod.rs @@ -0,0 +1,22 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +#[cargo_test] +fn case() { + let project = Project::from_template(curr_dir!().join("in")); + let project_root = project.root(); + let cwd = &project_root; + + snapbox::cmd::Command::cargo_ui() + .arg("new") + .args(["crates/foo"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); + + assert_ui().subset_matches(curr_dir!().join("out"), &project_root); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/out/Cargo.toml new file mode 100644 index 000000000..8df793a4f --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/out/Cargo.toml @@ -0,0 +1,6 @@ +[workspace] +resolver = "2" +members = ["crates/foo"] + +[workspace.package] +authors = ["Rustaceans"] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/out/crates/foo/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/out/crates/foo/Cargo.toml new file mode 100644 index 000000000..d97480c7c --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/out/crates/foo/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "foo" +version = "0.1.0" +edition = "2021" +authors.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/out/crates/foo/src/main.rs b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/out/crates/foo/src/main.rs new file mode 100644 index 000000000..e7a11a969 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/out/crates/foo/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/stderr.log b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/stderr.log new file mode 100644 index 000000000..90150cdf5 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/stderr.log @@ -0,0 +1 @@ + Created binary (application) `crates/foo` package diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/stdout.log b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/stdout.log new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/stdout.log diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/in/Cargo.toml new file mode 100644 index 000000000..1f3dfe4de --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/in/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "2" +members = ["crates/bar", "crates/qux"] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/in/crates/bar/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/in/crates/bar/Cargo.toml new file mode 100644 index 000000000..825efac34 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/in/crates/bar/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "bar" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/in/crates/bar/src/main.rs b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/in/crates/bar/src/main.rs new file mode 100644 index 000000000..e7a11a969 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/in/crates/bar/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/in/crates/qux/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/in/crates/qux/Cargo.toml new file mode 100644 index 000000000..30a9d52b2 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/in/crates/qux/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "qux" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/in/crates/qux/src/main.rs b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/in/crates/qux/src/main.rs new file mode 100644 index 000000000..e7a11a969 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/in/crates/qux/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/mod.rs b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/mod.rs new file mode 100644 index 000000000..9b9642468 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/mod.rs @@ -0,0 +1,22 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +#[cargo_test] +fn case() { + let project = Project::from_template(curr_dir!().join("in")); + let project_root = project.root(); + let cwd = &project_root; + + snapbox::cmd::Command::cargo_ui() + .arg("new") + .args(["crates/foo"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); + + assert_ui().subset_matches(curr_dir!().join("out"), &project_root); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/out/Cargo.toml new file mode 100644 index 000000000..cf27071a9 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/out/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "2" +members = ["crates/bar", "crates/foo", "crates/qux"] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/out/crates/foo/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/out/crates/foo/Cargo.toml new file mode 100644 index 000000000..1d9cfe317 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/out/crates/foo/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "foo" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/out/crates/foo/src/main.rs b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/out/crates/foo/src/main.rs new file mode 100644 index 000000000..e7a11a969 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/out/crates/foo/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/stderr.log b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/stderr.log new file mode 100644 index 000000000..90150cdf5 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/stderr.log @@ -0,0 +1 @@ + Created binary (application) `crates/foo` package diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/stdout.log b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/stdout.log new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/stdout.log diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/in/Cargo.toml new file mode 100644 index 000000000..226fd80bc --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/in/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "2" +members = [] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/mod.rs b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/mod.rs new file mode 100644 index 000000000..8bf91be45 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/mod.rs @@ -0,0 +1,23 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +#[cargo_test] +fn case() { + let project = Project::from_template(curr_dir!().join("in")); + let project_root = project.root(); + let cwd = &project_root; + let package_path = cwd.join("crates").join("foo"); + + snapbox::cmd::Command::cargo_ui() + .arg("new") + .args([package_path]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); + + assert_ui().subset_matches(curr_dir!().join("out"), &project_root); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/out/Cargo.toml new file mode 100644 index 000000000..18a4e7cf2 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/out/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "2" +members = ["crates/foo"] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/out/crates/foo/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/out/crates/foo/Cargo.toml new file mode 100644 index 000000000..1d9cfe317 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/out/crates/foo/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "foo" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/out/crates/foo/src/main.rs b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/out/crates/foo/src/main.rs new file mode 100644 index 000000000..e7a11a969 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/out/crates/foo/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/stderr.log b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/stderr.log new file mode 100644 index 000000000..c93b25acb --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/stderr.log @@ -0,0 +1 @@ + Created binary (application) `[ROOT]/case/crates/foo` package diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/stdout.log b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/stdout.log new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/stdout.log diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/in/Cargo.toml new file mode 100644 index 000000000..226fd80bc --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/in/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "2" +members = [] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/mod.rs b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/mod.rs new file mode 100644 index 000000000..9b9642468 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/mod.rs @@ -0,0 +1,22 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +#[cargo_test] +fn case() { + let project = Project::from_template(curr_dir!().join("in")); + let project_root = project.root(); + let cwd = &project_root; + + snapbox::cmd::Command::cargo_ui() + .arg("new") + .args(["crates/foo"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); + + assert_ui().subset_matches(curr_dir!().join("out"), &project_root); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/out/Cargo.toml new file mode 100644 index 000000000..18a4e7cf2 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/out/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "2" +members = ["crates/foo"] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/out/crates/foo/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/out/crates/foo/Cargo.toml new file mode 100644 index 000000000..1d9cfe317 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/out/crates/foo/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "foo" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/out/crates/foo/src/main.rs b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/out/crates/foo/src/main.rs new file mode 100644 index 000000000..e7a11a969 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/out/crates/foo/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/stderr.log b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/stderr.log new file mode 100644 index 000000000..90150cdf5 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/stderr.log @@ -0,0 +1 @@ + Created binary (application) `crates/foo` package diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/stdout.log b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/stdout.log new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/stdout.log diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/in/Cargo.toml new file mode 100644 index 000000000..4790076a8 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/in/Cargo.toml @@ -0,0 +1,4 @@ +[workspace] +resolver = "2" +members = [] +exclude = ["crates/foo"] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/in/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/in/src/lib.rs new file mode 100644 index 000000000..7d12d9af8 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/in/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/mod.rs b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/mod.rs new file mode 100644 index 000000000..9b9642468 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/mod.rs @@ -0,0 +1,22 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +#[cargo_test] +fn case() { + let project = Project::from_template(curr_dir!().join("in")); + let project_root = project.root(); + let cwd = &project_root; + + snapbox::cmd::Command::cargo_ui() + .arg("new") + .args(["crates/foo"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); + + assert_ui().subset_matches(curr_dir!().join("out"), &project_root); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/out/Cargo.toml new file mode 100644 index 000000000..4790076a8 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/out/Cargo.toml @@ -0,0 +1,4 @@ +[workspace] +resolver = "2" +members = [] +exclude = ["crates/foo"] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/out/crates/foo/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/out/crates/foo/Cargo.toml new file mode 100644 index 000000000..1d9cfe317 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/out/crates/foo/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "foo" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/out/crates/foo/src/main.rs b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/out/crates/foo/src/main.rs new file mode 100644 index 000000000..e7a11a969 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/out/crates/foo/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/stderr.log b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/stderr.log new file mode 100644 index 000000000..90150cdf5 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/stderr.log @@ -0,0 +1 @@ + Created binary (application) `crates/foo` package diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/stdout.log b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/stdout.log new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/stdout.log diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/in/Cargo.toml new file mode 100644 index 000000000..a848b85b4 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/in/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "2" +members = ["crates/*"] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/mod.rs b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/mod.rs new file mode 100644 index 000000000..9b9642468 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/mod.rs @@ -0,0 +1,22 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +#[cargo_test] +fn case() { + let project = Project::from_template(curr_dir!().join("in")); + let project_root = project.root(); + let cwd = &project_root; + + snapbox::cmd::Command::cargo_ui() + .arg("new") + .args(["crates/foo"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); + + assert_ui().subset_matches(curr_dir!().join("out"), &project_root); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/out/Cargo.toml new file mode 100644 index 000000000..a848b85b4 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/out/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "2" +members = ["crates/*"] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/out/crates/foo/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/out/crates/foo/Cargo.toml new file mode 100644 index 000000000..1d9cfe317 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/out/crates/foo/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "foo" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/out/crates/foo/src/main.rs b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/out/crates/foo/src/main.rs new file mode 100644 index 000000000..e7a11a969 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/out/crates/foo/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/stderr.log b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/stderr.log new file mode 100644 index 000000000..90150cdf5 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/stderr.log @@ -0,0 +1 @@ + Created binary (application) `crates/foo` package diff --git a/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/stdout.log b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/stdout.log new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/stdout.log diff --git a/src/tools/cargo/tests/testsuite/cargo_new/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_new/help/stdout.log index a937f619b..3df5eceb8 100644 --- a/src/tools/cargo/tests/testsuite/cargo_new/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_new/help/stdout.log @@ -1,9 +1,9 @@ Create a new cargo package at <path> -Usage: cargo[EXE] new [OPTIONS] <path> +Usage: cargo[EXE] new [OPTIONS] <PATH> Arguments: - <path> + <PATH> Options: --vcs <VCS> Initialize a new repository for the given version control system, @@ -12,7 +12,7 @@ Options: --bin Use a binary (application) template [default] --lib Use a library template --edition <YEAR> Edition to set for the crate generated [possible values: 2015, 2018, - 2021] + 2021, 2024] --name <NAME> Set the resulting package name, defaults to the directory name --registry <REGISTRY> Registry to use -q, --quiet Do not print cargo log messages diff --git a/src/tools/cargo/tests/testsuite/cargo_new/mod.rs b/src/tools/cargo/tests/testsuite/cargo_new/mod.rs index 969b09f4f..da0304409 100644 --- a/src/tools/cargo/tests/testsuite/cargo_new/mod.rs +++ b/src/tools/cargo/tests/testsuite/cargo_new/mod.rs @@ -1,3 +1,9 @@ +mod add_members_to_workspace_format_previous_items; +mod add_members_to_workspace_format_sorted; +mod add_members_to_workspace_with_absolute_package_path; +mod add_members_to_workspace_with_empty_members; +mod add_members_to_workspace_with_exclude_list; +mod add_members_to_workspace_with_members_glob; mod help; mod inherit_workspace_lints; mod inherit_workspace_package_table; diff --git a/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_members/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_members/out/Cargo.toml index 2d204581c..8de6ed4bf 100644 --- a/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_members/out/Cargo.toml +++ b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_members/out/Cargo.toml @@ -1,3 +1,5 @@ +[workspace] +members = ["foo"] [workspace.package] authors = ["Rustaceans"] description = "foo" diff --git a/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_members/stderr.log b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_members/stderr.log index 03b1ff6db..9b5015924 100644 --- a/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_members/stderr.log +++ b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_members/stderr.log @@ -1,9 +1 @@ -warning: compiling this new package may not work due to invalid workspace configuration - -current package believes it's in a workspace when it's not: -current: [ROOT]/case/foo/Cargo.toml -workspace: [ROOT]/case/Cargo.toml - -this may be fixable by adding `foo` to the `workspace.members` array of the manifest located at: [ROOT]/case/Cargo.toml -Alternatively, to keep it out of the workspace, add the package to the `workspace.exclude` array, or add an empty `[workspace]` table to the package's manifest. Created binary (application) `foo` package diff --git a/src/tools/cargo/tests/testsuite/cargo_owner/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_owner/help/stdout.log index 580be3c88..110df8e9a 100644 --- a/src/tools/cargo/tests/testsuite/cargo_owner/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_owner/help/stdout.log @@ -1,9 +1,9 @@ Manage the owners of a crate on the registry -Usage: cargo[EXE] owner [OPTIONS] [crate] +Usage: cargo[EXE] owner [OPTIONS] [CRATE] Arguments: - [crate] + [CRATE] Options: -a, --add <LOGIN> Name of a user or team to invite as an owner diff --git a/src/tools/cargo/tests/testsuite/cargo_pkgid/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_pkgid/help/stdout.log index ed48bb7ea..5971e88dc 100644 --- a/src/tools/cargo/tests/testsuite/cargo_pkgid/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_pkgid/help/stdout.log @@ -1,9 +1,9 @@ Print a fully qualified package specification -Usage: cargo[EXE] pkgid [OPTIONS] [spec] +Usage: cargo[EXE] pkgid [OPTIONS] [SPEC] Arguments: - [spec] + [SPEC] Options: -q, --quiet Do not print cargo log messages diff --git a/src/tools/cargo/tests/testsuite/cargo_remove/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_remove/help/stdout.log index 8937fb9f3..47d2c87ad 100644 --- a/src/tools/cargo/tests/testsuite/cargo_remove/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_remove/help/stdout.log @@ -15,9 +15,9 @@ Options: -h, --help Print help Section: - --dev Remove as development dependency - --build Remove as build dependency - --target <TARGET> Remove as dependency from the given target platform + --dev Remove from dev-dependencies + --build Remove from build-dependencies + --target <TARGET> Remove from target-dependencies Package Selection: -p, --package [<SPEC>] Package to remove from diff --git a/src/tools/cargo/tests/testsuite/cargo_remove/invalid_dep/stderr.log b/src/tools/cargo/tests/testsuite/cargo_remove/invalid_dep/stderr.log index eea124d65..9bb137d1f 100644 --- a/src/tools/cargo/tests/testsuite/cargo_remove/invalid_dep/stderr.log +++ b/src/tools/cargo/tests/testsuite/cargo_remove/invalid_dep/stderr.log @@ -1,2 +1,2 @@ Removing invalid_dependency_name from dependencies -error: the dependency `invalid_dependency_name` could not be found in `dependencies`. +error: the dependency `invalid_dependency_name` could not be found in `dependencies` diff --git a/src/tools/cargo/tests/testsuite/cargo_remove/invalid_section/stderr.log b/src/tools/cargo/tests/testsuite/cargo_remove/invalid_section/stderr.log index fff5ff00a..8cbafa98e 100644 --- a/src/tools/cargo/tests/testsuite/cargo_remove/invalid_section/stderr.log +++ b/src/tools/cargo/tests/testsuite/cargo_remove/invalid_section/stderr.log @@ -1,2 +1,2 @@ Removing docopt from build-dependencies -error: the dependency `docopt` could not be found in `build-dependencies`. +error: the dependency `docopt` could not be found in `build-dependencies`; it is present in `dependencies` diff --git a/src/tools/cargo/tests/testsuite/cargo_remove/invalid_section_dep/stderr.log b/src/tools/cargo/tests/testsuite/cargo_remove/invalid_section_dep/stderr.log index 1926f9577..60c0f8b41 100644 --- a/src/tools/cargo/tests/testsuite/cargo_remove/invalid_section_dep/stderr.log +++ b/src/tools/cargo/tests/testsuite/cargo_remove/invalid_section_dep/stderr.log @@ -1,2 +1,2 @@ Removing semver from dev-dependencies -error: the dependency `semver` could not be found in `dev-dependencies`. +error: the dependency `semver` could not be found in `dev-dependencies`; it is present in `dependencies` diff --git a/src/tools/cargo/tests/testsuite/cargo_remove/invalid_target/stderr.log b/src/tools/cargo/tests/testsuite/cargo_remove/invalid_target/stderr.log index 5075b80b7..eae9f7887 100644 --- a/src/tools/cargo/tests/testsuite/cargo_remove/invalid_target/stderr.log +++ b/src/tools/cargo/tests/testsuite/cargo_remove/invalid_target/stderr.log @@ -1,2 +1,2 @@ Removing dbus from dependencies for target `powerpc-unknown-linux-gnu` -error: the dependency `dbus` could not be found in `target.powerpc-unknown-linux-gnu.dependencies`. +error: the dependency `dbus` could not be found in `target.powerpc-unknown-linux-gnu.dependencies`; it is present in `target.x86_64-unknown-linux-gnu.dependencies` diff --git a/src/tools/cargo/tests/testsuite/cargo_remove/invalid_target_dep/stderr.log b/src/tools/cargo/tests/testsuite/cargo_remove/invalid_target_dep/stderr.log index 54bfe085f..635a7bd6c 100644 --- a/src/tools/cargo/tests/testsuite/cargo_remove/invalid_target_dep/stderr.log +++ b/src/tools/cargo/tests/testsuite/cargo_remove/invalid_target_dep/stderr.log @@ -1,2 +1,2 @@ Removing toml from dependencies for target `x86_64-unknown-linux-gnu` -error: the dependency `toml` could not be found in `target.x86_64-unknown-linux-gnu.dependencies`. +error: the dependency `toml` could not be found in `target.x86_64-unknown-linux-gnu.dependencies`; it is present in `dependencies` diff --git a/src/tools/cargo/tests/testsuite/cargo_remove/mod.rs b/src/tools/cargo/tests/testsuite/cargo_remove/mod.rs index 4403e2425..7b9190642 100644 --- a/src/tools/cargo/tests/testsuite/cargo_remove/mod.rs +++ b/src/tools/cargo/tests/testsuite/cargo_remove/mod.rs @@ -20,6 +20,7 @@ mod multiple_dev; mod no_arg; mod offline; mod optional_dep_feature; +mod optional_dep_feature_formatting; mod optional_feature; mod package; mod remove_basic; diff --git a/src/tools/cargo/tests/testsuite/cargo_remove/multiple_dev/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_remove/multiple_dev/out/Cargo.toml index d961b2bb1..b435e33eb 100644 --- a/src/tools/cargo/tests/testsuite/cargo_remove/multiple_dev/out/Cargo.toml +++ b/src/tools/cargo/tests/testsuite/cargo_remove/multiple_dev/out/Cargo.toml @@ -17,4 +17,4 @@ toml = "0.1" clippy = "0.4" [features] -std = ["semver/std"] +std = [ "semver/std"] diff --git a/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature/out/Cargo.toml index 63112d334..f9613bd30 100644 --- a/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature/out/Cargo.toml +++ b/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature/out/Cargo.toml @@ -20,4 +20,4 @@ clippy = "0.4" regex = "0.1.1" [features] -std = ["semver/std"] +std = [ "semver/std"] diff --git a/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/in/Cargo.toml new file mode 100644 index 000000000..01755d687 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/in/Cargo.toml @@ -0,0 +1,42 @@ +[package] +name = "cargo-remove-test-fixture" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[build-dependencies] +semver = "0.1.0" + +[dependencies] +docopt = { version = "0.6", optional = true } +rustc-serialize = { version = "0.4", optional = true } +semver = "0.1" +toml = { version = "0.1", optional = true } +clippy = { version = "0.4", optional = true } + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = [ + # Leading clippy + "dep:clippy", # trailing clippy + + # Leading docopt + "dep:docopt", # trailing docopt + + # Leading rustc-serialize + "dep:rustc-serialize", # trailing rustc-serialize + + # Leading serde/std + "serde/std", # trailing serde/std + + # Leading semver/std + "semver/std", # trailing semver/std + + # Leading toml + "dep:toml", # trailing toml +] diff --git a/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/in/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/in/src/lib.rs new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/in/src/lib.rs @@ -0,0 +1 @@ + diff --git a/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/mod.rs b/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/mod.rs new file mode 100644 index 000000000..69406387b --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/mod.rs @@ -0,0 +1,35 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +#[cargo_test] +fn case() { + cargo_test_support::registry::init(); + cargo_test_support::registry::Package::new("clippy", "0.4.0+my-package").publish(); + cargo_test_support::registry::Package::new("docopt", "0.6.2+my-package").publish(); + cargo_test_support::registry::Package::new("regex", "0.1.1+my-package").publish(); + cargo_test_support::registry::Package::new("rustc-serialize", "0.4.0+my-package").publish(); + cargo_test_support::registry::Package::new("toml", "0.1.1+my-package").publish(); + cargo_test_support::registry::Package::new("semver", "0.1.1") + .feature("std", &[]) + .publish(); + cargo_test_support::registry::Package::new("serde", "1.0.90") + .feature("std", &[]) + .publish(); + + let project = Project::from_template(curr_dir!().join("in")); + let project_root = project.root(); + let cwd = &project_root; + + snapbox::cmd::Command::cargo_ui() + .arg("remove") + .args(["docopt", "toml"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); + + assert_ui().subset_matches(curr_dir!().join("out"), &project_root); +} diff --git a/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/out/Cargo.toml new file mode 100644 index 000000000..0398c8beb --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/out/Cargo.toml @@ -0,0 +1,40 @@ +[package] +name = "cargo-remove-test-fixture" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[build-dependencies] +semver = "0.1.0" + +[dependencies] +rustc-serialize = { version = "0.4", optional = true } +semver = "0.1" +clippy = { version = "0.4", optional = true } + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = [ + # Leading clippy + "dep:clippy", # trailing clippy + + # Leading docopt + # trailing docopt + + # Leading rustc-serialize + "dep:rustc-serialize", # trailing rustc-serialize + + # Leading serde/std + "serde/std", # trailing serde/std + + # Leading semver/std + "semver/std", # trailing semver/std + + # Leading toml + # trailing toml +] diff --git a/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/stderr.log b/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/stderr.log new file mode 100644 index 000000000..7bceb0f94 --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/stderr.log @@ -0,0 +1,2 @@ + Removing docopt from dependencies + Removing toml from dependencies diff --git a/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/stdout.log b/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/stdout.log new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/tools/cargo/tests/testsuite/cargo_remove/optional_dep_feature_formatting/stdout.log diff --git a/src/tools/cargo/tests/testsuite/cargo_run/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_run/help/stdout.log index 4b39f30b3..97c13382a 100644 --- a/src/tools/cargo/tests/testsuite/cargo_run/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_run/help/stdout.log @@ -1,9 +1,9 @@ Run a binary or example of the local package -Usage: cargo[EXE] run [OPTIONS] [args]... +Usage: cargo[EXE] run [OPTIONS] [ARGS]... Arguments: - [args]... Arguments for the binary or example to run + [ARGS]... Arguments for the binary or example to run Options: --ignore-rust-version Ignore `rust-version` specification in packages diff --git a/src/tools/cargo/tests/testsuite/cargo_rustc/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_rustc/help/stdout.log index 9d43841fe..60069f526 100644 --- a/src/tools/cargo/tests/testsuite/cargo_rustc/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_rustc/help/stdout.log @@ -1,9 +1,9 @@ Compile a package, and pass extra options to the compiler -Usage: cargo[EXE] rustc [OPTIONS] [args]... +Usage: cargo[EXE] rustc [OPTIONS] [ARGS]... Arguments: - [args]... Extra rustc flags + [ARGS]... Extra rustc flags Options: --print <INFO> Output compiler information without compiling @@ -28,9 +28,9 @@ Target Selection: --bin [<NAME>] Build only the specified binary --examples Build all examples --example [<NAME>] Build only the specified example - --tests Build all tests + --tests Build all test targets --test [<NAME>] Build only the specified test target - --benches Build all benches + --benches Build all bench targets --bench [<NAME>] Build only the specified bench target --all-targets Build all targets diff --git a/src/tools/cargo/tests/testsuite/cargo_rustdoc/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_rustdoc/help/stdout.log index 706072f24..67ee27e6b 100644 --- a/src/tools/cargo/tests/testsuite/cargo_rustdoc/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_rustdoc/help/stdout.log @@ -1,9 +1,9 @@ Build a package's documentation, using specified custom flags. -Usage: cargo[EXE] rustdoc [OPTIONS] [args]... +Usage: cargo[EXE] rustdoc [OPTIONS] [ARGS]... Arguments: - [args]... Extra rustdoc flags + [ARGS]... Extra rustdoc flags Options: --open Opens the docs in a browser after the operation @@ -26,9 +26,9 @@ Target Selection: --bin [<NAME>] Build only the specified binary --examples Build all examples --example [<NAME>] Build only the specified example - --tests Build all tests + --tests Build all test targets --test [<NAME>] Build only the specified test target - --benches Build all benches + --benches Build all bench targets --bench [<NAME>] Build only the specified bench target --all-targets Build all targets diff --git a/src/tools/cargo/tests/testsuite/cargo_search/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_search/help/stdout.log index 07170ad70..9cc508bba 100644 --- a/src/tools/cargo/tests/testsuite/cargo_search/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_search/help/stdout.log @@ -1,9 +1,9 @@ Search packages in crates.io -Usage: cargo[EXE] search [OPTIONS] [query]... +Usage: cargo[EXE] search [OPTIONS] [QUERY]... Arguments: - [query]... + [QUERY]... Options: --limit <LIMIT> Limit the number of results (default: 10, max: 100) diff --git a/src/tools/cargo/tests/testsuite/cargo_test/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_test/help/stdout.log index 5df62d6bb..d7ec18f46 100644 --- a/src/tools/cargo/tests/testsuite/cargo_test/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_test/help/stdout.log @@ -1,10 +1,10 @@ Execute all unit and integration tests and build examples of a local package -Usage: cargo[EXE] test [OPTIONS] [TESTNAME] [-- [args]...] +Usage: cargo[EXE] test [OPTIONS] [TESTNAME] [-- [ARGS]...] Arguments: [TESTNAME] If specified, only run tests containing this string in their names - [args]... Arguments for the test binary + [ARGS]... Arguments for the test binary Options: --doc Test only this library's documentation @@ -33,9 +33,9 @@ Target Selection: --bin [<NAME>] Test only the specified binary --examples Test all examples --example [<NAME>] Test only the specified example - --tests Test all tests + --tests Test all test targets --test [<NAME>] Test only the specified test target - --benches Test all benches + --benches Test all bench targets --bench [<NAME>] Test only the specified bench target --all-targets Test all targets (does not include doctests) diff --git a/src/tools/cargo/tests/testsuite/cargo_test/no_keep_going/stderr.log b/src/tools/cargo/tests/testsuite/cargo_test/no_keep_going/stderr.log index fd4ca9b2a..22323e651 100644 --- a/src/tools/cargo/tests/testsuite/cargo_test/no_keep_going/stderr.log +++ b/src/tools/cargo/tests/testsuite/cargo_test/no_keep_going/stderr.log @@ -2,6 +2,6 @@ error: unexpected argument '--keep-going' found tip: use `--no-fail-fast` to run as many tests as possible regardless of failure -Usage: cargo[EXE] test [OPTIONS] [TESTNAME] [-- [args]...] +Usage: cargo[EXE] test [OPTIONS] [TESTNAME] [-- [ARGS]...] For more information, try '--help'. diff --git a/src/tools/cargo/tests/testsuite/cargo_uninstall/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_uninstall/help/stdout.log index 2da1a5d57..efdf11c03 100644 --- a/src/tools/cargo/tests/testsuite/cargo_uninstall/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_uninstall/help/stdout.log @@ -1,9 +1,9 @@ Remove a Rust binary -Usage: cargo[EXE] uninstall [OPTIONS] [spec]... +Usage: cargo[EXE] uninstall [OPTIONS] [SPEC]... Arguments: - [spec]... + [SPEC]... Options: --root <DIR> Directory to uninstall packages from diff --git a/src/tools/cargo/tests/testsuite/cargo_yank/help/stdout.log b/src/tools/cargo/tests/testsuite/cargo_yank/help/stdout.log index c6dbfeb9d..61dc800c7 100644 --- a/src/tools/cargo/tests/testsuite/cargo_yank/help/stdout.log +++ b/src/tools/cargo/tests/testsuite/cargo_yank/help/stdout.log @@ -1,9 +1,9 @@ Remove a pushed crate from the index -Usage: cargo[EXE] yank [OPTIONS] [crate] +Usage: cargo[EXE] yank [OPTIONS] [CRATE] Arguments: - [crate] + [CRATE] Options: --version <VERSION> The version to yank or un-yank diff --git a/src/tools/cargo/tests/testsuite/check.rs b/src/tools/cargo/tests/testsuite/check.rs index b74bd6209..03611ae67 100644 --- a/src/tools/cargo/tests/testsuite/check.rs +++ b/src/tools/cargo/tests/testsuite/check.rs @@ -1496,3 +1496,26 @@ fn check_unused_manifest_keys() { ) .run(); } + +#[cargo_test] +fn versionless_package() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + description = "foo" + "#, + ) + .file("src/lib.rs", "") + .build(); + p.cargo("check") + .with_stderr( + "\ +[CHECKING] foo v0.0.0 ([CWD]) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); +} diff --git a/src/tools/cargo/tests/testsuite/check_cfg.rs b/src/tools/cargo/tests/testsuite/check_cfg.rs index c35da637d..57d5f8053 100644 --- a/src/tools/cargo/tests/testsuite/check_cfg.rs +++ b/src/tools/cargo/tests/testsuite/check_cfg.rs @@ -15,16 +15,16 @@ macro_rules! x { $what, '(', $($who,)* ')', "'", "[..]") } }}; - ($tool:tt => $what:tt of $who:tt with $($values:tt)*) => {{ + ($tool:tt => $what:tt of $who:tt with $($first_value:tt $($other_values:tt)*)?) => {{ #[cfg(windows)] { concat!("[RUNNING] [..]", $tool, "[..] --check-cfg \"", - $what, '(', $who, $(", ", "/\"", $values, "/\"",)* ")", '"', "[..]") + $what, '(', $who, ", values(", $("/\"", $first_value, "/\"", $(", ", "/\"", $other_values, "/\"",)*)* "))", '"', "[..]") } #[cfg(not(windows))] { concat!("[RUNNING] [..]", $tool, "[..] --check-cfg '", - $what, '(', $who, $(", ", "\"", $values, "\"",)* ")", "'", "[..]") + $what, '(', $who, ", values(", $("\"", $first_value, "\"", $(", ", "\"", $other_values, "\"",)*)* "))", "'", "[..]") } }}; } @@ -47,9 +47,9 @@ fn features() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("check -v -Zcheck-cfg=features") + p.cargo("check -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b")) + .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b")) .run(); } @@ -76,10 +76,9 @@ fn features_with_deps() { .file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}") .build(); - p.cargo("check -v -Zcheck-cfg=features") + p.cargo("check -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "values" of "feature")) - .with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b")) + .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b")) .run(); } @@ -107,10 +106,9 @@ fn features_with_opt_deps() { .file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}") .build(); - p.cargo("check -v -Zcheck-cfg=features") + p.cargo("check -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "values" of "feature")) - .with_stderr_contains(x!("rustc" => "values" of "feature" with "bar" "default" "f_a" "f_b")) + .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "bar" "default" "f_a" "f_b")) .run(); } @@ -137,111 +135,22 @@ fn features_with_namespaced_features() { .file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}") .build(); - p.cargo("check -v -Zcheck-cfg=features") + p.cargo("check -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b")) + .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b")) .run(); } #[cargo_test(nightly, reason = "--check-cfg is unstable")] -fn well_known_names() { +fn well_known_names_values() { let p = project() .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("src/main.rs", "fn main() {}") .build(); - p.cargo("check -v -Zcheck-cfg=names") + p.cargo("check -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "names")) - .run(); -} - -#[cargo_test(nightly, reason = "--check-cfg is unstable")] -fn well_known_values() { - let p = project() - .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("check -v -Zcheck-cfg=values") - .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "values")) - .run(); -} - -#[cargo_test(nightly, reason = "--check-cfg is unstable")] -fn cli_all_options() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - - [features] - f_a = [] - f_b = [] - "#, - ) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("check -v -Zcheck-cfg=features,names,values") - .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "names")) - .with_stderr_contains(x!("rustc" => "values")) - .with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b")) - .run(); -} - -#[cargo_test(nightly, reason = "--check-cfg is unstable")] -fn features_with_cargo_check() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - - [features] - f_a = [] - f_b = [] - "#, - ) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("check -v -Zcheck-cfg=features") - .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b")) - .run(); -} - -#[cargo_test(nightly, reason = "--check-cfg is unstable")] -fn well_known_names_with_check() { - let p = project() - .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("check -v -Zcheck-cfg=names") - .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "names")) - .run(); -} - -#[cargo_test(nightly, reason = "--check-cfg is unstable")] -fn well_known_values_with_check() { - let p = project() - .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("check -v -Zcheck-cfg=values") - .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "values")) + .with_stderr_contains(x!("rustc" => "cfg" of "feature" with)) .run(); } @@ -263,9 +172,9 @@ fn features_test() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("test -v -Zcheck-cfg=features") + p.cargo("test -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b")) + .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b")) .run(); } @@ -288,64 +197,37 @@ fn features_doctest() { .file("src/lib.rs", "#[allow(dead_code)] fn foo() {}") .build(); - p.cargo("test -v --doc -Zcheck-cfg=features") + p.cargo("test -v --doc -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "values" of "feature" with "default" "f_a" "f_b")) - .with_stderr_contains(x!("rustdoc" => "values" of "feature" with "default" "f_a" "f_b")) + .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "default" "f_a" "f_b")) + .with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b")) .run(); } #[cargo_test(nightly, reason = "--check-cfg is unstable")] -fn well_known_names_test() { +fn well_known_names_values_test() { let p = project() .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("src/main.rs", "fn main() {}") .build(); - p.cargo("test -v -Zcheck-cfg=names") + p.cargo("test -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "names")) + .with_stderr_contains(x!("rustc" => "cfg" of "feature" with)) .run(); } #[cargo_test(nightly, reason = "--check-cfg is unstable")] -fn well_known_values_test() { - let p = project() - .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("test -v -Zcheck-cfg=values") - .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "values")) - .run(); -} - -#[cargo_test(nightly, reason = "--check-cfg is unstable")] -fn well_known_names_doctest() { +fn well_known_names_values_doctest() { let p = project() .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) .file("src/lib.rs", "#[allow(dead_code)] fn foo() {}") .build(); - p.cargo("test -v --doc -Zcheck-cfg=names") + p.cargo("test -v --doc -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "names")) - .with_stderr_contains(x!("rustdoc" => "names")) - .run(); -} - -#[cargo_test(nightly, reason = "--check-cfg is unstable")] -fn well_known_values_doctest() { - let p = project() - .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) - .file("src/lib.rs", "#[allow(dead_code)] fn foo() {}") - .build(); - - p.cargo("test -v --doc -Zcheck-cfg=values") - .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "values")) - .with_stderr_contains(x!("rustdoc" => "values")) + .with_stderr_contains(x!("rustc" => "cfg" of "feature" with)) + .with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with)) .run(); } @@ -368,9 +250,9 @@ fn features_doc() { .file("src/lib.rs", "#[allow(dead_code)] fn foo() {}") .build(); - p.cargo("doc -v -Zcheck-cfg=features") + p.cargo("doc -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustdoc" => "values" of "feature" with "default" "f_a" "f_b")) + .with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b")) .run(); } @@ -390,13 +272,13 @@ fn build_script_feedback() { .file("src/main.rs", "fn main() {}") .file( "build.rs", - r#"fn main() { println!("cargo:rustc-check-cfg=names(foo)"); }"#, + r#"fn main() { println!("cargo:rustc-check-cfg=cfg(foo)"); }"#, ) .build(); - p.cargo("check -v -Zcheck-cfg=output") + p.cargo("check -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "names" of "foo")) + .with_stderr_contains(x!("rustc" => "cfg" of "foo")) .run(); } @@ -416,12 +298,13 @@ fn build_script_doc() { .file("src/main.rs", "fn main() {}") .file( "build.rs", - r#"fn main() { println!("cargo:rustc-check-cfg=names(foo)"); }"#, + r#"fn main() { println!("cargo:rustc-check-cfg=cfg(foo)"); }"#, ) .build(); - p.cargo("doc -v -Zcheck-cfg=output") + + p.cargo("doc -v -Zcheck-cfg") .with_stderr_does_not_contain("rustc [..] --check-cfg [..]") - .with_stderr_contains(x!("rustdoc" => "names" of "foo")) + .with_stderr_contains(x!("rustdoc" => "cfg" of "foo")) .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) @@ -429,7 +312,9 @@ fn build_script_doc() { [RUNNING] `[..]/build-script-build` [DOCUMENTING] foo [..] [RUNNING] `rustdoc [..] src/main.rs [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]", +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html +", ) .masquerade_as_nightly_cargo(&["check-cfg"]) .run(); @@ -458,19 +343,54 @@ fn build_script_override() { &format!( r#" [target.{}.a] - rustc-check-cfg = ["names(foo)"] + rustc-check-cfg = ["cfg(foo)"] "#, target ), ) .build(); - p.cargo("check -v -Zcheck-cfg=output") - .with_stderr_contains(x!("rustc" => "names" of "foo")) + p.cargo("check -v -Zcheck-cfg") + .with_stderr_contains(x!("rustc" => "cfg" of "foo")) .masquerade_as_nightly_cargo(&["check-cfg"]) .run(); } +#[cargo_test] +fn build_script_override_feature_gate() { + let target = cargo_test_support::rustc_host(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + links = "a" + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("build.rs", "fn main() {}") + .file( + ".cargo/config", + &format!( + r#" + [target.{}.a] + rustc-check-cfg = ["cfg(foo)"] + "#, + target + ), + ) + .build(); + + p.cargo("check") + .with_stderr_contains( + "warning: target config[..]rustc-check-cfg[..] requires -Zcheck-cfg flag", + ) + .run(); +} + #[cargo_test(nightly, reason = "--check-cfg is unstable")] fn build_script_test() { let p = project() @@ -487,7 +407,7 @@ fn build_script_test() { .file( "build.rs", r#"fn main() { - println!("cargo:rustc-check-cfg=names(foo)"); + println!("cargo:rustc-check-cfg=cfg(foo)"); println!("cargo:rustc-cfg=foo"); }"#, ) @@ -516,9 +436,9 @@ fn build_script_test() { .file("tests/test.rs", "#[cfg(foo)] #[test] fn test_bar() {}") .build(); - p.cargo("test -v -Zcheck-cfg=output") - .with_stderr_contains(x!("rustc" => "names" of "foo")) - .with_stderr_contains(x!("rustdoc" => "names" of "foo")) + p.cargo("test -v -Zcheck-cfg") + .with_stderr_contains(x!("rustc" => "cfg" of "foo")) + .with_stderr_contains(x!("rustdoc" => "cfg" of "foo")) .with_stdout_contains("test test_foo ... ok") .with_stdout_contains("test test_bar ... ok") .with_stdout_contains_n("test [..] ... ok", 3) @@ -526,6 +446,34 @@ fn build_script_test() { .run(); } +#[cargo_test] +fn build_script_feature_gate() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + build = "build.rs" + "#, + ) + .file( + "build.rs", + r#"fn main() { + println!("cargo:rustc-check-cfg=cfg(foo)"); + println!("cargo:rustc-cfg=foo"); + }"#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("check") + .with_stderr_contains("warning[..]cargo:rustc-check-cfg requires -Zcheck-cfg flag") + .with_status(0) + .run(); +} + #[cargo_test(nightly, reason = "--check-cfg is unstable")] fn config_valid() { let p = project() @@ -546,16 +494,14 @@ fn config_valid() { ".cargo/config.toml", r#" [unstable] - check-cfg = ["features", "names", "values"] + check-cfg = true "#, ) .build(); - p.cargo("check -v -Zcheck-cfg=features,names,values") + p.cargo("check -v") .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains(x!("rustc" => "names")) - .with_stderr_contains(x!("rustc" => "values")) - .with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b")) + .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b")) .run(); } @@ -582,7 +528,36 @@ fn config_invalid() { p.cargo("check") .masquerade_as_nightly_cargo(&["check-cfg"]) - .with_stderr_contains("error: unstable check-cfg only takes `features`, `names`, `values` or `output` as valid inputs") + .with_stderr_contains("error:[..]`unstable.check-cfg` expected true/false[..]") .with_status(101) .run(); } + +#[cargo_test] +fn config_feature_gate() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + + [features] + f_a = [] + "#, + ) + .file("src/main.rs", "fn main() {}") + .file( + ".cargo/config.toml", + r#" + [unstable] + check-cfg = true + "#, + ) + .build(); + + p.cargo("check -v") + .with_stderr_does_not_contain("--check-cfg") + .run(); +} diff --git a/src/tools/cargo/tests/testsuite/collisions.rs b/src/tools/cargo/tests/testsuite/collisions.rs index 77e05dd9c..986619eb2 100644 --- a/src/tools/cargo/tests/testsuite/collisions.rs +++ b/src/tools/cargo/tests/testsuite/collisions.rs @@ -202,6 +202,7 @@ fn collision_doc_multiple_versions() { [DOCUMENTING] bar v2.0.0 [FINISHED] [..] [DOCUMENTING] foo v0.1.0 [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -384,6 +385,7 @@ fn collision_doc_profile_split() { [DOCUMENTING] pm v0.1.0 [..] [DOCUMENTING] foo v0.1.0 [..] [FINISHED] [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -430,6 +432,7 @@ the same path; see <https://github.com/rust-lang/cargo/issues/6313>. [CHECKING] bar v1.0.0 [DOCUMENTING] foo v0.1.0 [..] [FINISHED] [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -478,6 +481,7 @@ fn collision_doc_target() { [CHECKING] bar v1.0.0 [DOCUMENTING] foo v0.1.0 [..] [FINISHED] [..] +[GENERATED] [CWD]/target/[..]/doc/foo/index.html ", ) .run(); @@ -545,6 +549,8 @@ the same path; see <https://github.com/rust-lang/cargo/issues/6313>. [DOCUMENTING] foo-macro v1.0.0 [..] [DOCUMENTING] abc v1.0.0 [..] [FINISHED] [..] +[GENERATED] [CWD]/target/doc/abc/index.html +[GENERATED] [CWD]/target/doc/foo_macro/index.html ") .run(); } diff --git a/src/tools/cargo/tests/testsuite/config.rs b/src/tools/cargo/tests/testsuite/config.rs index 7078fc445..e5078bd8e 100644 --- a/src/tools/cargo/tests/testsuite/config.rs +++ b/src/tools/cargo/tests/testsuite/config.rs @@ -2,8 +2,9 @@ use cargo::core::{PackageIdSpec, Shell}; use cargo::util::config::{self, Config, Definition, JobsConfig, SslVersionConfig, StringList}; -use cargo::util::interning::InternedString; -use cargo::util::toml::{self as cargo_toml, TomlDebugInfo, VecStringOrBool as VSOB}; +use cargo::util::toml::schema::TomlTrimPaths; +use cargo::util::toml::schema::TomlTrimPathsValue; +use cargo::util::toml::schema::{self as cargo_toml, TomlDebugInfo, VecStringOrBool as VSOB}; use cargo::CargoResult; use cargo_test_support::compare; use cargo_test_support::{panic_error, paths, project, symlink_supported, t}; @@ -21,6 +22,7 @@ pub struct ConfigBuilder { unstable: Vec<String>, config_args: Vec<String>, cwd: Option<PathBuf>, + root: Option<PathBuf>, enable_nightly_features: bool, } @@ -30,6 +32,7 @@ impl ConfigBuilder { env: HashMap::new(), unstable: Vec::new(), config_args: Vec::new(), + root: None, cwd: None, enable_nightly_features: false, } @@ -60,8 +63,28 @@ impl ConfigBuilder { } /// Sets the current working directory where config files will be loaded. + /// + /// Default is the root from [`ConfigBuilder::root`] or [`paths::root`]. pub fn cwd(&mut self, path: impl AsRef<Path>) -> &mut Self { - self.cwd = Some(paths::root().join(path.as_ref())); + let path = path.as_ref(); + let cwd = self + .root + .as_ref() + .map_or_else(|| paths::root().join(path), |r| r.join(path)); + self.cwd = Some(cwd); + self + } + + /// Sets the test root directory. + /// + /// This generally should not be necessary. It is only useful if you want + /// to create a `Config` from within a thread. Since Cargo's testsuite + /// uses thread-local storage, this can be used to avoid accessing that + /// thread-local storage. + /// + /// Default is [`paths::root`]. + pub fn root(&mut self, path: impl Into<PathBuf>) -> &mut Self { + self.root = Some(path.into()); self } @@ -72,14 +95,15 @@ impl ConfigBuilder { /// Creates the `Config`, returning a Result. pub fn build_err(&self) -> CargoResult<Config> { - let output = Box::new(fs::File::create(paths::root().join("shell.out")).unwrap()); + let root = self.root.clone().unwrap_or_else(|| paths::root()); + let output = Box::new(fs::File::create(root.join("shell.out")).unwrap()); let shell = Shell::from_write(output); - let cwd = self.cwd.clone().unwrap_or_else(|| paths::root()); - let homedir = paths::home(); + let cwd = self.cwd.clone().unwrap_or_else(|| root.clone()); + let homedir = root.join("home").join(".cargo"); let mut config = Config::new(shell, cwd, homedir); config.nightly_features_allowed = self.enable_nightly_features || !self.unstable.is_empty(); config.set_env(self.env.clone()); - config.set_search_stop_path(paths::root()); + config.set_search_stop_path(&root); config.configure( 0, false, @@ -422,8 +446,8 @@ lto = false p, cargo_toml::TomlProfile { lto: Some(cargo_toml::StringOrBool::Bool(false)), - dir_name: Some(InternedString::new("without-lto")), - inherits: Some(InternedString::new("dev")), + dir_name: Some(String::from("without-lto")), + inherits: Some(String::from("dev")), ..Default::default() } ); @@ -1503,7 +1527,7 @@ fn all_profile_options() { let base_settings = cargo_toml::TomlProfile { opt_level: Some(cargo_toml::TomlOptLevel("0".to_string())), lto: Some(cargo_toml::StringOrBool::String("thin".to_string())), - codegen_backend: Some(InternedString::new("example")), + codegen_backend: Some(String::from("example")), codegen_units: Some(123), debug: Some(cargo_toml::TomlDebugInfo::Limited), split_debuginfo: Some("packed".to_string()), @@ -1512,12 +1536,13 @@ fn all_profile_options() { panic: Some("abort".to_string()), overflow_checks: Some(true), incremental: Some(true), - dir_name: Some(InternedString::new("dir_name")), - inherits: Some(InternedString::new("debug")), + dir_name: Some(String::from("dir_name")), + inherits: Some(String::from("debug")), strip: Some(cargo_toml::StringOrBool::String("symbols".to_string())), package: None, build_override: None, rustflags: None, + trim_paths: None, }; let mut overrides = BTreeMap::new(); let key = cargo_toml::ProfilePackageSpec::Spec(PackageIdSpec::parse("foo").unwrap()); @@ -1705,3 +1730,63 @@ jobs = 2 JobsConfig::Integer(v) => assert_eq!(v, 2), } } + +#[cargo_test] +fn trim_paths_parsing() { + let config = ConfigBuilder::new().build(); + let p: cargo_toml::TomlProfile = config.get("profile.dev").unwrap(); + assert_eq!(p.trim_paths, None); + + let test_cases = [ + (TomlTrimPathsValue::Diagnostics.into(), "diagnostics"), + (TomlTrimPathsValue::Macro.into(), "macro"), + (TomlTrimPathsValue::Object.into(), "object"), + ]; + for (expected, val) in test_cases { + // env + let config = ConfigBuilder::new() + .env("CARGO_PROFILE_DEV_TRIM_PATHS", val) + .build(); + let trim_paths: TomlTrimPaths = config.get("profile.dev.trim-paths").unwrap(); + assert_eq!(trim_paths, expected, "failed to parse {val}"); + + // config.toml + let config = ConfigBuilder::new() + .config_arg(format!("profile.dev.trim-paths='{val}'")) + .build(); + let trim_paths: TomlTrimPaths = config.get("profile.dev.trim-paths").unwrap(); + assert_eq!(trim_paths, expected, "failed to parse {val}"); + } + + let test_cases = [(TomlTrimPaths::none(), false), (TomlTrimPaths::All, true)]; + + for (expected, val) in test_cases { + // env + let config = ConfigBuilder::new() + .env("CARGO_PROFILE_DEV_TRIM_PATHS", format!("{val}")) + .build(); + let trim_paths: TomlTrimPaths = config.get("profile.dev.trim-paths").unwrap(); + assert_eq!(trim_paths, expected, "failed to parse {val}"); + + // config.toml + let config = ConfigBuilder::new() + .config_arg(format!("profile.dev.trim-paths={val}")) + .build(); + let trim_paths: TomlTrimPaths = config.get("profile.dev.trim-paths").unwrap(); + assert_eq!(trim_paths, expected, "failed to parse {val}"); + } + + let expected = vec![ + TomlTrimPathsValue::Diagnostics, + TomlTrimPathsValue::Macro, + TomlTrimPathsValue::Object, + ] + .into(); + let val = r#"["diagnostics", "macro", "object"]"#; + // config.toml + let config = ConfigBuilder::new() + .config_arg(format!("profile.dev.trim-paths={val}")) + .build(); + let trim_paths: TomlTrimPaths = config.get("profile.dev.trim-paths").unwrap(); + assert_eq!(trim_paths, expected, "failed to parse {val}"); +} diff --git a/src/tools/cargo/tests/testsuite/cross_compile.rs b/src/tools/cargo/tests/testsuite/cross_compile.rs index 1bc0c277d..b57ba2c7a 100644 --- a/src/tools/cargo/tests/testsuite/cross_compile.rs +++ b/src/tools/cargo/tests/testsuite/cross_compile.rs @@ -411,92 +411,6 @@ fn linker() { .run(); } -#[cargo_test(nightly, reason = "plugins are unstable")] -fn plugin_with_extra_dylib_dep() { - if cross_compile::disabled() { - return; - } - - let foo = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - - [dependencies.bar] - path = "../bar" - "#, - ) - .file( - "src/main.rs", - r#" - #![feature(plugin)] - #![plugin(bar)] - - fn main() {} - "#, - ) - .build(); - let _bar = project() - .at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - - [lib] - name = "bar" - plugin = true - - [dependencies.baz] - path = "../baz" - "#, - ) - .file( - "src/lib.rs", - r#" - #![feature(rustc_private)] - - extern crate baz; - extern crate rustc_driver; - - use rustc_driver::plugin::Registry; - - #[no_mangle] - pub fn __rustc_plugin_registrar(reg: &mut Registry) { - println!("{}", baz::baz()); - } - "#, - ) - .build(); - let _baz = project() - .at("baz") - .file( - "Cargo.toml", - r#" - [package] - name = "baz" - version = "0.0.1" - authors = [] - - [lib] - name = "baz" - crate_type = ["dylib"] - "#, - ) - .file("src/lib.rs", "pub fn baz() -> i32 { 1 }") - .build(); - - let target = cross_compile::alternate(); - foo.cargo("build --target").arg(&target).run(); -} - #[cargo_test] fn cross_tests() { if !cross_compile::can_run_on_host() { diff --git a/src/tools/cargo/tests/testsuite/custom_target.rs b/src/tools/cargo/tests/testsuite/custom_target.rs index 491d3233c..a04029075 100644 --- a/src/tools/cargo/tests/testsuite/custom_target.rs +++ b/src/tools/cargo/tests/testsuite/custom_target.rs @@ -116,6 +116,8 @@ fn custom_target_dependency() { } #[cargo_test(nightly, reason = "requires features no_core, lang_items")] +// This is randomly crashing in lld. See https://github.com/rust-lang/rust/issues/115985 +#[cfg_attr(all(windows, target_env = "gnu"), ignore = "windows-gnu lld crashing")] fn custom_bin_target() { let p = project() .file( diff --git a/src/tools/cargo/tests/testsuite/death.rs b/src/tools/cargo/tests/testsuite/death.rs index f0e182d01..b61896dc9 100644 --- a/src/tools/cargo/tests/testsuite/death.rs +++ b/src/tools/cargo/tests/testsuite/death.rs @@ -1,12 +1,12 @@ //! Tests for ctrl-C handling. +use cargo_test_support::{project, slow_cpu_multiplier}; use std::fs; use std::io::{self, Read}; use std::net::TcpListener; use std::process::{Child, Stdio}; use std::thread; - -use cargo_test_support::{project, slow_cpu_multiplier}; +use std::time; #[cargo_test] fn ctrl_c_kills_everyone() { @@ -87,6 +87,155 @@ fn ctrl_c_kills_everyone() { ); } +#[cargo_test] +fn kill_cargo_add_never_corrupts_cargo_toml() { + cargo_test_support::registry::init(); + cargo_test_support::registry::Package::new("my-package", "0.1.1+my-package").publish(); + + let with_dependency = r#" +[package] +name = "foo" +version = "0.0.1" +authors = [] + +[dependencies] +my-package = "0.1.1" +"#; + let without_dependency = r#" +[package] +name = "foo" +version = "0.0.1" +authors = [] +"#; + + for sleep_time_ms in [30, 60, 90] { + let p = project() + .file("Cargo.toml", without_dependency) + .file("src/lib.rs", "") + .build(); + + let mut cargo = p.cargo("add").arg("my-package").build_command(); + cargo + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()); + + let mut child = cargo.spawn().unwrap(); + + thread::sleep(time::Duration::from_millis(sleep_time_ms)); + + assert!(child.kill().is_ok()); + assert!(child.wait().is_ok()); + + // check the Cargo.toml + let contents = fs::read(p.root().join("Cargo.toml")).unwrap(); + + // not empty + assert_ne!( + contents, b"", + "Cargo.toml is empty, and should not be at {} milliseconds", + sleep_time_ms + ); + + // We should have the original Cargo.toml or the new one, nothing else. + if std::str::from_utf8(&contents) + .unwrap() + .contains("[dependencies]") + { + assert_eq!( + std::str::from_utf8(&contents).unwrap(), + with_dependency, + "Cargo.toml is with_dependency after add at {} milliseconds", + sleep_time_ms + ); + } else { + assert_eq!( + std::str::from_utf8(&contents).unwrap(), + without_dependency, + "Cargo.toml is without_dependency after add at {} milliseconds", + sleep_time_ms + ); + } + } +} + +#[cargo_test] +fn kill_cargo_remove_never_corrupts_cargo_toml() { + let with_dependency = r#" +[package] +name = "foo" +version = "0.0.1" +authors = [] +build = "build.rs" + +[dependencies] +bar = "0.0.1" +"#; + let without_dependency = r#" +[package] +name = "foo" +version = "0.0.1" +authors = [] +build = "build.rs" +"#; + + // This test depends on killing the cargo process at the right time to cause a failed write. + // Note that we're iterating and using the index as time in ms to sleep before killing the cargo process. + // If it is working correctly, we never fail, but can't hang out here all day... + // So we'll just run it a few times and hope for the best. + for sleep_time_ms in [30, 60, 90] { + // new basic project with a single dependency + let p = project() + .file("Cargo.toml", with_dependency) + .file("src/lib.rs", "") + .build(); + + // run cargo remove the dependency + let mut cargo = p.cargo("remove").arg("bar").build_command(); + cargo + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()); + + let mut child = cargo.spawn().unwrap(); + + thread::sleep(time::Duration::from_millis(sleep_time_ms)); + + assert!(child.kill().is_ok()); + assert!(child.wait().is_ok()); + + // check the Cargo.toml + let contents = fs::read(p.root().join("Cargo.toml")).unwrap(); + + // not empty + assert_ne!( + contents, b"", + "Cargo.toml is empty, and should not be at {} milliseconds", + sleep_time_ms + ); + + // We should have the original Cargo.toml or the new one, nothing else. + if std::str::from_utf8(&contents) + .unwrap() + .contains("[dependencies]") + { + assert_eq!( + std::str::from_utf8(&contents).unwrap(), + with_dependency, + "Cargo.toml is not the same as the original at {} milliseconds", + sleep_time_ms + ); + } else { + assert_eq!( + std::str::from_utf8(&contents).unwrap(), + without_dependency, + "Cargo.toml is not the same as expected at {} milliseconds", + sleep_time_ms + ); + } + } +} + #[cfg(unix)] pub fn ctrl_c(child: &mut Child) { let r = unsafe { libc::kill(-(child.id() as i32), libc::SIGINT) }; diff --git a/src/tools/cargo/tests/testsuite/doc.rs b/src/tools/cargo/tests/testsuite/doc.rs index a16980912..65169d214 100644 --- a/src/tools/cargo/tests/testsuite/doc.rs +++ b/src/tools/cargo/tests/testsuite/doc.rs @@ -31,6 +31,7 @@ fn simple() { [..] foo v0.0.1 ([CWD]) [..] foo v0.0.1 ([CWD]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -69,6 +70,7 @@ fn doc_twice() { "\ [DOCUMENTING] foo v0.0.1 ([CWD]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -103,6 +105,7 @@ fn doc_deps() { [..] bar v0.0.1 ([CWD]/bar) [DOCUMENTING] foo v0.0.1 ([CWD]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -151,6 +154,7 @@ fn doc_no_deps() { [CHECKING] bar v0.0.1 ([CWD]/bar) [DOCUMENTING] foo v0.0.1 ([CWD]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -284,6 +288,8 @@ the same path; see <https://github.com/rust-lang/cargo/issues/6313>. [DOCUMENTING] bar v0.1.0 ([ROOT]/foo/bar) [DOCUMENTING] foo v0.1.0 ([ROOT]/foo/foo) [FINISHED] [..] +[GENERATED] [CWD]/target/doc/foo_lib/index.html +[GENERATED] [CWD]/target/doc/foo_lib/index.html ", ) .run(); @@ -398,6 +404,7 @@ fn doc_lib_bin_same_name_documents_lib() { "\ [DOCUMENTING] foo v0.0.1 ([CWD]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -433,6 +440,7 @@ fn doc_lib_bin_same_name_documents_lib_when_requested() { "\ [DOCUMENTING] foo v0.0.1 ([CWD]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -478,6 +486,7 @@ the same path; see <https://github.com/rust-lang/cargo/issues/6313>. [CHECKING] foo v0.0.1 ([CWD]) [DOCUMENTING] foo v0.0.1 ([CWD]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -523,6 +532,7 @@ the same path; see <https://github.com/rust-lang/cargo/issues/6313>. [CHECKING] foo v0.0.1 ([CWD]) [DOCUMENTING] foo v0.0.1 ([CWD]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -567,7 +577,9 @@ fn doc_lib_bin_example_same_name_documents_named_example_when_requested() { "\ [CHECKING] foo v0.0.1 ([CWD]) [DOCUMENTING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]", +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/ex1/index.html +", ) .run(); @@ -620,7 +632,10 @@ fn doc_lib_bin_example_same_name_documents_examples_when_requested() { "\ [CHECKING] foo v0.0.1 ([CWD]) [DOCUMENTING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]", +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/ex1/index.html +[GENERATED] [CWD]/target/doc/ex2/index.html +", ) .run(); @@ -677,6 +692,7 @@ fn doc_dash_p() { [..] b v0.0.1 ([CWD]/b) [DOCUMENTING] a v0.0.1 ([CWD]/a) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/a/index.html ", ) .run(); @@ -704,6 +720,7 @@ fn doc_all_exclude() { "\ [DOCUMENTING] bar v0.1.0 ([..]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/bar/index.html ", ) .run(); @@ -731,6 +748,7 @@ fn doc_all_exclude_glob() { "\ [DOCUMENTING] bar v0.1.0 ([..]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/bar/index.html ", ) .run(); @@ -918,6 +936,7 @@ fn doc_release() { [DOCUMENTING] foo v0.0.1 ([..]) [RUNNING] `rustdoc [..] src/lib.rs [..]` [FINISHED] release [optimized] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -1006,6 +1025,7 @@ fn features() { [DOCUMENTING] bar v0.0.1 [..] [DOCUMENTING] foo v0.0.1 [..] [FINISHED] [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -1020,6 +1040,7 @@ fn features() { [DOCUMENTING] bar v0.0.1 [..] [DOCUMENTING] foo v0.0.1 [..] [FINISHED] [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -1032,6 +1053,7 @@ fn features() { [DOCUMENTING] bar v0.0.1 [..] [DOCUMENTING] foo v0.0.1 [..] [FINISHED] [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -1202,6 +1224,7 @@ fn doc_virtual_manifest_one_project() { "\ [DOCUMENTING] bar v0.1.0 ([..]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/bar/index.html ", ) .run(); @@ -1229,6 +1252,7 @@ fn doc_virtual_manifest_glob() { "\ [DOCUMENTING] baz v0.1.0 ([..]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/baz/index.html ", ) .run(); @@ -1277,6 +1301,7 @@ the same path; see <https://github.com/rust-lang/cargo/issues/6313>. [CHECKING] bar v0.1.0 [DOCUMENTING] bar v0.1.0 [..] [FINISHED] [..] +[GENERATED] [CWD]/target/doc/bar/index.html ", ) .run(); @@ -1639,6 +1664,7 @@ fn doc_cap_lints() { [CHECKING] a v0.5.0 ([..]) [DOCUMENTING] foo v0.0.1 ([..]) [FINISHED] dev [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -1903,6 +1929,7 @@ fn bin_private_items() { "\ [DOCUMENTING] foo v0.0.1 ([CWD]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -1963,6 +1990,7 @@ fn bin_private_items_deps() { [CHECKING] bar v0.0.1 ([..]) [DOCUMENTING] foo v0.0.1 ([CWD]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -1997,6 +2025,7 @@ fn crate_versions() { [DOCUMENTING] foo v1.2.4 [..] [RUNNING] `rustdoc --crate-type lib --crate-name foo src/lib.rs [..]--crate-version 1.2.4` [FINISHED] [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -2406,7 +2435,8 @@ fn doc_fingerprint_unusual_behavior() { p.cargo("doc") .with_stderr( "[DOCUMENTING] foo [..]\n\ - [FINISHED] [..]", + [FINISHED] [..]\n\ + [GENERATED] [CWD]/target/doc/foo/index.html", ) .run(); // This will delete somefile, but not .hidden. @@ -2425,7 +2455,8 @@ fn doc_fingerprint_unusual_behavior() { .masquerade_as_nightly_cargo(&["skip-rustdoc-fingerprint"]) .with_stderr( "[DOCUMENTING] foo [..]\n\ - [FINISHED] [..]", + [FINISHED] [..]\n\ + [GENERATED] [CWD]/target/doc/foo/index.html", ) .run(); // Should not have deleted anything. @@ -2467,6 +2498,8 @@ fn lib_before_bin() { [RUNNING] `rustdoc --crate-type lib --crate-name foo src/lib.rs [..] [RUNNING] `rustdoc --crate-type bin --crate-name somebin src/bin/somebin.rs [..] [FINISHED] [..] +[GENERATED] [CWD]/target/doc/foo/index.html +[GENERATED] [CWD]/target/doc/somebin/index.html ", ) .run(); @@ -2517,6 +2550,7 @@ fn doc_lib_false() { [CHECKING] foo v0.1.0 [..] [DOCUMENTING] foo v0.1.0 [..] [FINISHED] [..] +[GENERATED] [CWD]/target/doc/some_bin/index.html ", ) .run(); @@ -2563,6 +2597,7 @@ fn doc_lib_false_dep() { [CHECKING] bar v0.1.0 [..] [DOCUMENTING] foo v0.1.0 [..] [FINISHED] [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -2587,7 +2622,8 @@ fn link_to_private_item() { p.cargo("doc") .with_stderr( "[DOCUMENTING] foo [..]\n\ - [FINISHED] [..]", + [FINISHED] [..]\n\ + [GENERATED] [CWD]/target/doc/foo/index.html", ) .run(); } diff --git a/src/tools/cargo/tests/testsuite/docscrape.rs b/src/tools/cargo/tests/testsuite/docscrape.rs index c536a6738..d4d011ff3 100644 --- a/src/tools/cargo/tests/testsuite/docscrape.rs +++ b/src/tools/cargo/tests/testsuite/docscrape.rs @@ -26,13 +26,18 @@ fn basic() { [SCRAPING] foo v0.0.1 ([CWD]) [DOCUMENTING] foo v0.0.1 ([CWD]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); p.cargo("doc -Zunstable-options -Z rustdoc-scrape-examples") .masquerade_as_nightly_cargo(&["rustdoc-scrape-examples"]) - .with_stderr("[FINISHED] [..]") + .with_stderr( + "[FINISHED] [..] +[GENERATED] [CWD]/target/doc/foo/index.html +", + ) .run(); let doc_html = p.read_file("target/doc/foo/fn.foo.html"); @@ -311,6 +316,7 @@ fn cache() { [SCRAPING] foo v0.0.1 ([CWD]) [DOCUMENTING] foo v0.0.1 ([CWD]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -320,6 +326,7 @@ fn cache() { .with_stderr( "\ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -361,7 +368,9 @@ warning: failed to scan example \"ex2\" in package `foo` for example code usage If an example should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` definition in Cargo.toml warning: `foo` (example \"ex2\") generated 1 warning [DOCUMENTING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]", +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html +", ) .run(); } @@ -425,7 +434,9 @@ warning: failed to scan example \"ex1\" in package `foo` for example code usage If an example should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` definition in Cargo.toml warning: `foo` (example \"ex1\") generated 1 warning [DOCUMENTING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]", +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html +", ) .run(); @@ -448,7 +459,9 @@ error: expected one of `!` or `::`, found `NOT` | ^^^ expected one of `!` or `::` [DOCUMENTING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]", +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html +", ) .run(); @@ -499,7 +512,9 @@ warning: Rustdoc did not scrape the following examples because they require dev- If you want Rustdoc to scrape these examples, then add `doc-scrape-examples = true` to the [[example]] target configuration of at least one example. [DOCUMENTING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]", +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html +", ) .run(); @@ -513,7 +528,9 @@ warning: Rustdoc did not scrape the following examples because they require dev- [DOCUMENTING] a v0.0.1 ([CWD]/a) [SCRAPING] foo v0.0.1 ([CWD]) [DOCUMENTING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]", +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/ex/index.html +", ) .run(); } @@ -560,7 +577,9 @@ fn use_dev_deps_if_explicitly_enabled() { [CHECKING] a v0.0.1 ([CWD]/a) [SCRAPING] foo v0.0.1 ([CWD]) [DOCUMENTING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]", +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html +", ) .run(); } diff --git a/src/tools/cargo/tests/testsuite/features.rs b/src/tools/cargo/tests/testsuite/features.rs index 557fab14a..4b7455c37 100644 --- a/src/tools/cargo/tests/testsuite/features.rs +++ b/src/tools/cargo/tests/testsuite/features.rs @@ -36,6 +36,37 @@ Caused by: } #[cargo_test] +fn empty_feature_name() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [features] + "" = [] + "#, + ) + .file("src/main.rs", "") + .build(); + + p.cargo("check") + .with_status(101) + .with_stderr( + "\ +[ERROR] failed to parse manifest at `[..]` + +Caused by: + feature name cannot be empty +", + ) + .run(); +} + +#[cargo_test] fn same_name() { // Feature with the same name as a dependency. let p = project() @@ -1144,6 +1175,61 @@ fn activating_feature_activates_dep() { } #[cargo_test] +fn activating_feature_does_not_activate_transitive_dev_dependency() { + let p = project() + .no_manifest() + .file( + "a/Cargo.toml", + r#" + [package] + name = "a" + version = "0.0.0" + edition = "2021" + + [features] + f = ["b/f"] + + [dependencies] + b = { path = "../b" } + "#, + ) + .file( + "b/Cargo.toml", + r#" + [package] + name = "b" + version = "0.0.0" + edition = "2021" + + [features] + f = ["c/f"] + + [dev-dependencies] + c = { path = "../c" } + "#, + ) + .file( + "c/Cargo.toml", + r#" + [package] + name = "c" + version = "0.0.0" + edition = "2021" + + [features] + f = [] + "#, + ) + .file("a/src/lib.rs", "") + .file("b/src/lib.rs", "") + .file("c/src/lib.rs", "compile_error!") + .build(); + + p.cargo("check --manifest-path a/Cargo.toml --features f") + .run(); +} + +#[cargo_test] fn dep_feature_in_cmd_line() { let p = project() .file( @@ -1990,7 +2076,7 @@ error: failed to parse manifest at `[ROOT]/foo/Cargo.toml` Caused by: invalid character `&` in feature `a&b` in package foo v0.1.0 ([ROOT]/foo), \ - characters must be Unicode XID characters, `+`, or `.` \ + characters must be Unicode XID characters, '-', `+`, or `.` \ (numbers, `+`, `-`, `_`, `.`, or most letters) ", ) diff --git a/src/tools/cargo/tests/testsuite/features2.rs b/src/tools/cargo/tests/testsuite/features2.rs index 9238de2c6..125a293a0 100644 --- a/src/tools/cargo/tests/testsuite/features2.rs +++ b/src/tools/cargo/tests/testsuite/features2.rs @@ -1807,7 +1807,7 @@ fn shared_dep_same_but_dependencies() { [COMPILING] dep [..] [COMPILING] bin2 [..] [COMPILING] bin1 [..] -warning: feat: enabled +warning: bin2@0.1.0: feat: enabled [FINISHED] [..] ", ) @@ -1823,7 +1823,7 @@ warning: feat: enabled [FRESH] subdep [..] [FRESH] dep [..] [FRESH] bin1 [..] -warning: feat: enabled +warning: bin2@0.1.0: feat: enabled [FRESH] bin2 [..] [FINISHED] [..] ", @@ -1955,6 +1955,7 @@ fn doc_optional() { [CHECKING] bar v1.0.0 [DOCUMENTING] foo v0.1.0 [..] [FINISHED] [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); diff --git a/src/tools/cargo/tests/testsuite/glob_targets.rs b/src/tools/cargo/tests/testsuite/glob_targets.rs index 8021dffa9..1eed4b1fa 100644 --- a/src/tools/cargo/tests/testsuite/glob_targets.rs +++ b/src/tools/cargo/tests/testsuite/glob_targets.rs @@ -137,6 +137,7 @@ fn doc_bin() { [DOCUMENTING] foo v0.0.1 ([CWD]) [RUNNING] `rustdoc --crate-type bin --crate-name bin1 [..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/bin1/index.html ", ) .run(); @@ -407,6 +408,7 @@ fn rustdoc_example() { [DOCUMENTING] foo v0.0.1 ([CWD]) [RUNNING] `rustdoc --crate-type bin --crate-name example1 [..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/example1/index.html ", ) .run(); @@ -421,6 +423,7 @@ fn rustdoc_bin() { [DOCUMENTING] foo v0.0.1 ([CWD]) [RUNNING] `rustdoc --crate-type bin --crate-name bin1 [..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/bin1/index.html ", ) .run(); @@ -435,6 +438,7 @@ fn rustdoc_bench() { [DOCUMENTING] foo v0.0.1 ([CWD]) [RUNNING] `rustdoc --crate-type bin --crate-name bench1 [..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/bench1/index.html ", ) .run(); @@ -449,6 +453,7 @@ fn rustdoc_test() { [DOCUMENTING] foo v0.0.1 ([CWD]) [RUNNING] `rustdoc --crate-type bin --crate-name test1 [..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/test1/index.html ", ) .run(); diff --git a/src/tools/cargo/tests/testsuite/install.rs b/src/tools/cargo/tests/testsuite/install.rs index 0a3670e6c..fd53b607b 100644 --- a/src/tools/cargo/tests/testsuite/install.rs +++ b/src/tools/cargo/tests/testsuite/install.rs @@ -58,6 +58,28 @@ fn simple() { } #[cargo_test] +fn install_the_same_version_twice() { + pkg("foo", "0.0.1"); + + cargo_process("install foo foo") + .with_stderr( + "\ +[UPDATING] `[..]` index +[DOWNLOADING] crates ... +[DOWNLOADED] foo v0.0.1 (registry [..]) +[INSTALLING] foo v0.0.1 +[COMPILING] foo v0.0.1 +[FINISHED] release [optimized] target(s) in [..] +[INSTALLING] [CWD]/home/.cargo/bin/foo[EXE] +[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`) +[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries +", + ) + .run(); + assert_has_installed_exe(cargo_home(), "foo"); +} + +#[cargo_test] fn toolchain() { pkg("foo", "0.0.1"); @@ -1614,7 +1636,7 @@ fn inline_version_without_name() { cargo_process("install @0.1.1") .with_status(1) .with_stderr( - "error: invalid value '@0.1.1' for '[crate]...': missing crate name before '@' + "error: invalid value '@0.1.1' for '[CRATE[@<VER>]]...': missing crate name before '@' For more information, try '--help'. ", @@ -1844,7 +1866,9 @@ fn install_empty_argument() { cargo_process("install") .arg("") .with_status(1) - .with_stderr_contains("[ERROR] invalid value '' for '[crate]...': crate name is empty") + .with_stderr_contains( + "[ERROR] invalid value '' for '[CRATE[@<VER>]]...': crate name is empty", + ) .run(); } @@ -2455,7 +2479,7 @@ error: unexpected argument '--release' found tip: `--release` is the default for `cargo install`; instead `--debug` is supported -Usage: cargo[EXE] install [OPTIONS] [crate]... +Usage: cargo[EXE] install [OPTIONS] [CRATE[@<VER>]]... For more information, try '--help'. ", @@ -2463,3 +2487,23 @@ For more information, try '--help'. .with_status(1) .run(); } + +#[cargo_test] +fn install_incompat_msrv() { + Package::new("foo", "0.1.0") + .file("src/main.rs", "fn main() {}") + .rust_version("1.30") + .publish(); + Package::new("foo", "0.2.0") + .file("src/main.rs", "fn main() {}") + .rust_version("1.9876.0") + .publish(); + + cargo_process("install foo") + .with_stderr("\ +[UPDATING] `dummy-registry` index +[ERROR] cannot install package `foo 0.2.0`, it requires rustc 1.9876.0 or newer, while the currently active rustc version is [..] +`foo 0.1.0` supports rustc 1.30 +") + .with_status(101).run(); +} diff --git a/src/tools/cargo/tests/testsuite/install_upgrade.rs b/src/tools/cargo/tests/testsuite/install_upgrade.rs index 580117f5c..fe4f8c6c7 100644 --- a/src/tools/cargo/tests/testsuite/install_upgrade.rs +++ b/src/tools/cargo/tests/testsuite/install_upgrade.rs @@ -230,7 +230,7 @@ fn ambiguous_version_no_longer_allowed() { cargo_process("install foo --version=1.0") .with_stderr( "\ -[ERROR] invalid value '1.0' for '--version <VERSION>': cannot parse '1.0' as a SemVer version +[ERROR] invalid value '1.0' for '--version <VERSION>': unexpected end of input while parsing minor version number tip: if you want to specify SemVer range, add an explicit qualifier, like '^1.0' diff --git a/src/tools/cargo/tests/testsuite/list_availables.rs b/src/tools/cargo/tests/testsuite/list_availables.rs index fe635a19b..ebd6e9c1c 100644 --- a/src/tools/cargo/tests/testsuite/list_availables.rs +++ b/src/tools/cargo/tests/testsuite/list_availables.rs @@ -59,7 +59,7 @@ Available binaries: .with_stderr( "\ error: \"--bench\" takes one argument. -Available benches: +Available bench targets: bench1 bench2 @@ -75,7 +75,7 @@ Available benches: .with_stderr( "\ error: \"--test\" takes one argument. -Available tests: +Available test targets: test1 test2 @@ -139,7 +139,7 @@ No binaries available. .with_stderr( "\ error: \"--bench\" takes one argument. -No benches available. +No bench targets available. ", ) @@ -153,7 +153,7 @@ No benches available. .with_stderr( "\ error: \"--test\" takes one argument. -No tests available. +No test targets available. ", ) diff --git a/src/tools/cargo/tests/testsuite/main.rs b/src/tools/cargo/tests/testsuite/main.rs index 8279f5818..07f749e34 100644 --- a/src/tools/cargo/tests/testsuite/main.rs +++ b/src/tools/cargo/tests/testsuite/main.rs @@ -17,6 +17,7 @@ mod build_plan; mod build_script; mod build_script_env; mod build_script_extra_link_arg; +mod cache_lock; mod cache_messages; mod cargo; mod cargo_add; @@ -131,12 +132,12 @@ mod patch; mod path; mod paths; mod pkgid; -mod plugins; mod proc_macro; mod profile_config; mod profile_custom; mod profile_overrides; mod profile_targets; +mod profile_trim_paths; mod profiles; mod progress; mod pub_priv; diff --git a/src/tools/cargo/tests/testsuite/metadata.rs b/src/tools/cargo/tests/testsuite/metadata.rs index fbead4dea..888cdce8c 100644 --- a/src/tools/cargo/tests/testsuite/metadata.rs +++ b/src/tools/cargo/tests/testsuite/metadata.rs @@ -4257,3 +4257,285 @@ fn workspace_metadata_with_dependencies_no_deps_artifact() { ) .run(); } + +#[cargo_test] +fn versionless_packages() { + let p = project() + .file( + "Cargo.toml", + r#" + [workspace] + members = ["bar", "baz"] + "#, + ) + .file( + "bar/Cargo.toml", + r#" + [package] + name = "bar" + + [dependencies] + foobar = "0.0.1" + baz = { path = "../baz/" } + "#, + ) + .file("bar/src/lib.rs", "") + .file( + "baz/Cargo.toml", + r#" + [package] + name = "baz" + + [dependencies] + foobar = "0.0.1" + "#, + ) + .file("baz/src/lib.rs", "") + .build(); + Package::new("foobar", "0.0.1").publish(); + + p.cargo("metadata -q --format-version 1") + .with_json( + r#" +{ + "packages": [ + { + "name": "bar", + "version": "0.0.0", + "id": "bar 0.0.0 [..]", + "license": null, + "license_file": null, + "description": null, + "source": null, + "dependencies": [ + { + "name": "baz", + "source": null, + "req": "*", + "kind": null, + "rename": null, + "optional": false, + "uses_default_features": true, + "features": [], + "target": null, + "registry": null, + "path": "[..]/baz" + }, + { + "name": "foobar", + "source": "registry+https://github.com/rust-lang/crates.io-index", + "req": "^0.0.1", + "kind": null, + "rename": null, + "optional": false, + "uses_default_features": true, + "features": [], + "target": null, + "registry": null + } + ], + "targets": [ + { + "kind": [ + "lib" + ], + "crate_types": [ + "lib" + ], + "name": "bar", + "src_path": "[..]/bar/src/lib.rs", + "edition": "2015", + "doc": true, + "doctest": true, + "test": true + } + ], + "features": {}, + "manifest_path": "[..]/bar/Cargo.toml", + "metadata": null, + "publish": [], + "authors": [], + "categories": [], + "keywords": [], + "readme": null, + "repository": null, + "homepage": null, + "documentation": null, + "edition": "2015", + "links": null, + "default_run": null, + "rust_version": null + }, + { + "name": "baz", + "version": "0.0.0", + "id": "baz 0.0.0 [..]", + "license": null, + "license_file": null, + "description": null, + "source": null, + "dependencies": [ + { + "name": "foobar", + "source": "registry+https://github.com/rust-lang/crates.io-index", + "req": "^0.0.1", + "kind": null, + "rename": null, + "optional": false, + "uses_default_features": true, + "features": [], + "target": null, + "registry": null + } + ], + "targets": [ + { + "kind": [ + "lib" + ], + "crate_types": [ + "lib" + ], + "name": "baz", + "src_path": "[..]/baz/src/lib.rs", + "edition": "2015", + "doc": true, + "doctest": true, + "test": true + } + ], + "features": {}, + "manifest_path": "[..]/baz/Cargo.toml", + "metadata": null, + "publish": [], + "authors": [], + "categories": [], + "keywords": [], + "readme": null, + "repository": null, + "homepage": null, + "documentation": null, + "edition": "2015", + "links": null, + "default_run": null, + "rust_version": null + }, + { + "name": "foobar", + "version": "0.0.1", + "id": "foobar 0.0.1 [..]", + "license": null, + "license_file": null, + "description": null, + "source": "registry+https://github.com/rust-lang/crates.io-index", + "dependencies": [], + "targets": [ + { + "kind": [ + "lib" + ], + "crate_types": [ + "lib" + ], + "name": "foobar", + "src_path": "[..]/foobar-0.0.1/src/lib.rs", + "edition": "2015", + "doc": true, + "doctest": true, + "test": true + } + ], + "features": {}, + "manifest_path": "[..]/foobar-0.0.1/Cargo.toml", + "metadata": null, + "publish": null, + "authors": [], + "categories": [], + "keywords": [], + "readme": null, + "repository": null, + "homepage": null, + "documentation": null, + "edition": "2015", + "links": null, + "default_run": null, + "rust_version": null + } + ], + "workspace_members": [ + "bar 0.0.0 [..]", + "baz 0.0.0 [..]" + ], + "workspace_default_members": [ + "bar 0.0.0 [..]", + "baz 0.0.0 [..]" + ], + "resolve": { + "nodes": [ + { + "id": "bar 0.0.0 [..]", + "dependencies": [ + "baz 0.0.0 [..]", + "foobar 0.0.1 [..]" + ], + "deps": [ + { + "name": "baz", + "pkg": "baz 0.0.0 [..]", + "dep_kinds": [ + { + "kind": null, + "target": null + } + ] + }, + { + "name": "foobar", + "pkg": "foobar 0.0.1 [..]", + "dep_kinds": [ + { + "kind": null, + "target": null + } + ] + } + ], + "features": [] + }, + { + "id": "baz 0.0.0 [..]", + "dependencies": [ + "foobar 0.0.1 [..]" + ], + "deps": [ + { + "name": "foobar", + "pkg": "foobar 0.0.1 [..]", + "dep_kinds": [ + { + "kind": null, + "target": null + } + ] + } + ], + "features": [] + }, + { + "id": "foobar 0.0.1 [..]", + "dependencies": [], + "deps": [], + "features": [] + } + ], + "root": null + }, + "target_directory": "[..]/foo/target", + "version": 1, + "workspace_root": "[..]", + "metadata": null +} +"#, + ) + .run(); +} diff --git a/src/tools/cargo/tests/testsuite/multitarget.rs b/src/tools/cargo/tests/testsuite/multitarget.rs index 5f3543f01..30be9e97d 100644 --- a/src/tools/cargo/tests/testsuite/multitarget.rs +++ b/src/tools/cargo/tests/testsuite/multitarget.rs @@ -111,6 +111,34 @@ fn simple_doc() { } #[cargo_test] +fn simple_doc_open() { + if cross_compile::disabled() { + return; + } + let t1 = cross_compile::alternate(); + let t2 = rustc_host(); + let p = project() + .file("Cargo.toml", &basic_manifest("foo", "1.0.0")) + .file("src/lib.rs", "//! empty lib") + .build(); + + p.cargo("doc") + .arg("--open") + .arg("--target") + .arg(&t1) + .arg("--target") + .arg(&t2) + .with_stderr( + "\ +[DOCUMENTING] foo v1.0.0 ([..]) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[ERROR] only one `--target` argument is supported", + ) + .with_status(101) + .run(); +} + +#[cargo_test] fn simple_check() { if cross_compile::disabled() { return; diff --git a/src/tools/cargo/tests/testsuite/new.rs b/src/tools/cargo/tests/testsuite/new.rs index 91a2871e9..a34169e9d 100644 --- a/src/tools/cargo/tests/testsuite/new.rs +++ b/src/tools/cargo/tests/testsuite/new.rs @@ -124,7 +124,7 @@ fn no_argument() { .with_stderr_contains( "\ error: the following required arguments were not provided: - <path> + <PATH> ", ) .run(); @@ -451,6 +451,7 @@ fn non_ascii_name() { "\ [WARNING] the name `Привет` contains non-ASCII characters Non-ASCII crate names are not supported by Rust. +[WARNING] the name `Привет` is not snake_case or kebab-case which is recommended for package names, consider `привет` [CREATED] binary (application) `Привет` package ", ) @@ -502,6 +503,29 @@ or change the name in Cargo.toml with: } #[cargo_test] +fn non_snake_case_name() { + cargo_process("new UPPERcase_name") + .with_stderr( + "\ +[WARNING] the name `UPPERcase_name` is not snake_case or kebab-case which is recommended for package names, consider `uppercase_name` +[CREATED] binary (application) `UPPERcase_name` package +", + ) + .run(); +} + +#[cargo_test] +fn kebab_case_name_is_accepted() { + cargo_process("new kebab-case-is-valid") + .with_stderr( + "\ +[CREATED] binary (application) `kebab-case-is-valid` package +", + ) + .run(); +} + +#[cargo_test] fn git_default_branch() { // Check for init.defaultBranch support. create_default_gitconfig(); diff --git a/src/tools/cargo/tests/testsuite/out_dir.rs b/src/tools/cargo/tests/testsuite/out_dir.rs index fe647f56e..83621a2d2 100644 --- a/src/tools/cargo/tests/testsuite/out_dir.rs +++ b/src/tools/cargo/tests/testsuite/out_dir.rs @@ -281,6 +281,29 @@ fn cargo_build_out_dir() { ); } +#[cargo_test] +fn unsupported_short_out_dir_flag() { + let p = project() + .file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#) + .build(); + + p.cargo("build -Z unstable-options -O") + .masquerade_as_nightly_cargo(&["out-dir"]) + .with_stderr( + "\ +error: unexpected argument '-O' found + + tip: a similar argument exists: '--out-dir' + +Usage: cargo[EXE] build [OPTIONS] + +For more information, try '--help'. +", + ) + .with_status(1) + .run(); +} + fn check_dir_contents( out_dir: &Path, expected_linux: &[&str], diff --git a/src/tools/cargo/tests/testsuite/package.rs b/src/tools/cargo/tests/testsuite/package.rs index 010523fda..4ec4fc0d6 100644 --- a/src/tools/cargo/tests/testsuite/package.rs +++ b/src/tools/cargo/tests/testsuite/package.rs @@ -1359,7 +1359,7 @@ Caused by: failed to parse the `edition` key Caused by: - supported edition values are `2015`, `2018`, or `2021`, but `chicken` is unknown + supported edition values are `2015`, `2018`, `2021`, or `2024`, but `chicken` is unknown " .to_string(), ) @@ -1391,7 +1391,7 @@ Caused by: failed to parse the `edition` key Caused by: - this version of Cargo is older than the `2038` edition, and only supports `2015`, `2018`, and `2021` editions. + this version of Cargo is older than the `2038` edition, and only supports `2015`, `2018`, `2021`, and `2024` editions. " .to_string(), ) @@ -3095,3 +3095,40 @@ src/main.rs &[], ); } + +#[cargo_test] +fn versionless_package() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + description = "foo" + "#, + ) + .file("src/main.rs", r#"fn main() { println!("hello"); }"#) + .build(); + + p.cargo("package") + .with_stderr( + "\ +warning: manifest has no license, license-file, documentation, homepage or repository. +See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info. + Packaging foo v0.0.0 ([CWD]) + Verifying foo v0.0.0 ([CWD]) + Compiling foo v0.0.0 ([CWD]/target/package/foo-0.0.0) + Finished dev [unoptimized + debuginfo] target(s) in [..]s + Packaged 4 files, [..]B ([..]B compressed) +", + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.0.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.0.crate", + &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], + &[], + ); +} diff --git a/src/tools/cargo/tests/testsuite/plugins.rs b/src/tools/cargo/tests/testsuite/plugins.rs deleted file mode 100644 index 331ba32e0..000000000 --- a/src/tools/cargo/tests/testsuite/plugins.rs +++ /dev/null @@ -1,421 +0,0 @@ -//! Tests for rustc plugins. - -use cargo_test_support::rustc_host; -use cargo_test_support::{basic_manifest, project}; - -#[cargo_test(nightly, reason = "plugins are unstable")] -fn plugin_to_the_max() { - let foo = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - - [lib] - name = "foo_lib" - - [dependencies.bar] - path = "../bar" - "#, - ) - .file( - "src/main.rs", - r#" - #![feature(plugin)] - #![plugin(bar)] - extern crate foo_lib; - - fn main() { foo_lib::foo(); } - "#, - ) - .file( - "src/foo_lib.rs", - r#" - #![feature(plugin)] - #![plugin(bar)] - - pub fn foo() {} - "#, - ) - .build(); - let _bar = project() - .at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - - [lib] - name = "bar" - plugin = true - - [dependencies.baz] - path = "../baz" - "#, - ) - .file( - "src/lib.rs", - r#" - #![feature(rustc_private)] - - extern crate baz; - extern crate rustc_driver; - - use rustc_driver::plugin::Registry; - - #[no_mangle] - pub fn __rustc_plugin_registrar(_reg: &mut Registry) { - println!("{}", baz::baz()); - } - "#, - ) - .build(); - let _baz = project() - .at("baz") - .file( - "Cargo.toml", - r#" - [package] - name = "baz" - version = "0.0.1" - authors = [] - - [lib] - name = "baz" - crate_type = ["dylib"] - "#, - ) - .file("src/lib.rs", "pub fn baz() -> i32 { 1 }") - .build(); - - foo.cargo("build").run(); - foo.cargo("doc").run(); -} - -#[cargo_test(nightly, reason = "plugins are unstable")] -fn plugin_with_dynamic_native_dependency() { - let build = project() - .at("builder") - .file( - "Cargo.toml", - r#" - [package] - name = "builder" - version = "0.0.1" - authors = [] - - [lib] - name = "builder" - crate-type = ["dylib"] - "#, - ) - .file("src/lib.rs", "#[no_mangle] pub extern fn foo() {}") - .build(); - - let foo = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - - [dependencies.bar] - path = "bar" - "#, - ) - .file( - "src/main.rs", - r#" - #![feature(plugin)] - #![plugin(bar)] - - fn main() {} - "#, - ) - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - build = 'build.rs' - - [lib] - name = "bar" - plugin = true - "#, - ) - .file( - "bar/build.rs", - r#" - use std::env; - use std::fs; - use std::path::PathBuf; - - fn main() { - let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); - let root = PathBuf::from(env::var("BUILDER_ROOT").unwrap()); - let file = format!("{}builder{}", - env::consts::DLL_PREFIX, - env::consts::DLL_SUFFIX); - let src = root.join(&file); - let dst = out_dir.join(&file); - fs::copy(src, dst).unwrap(); - if cfg!(target_env = "msvc") { - fs::copy(root.join("builder.dll.lib"), - out_dir.join("builder.dll.lib")).unwrap(); - } - println!("cargo:rustc-flags=-L {}", out_dir.display()); - } - "#, - ) - .file( - "bar/src/lib.rs", - r#" - #![feature(rustc_private)] - - extern crate rustc_driver; - use rustc_driver::plugin::Registry; - - #[cfg_attr(not(target_env = "msvc"), link(name = "builder"))] - #[cfg_attr(target_env = "msvc", link(name = "builder.dll"))] - extern { fn foo(); } - - #[no_mangle] - pub fn __rustc_plugin_registrar(_reg: &mut Registry) { - unsafe { foo() } - } - "#, - ) - .build(); - - build.cargo("build").run(); - - let root = build.root().join("target").join("debug"); - foo.cargo("build -v").env("BUILDER_ROOT", root).run(); -} - -#[cargo_test] -fn plugin_integration() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - build = "build.rs" - - [lib] - name = "foo" - plugin = true - doctest = false - "#, - ) - .file("build.rs", "fn main() {}") - .file("src/lib.rs", "") - .file("tests/it_works.rs", "") - .build(); - - p.cargo("test -v").run(); -} - -#[cargo_test] -fn doctest_a_plugin() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - - [dependencies] - bar = { path = "bar" } - "#, - ) - .file("src/lib.rs", "#[macro_use] extern crate bar;") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - - [lib] - name = "bar" - plugin = true - "#, - ) - .file("bar/src/lib.rs", "pub fn bar() {}") - .build(); - - p.cargo("test -v").run(); -} - -// See #1515 -#[cargo_test] -fn native_plugin_dependency_with_custom_linker() { - let target = rustc_host(); - - let _foo = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - - [lib] - plugin = true - "#, - ) - .file("src/lib.rs", "") - .build(); - - let bar = project() - .at("bar") - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - - [dependencies.foo] - path = "../foo" - "#, - ) - .file("src/lib.rs", "") - .file( - ".cargo/config", - &format!( - r#" - [target.{}] - linker = "nonexistent-linker" - "#, - target - ), - ) - .build(); - - bar.cargo("build --verbose") - .with_status(101) - .with_stderr_contains( - "\ -[COMPILING] foo v0.0.1 ([..]) -[RUNNING] `rustc [..] -C linker=nonexistent-linker [..]` -[ERROR] [..]linker[..] -", - ) - .run(); -} - -#[cargo_test(nightly, reason = "requires rustc_private")] -fn panic_abort_plugins() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - - [profile.dev] - panic = 'abort' - - [dependencies] - bar = { path = "bar" } - "#, - ) - .file("src/lib.rs", "") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - - [lib] - plugin = true - "#, - ) - .file( - "bar/src/lib.rs", - r#" - #![feature(rustc_private)] - extern crate rustc_ast; - extern crate rustc_driver; - "#, - ) - .build(); - - p.cargo("build").run(); -} - -#[cargo_test(nightly, reason = "requires rustc_private")] -fn shared_panic_abort_plugins() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - - [profile.dev] - panic = 'abort' - - [dependencies] - bar = { path = "bar" } - baz = { path = "baz" } - "#, - ) - .file("src/lib.rs", "extern crate baz;") - .file( - "bar/Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - - [lib] - plugin = true - - [dependencies] - baz = { path = "../baz" } - "#, - ) - .file( - "bar/src/lib.rs", - r#" - #![feature(rustc_private)] - extern crate rustc_ast; - extern crate rustc_driver; - extern crate baz; - "#, - ) - .file("baz/Cargo.toml", &basic_manifest("baz", "0.0.1")) - .file("baz/src/lib.rs", "") - .build(); - - p.cargo("build -v").run(); -} diff --git a/src/tools/cargo/tests/testsuite/proc_macro.rs b/src/tools/cargo/tests/testsuite/proc_macro.rs index 7d6f6ba86..cabf251a0 100644 --- a/src/tools/cargo/tests/testsuite/proc_macro.rs +++ b/src/tools/cargo/tests/testsuite/proc_macro.rs @@ -202,52 +202,6 @@ fn impl_and_derive() { p.cargo("run").with_stdout("X { success: true }").run(); } -#[cargo_test(nightly, reason = "plugins are unstable")] -fn plugin_and_proc_macro() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - - [lib] - plugin = true - proc-macro = true - "#, - ) - .file( - "src/lib.rs", - r#" - #![feature(rustc_private)] - #![feature(proc_macro, proc_macro_lib)] - - extern crate rustc_driver; - use rustc_driver::plugin::Registry; - - extern crate proc_macro; - use proc_macro::TokenStream; - - #[no_mangle] - pub fn __rustc_plugin_registrar(reg: &mut Registry) {} - - #[proc_macro_derive(Questionable)] - pub fn questionable(input: TokenStream) -> TokenStream { - input - } - "#, - ) - .build(); - - let msg = " `lib.plugin` and `lib.proc-macro` cannot both be `true`"; - p.cargo("check") - .with_status(101) - .with_stderr_contains(msg) - .run(); -} - #[cargo_test] fn proc_macro_doctest() { let foo = project() diff --git a/src/tools/cargo/tests/testsuite/profile_config.rs b/src/tools/cargo/tests/testsuite/profile_config.rs index 143c050f9..710a0d8ef 100644 --- a/src/tools/cargo/tests/testsuite/profile_config.rs +++ b/src/tools/cargo/tests/testsuite/profile_config.rs @@ -1,6 +1,6 @@ //! Tests for profiles defined in config files. -use cargo::util::toml::TomlDebugInfo; +use cargo::util::toml::schema::TomlDebugInfo; use cargo_test_support::paths::CargoPathExt; use cargo_test_support::registry::Package; use cargo_test_support::{basic_lib_manifest, paths, project}; diff --git a/src/tools/cargo/tests/testsuite/profile_targets.rs b/src/tools/cargo/tests/testsuite/profile_targets.rs index f2de169b9..9f00b73f3 100644 --- a/src/tools/cargo/tests/testsuite/profile_targets.rs +++ b/src/tools/cargo/tests/testsuite/profile_targets.rs @@ -667,5 +667,6 @@ fn profile_selection_doc() { [DOCUMENTING] foo [..] [RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..] [FINISHED] dev [unoptimized + debuginfo] [..] +[GENERATED] [CWD]/target/doc/foo/index.html ").run(); } diff --git a/src/tools/cargo/tests/testsuite/profile_trim_paths.rs b/src/tools/cargo/tests/testsuite/profile_trim_paths.rs new file mode 100644 index 000000000..1d24c159b --- /dev/null +++ b/src/tools/cargo/tests/testsuite/profile_trim_paths.rs @@ -0,0 +1,614 @@ +//! Tests for `-Ztrim-paths`. + +use cargo_test_support::basic_manifest; +use cargo_test_support::git; +use cargo_test_support::paths; +use cargo_test_support::project; +use cargo_test_support::registry::Package; + +#[cargo_test] +fn gated_manifest() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + + [profile.dev] + trim-paths = "macro" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .with_status(101) + .with_stderr_contains( + "\ +[ERROR] failed to parse manifest at `[CWD]/Cargo.toml` + +Caused by: + feature `trim-paths` is required", + ) + .run(); +} + +#[cargo_test] +fn gated_config_toml() { + let p = project() + .file( + ".cargo/config.toml", + r#" + [profile.dev] + trim-paths = "macro" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .with_status(101) + .with_stderr_contains( + "\ +[ERROR] config profile `dev` is not valid (defined in `[CWD]/.cargo/config.toml`) + +Caused by: + feature `trim-paths` is required", + ) + .run(); +} + +#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")] +fn release_profile_default_to_object() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build --release --verbose -Ztrim-paths") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .with_stderr( + "\ +[COMPILING] foo v0.0.1 ([CWD]) +[RUNNING] `rustc [..]\ + -Zremap-path-scope=object \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix=[CWD]= [..] +[FINISHED] release [..]", + ) + .run(); +} + +#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")] +fn one_option() { + let build = |option| { + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.0.1" + + [profile.dev] + trim-paths = "{option}" + "# + ), + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build -v -Ztrim-paths") + }; + + for option in ["macro", "diagnostics", "object", "all"] { + build(option) + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .with_stderr(&format!( + "\ +[COMPILING] foo v0.0.1 ([CWD]) +[RUNNING] `rustc [..]\ + -Zremap-path-scope={option} \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix=[CWD]= [..] +[FINISHED] dev [..]", + )) + .run(); + } + build("none") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .with_stderr_does_not_contain("[..]-Zremap-path-scope=[..]") + .with_stderr_does_not_contain("[..]--remap-path-prefix=[..]") + .run(); +} + +#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")] +fn multiple_options() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + + [profile.dev] + trim-paths = ["diagnostics", "macro", "object"] + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build --verbose -Ztrim-paths") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .with_stderr( + "\ +[COMPILING] foo v0.0.1 ([CWD]) +[RUNNING] `rustc [..]\ + -Zremap-path-scope=diagnostics,macro,object \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix=[CWD]= [..] +[FINISHED] dev [..]", + ) + .run(); +} + +#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")] +fn profile_merge_works() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + + [profile.dev] + trim-paths = ["macro"] + + [profile.custom] + inherits = "dev" + trim-paths = ["diagnostics"] + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build -v -Ztrim-paths --profile custom") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .with_stderr( + "\ +[COMPILING] foo v0.0.1 ([CWD]) +[RUNNING] `rustc [..]\ + -Zremap-path-scope=diagnostics \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix=[CWD]= [..] +[FINISHED] custom [..]", + ) + .run(); +} + +#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")] +fn registry_dependency() { + Package::new("bar", "0.0.1") + .file("Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("src/lib.rs", r#"pub fn f() { println!("{}", file!()); }"#) + .publish(); + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + + [dependencies] + bar = "0.0.1" + + [profile.dev] + trim-paths = "object" + "#, + ) + .file("src/main.rs", "fn main() { bar::f(); }") + .build(); + + let registry_src = paths::home().join(".cargo/registry/src"); + let pkg_remap = format!("{}/[..]/bar-0.0.1=bar-0.0.1", registry_src.display()); + + p.cargo("run --verbose -Ztrim-paths") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .with_stdout("bar-0.0.1/src/lib.rs") + .with_stderr(&format!( + "\ +[UPDATING] [..] +[DOWNLOADING] crates ... +[DOWNLOADED] bar v0.0.1 ([..]) +[COMPILING] bar v0.0.1 +[RUNNING] `rustc [..]\ + -Zremap-path-scope=object \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix={pkg_remap} [..] +[COMPILING] foo v0.0.1 ([CWD]) +[RUNNING] `rustc [..]\ + -Zremap-path-scope=object \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix=[CWD]= [..] +[FINISHED] dev [..] +[RUNNING] `target/debug/foo[EXE]`" + )) + .run(); +} + +#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")] +fn git_dependency() { + let git_project = git::new("bar", |project| { + project + .file("Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("src/lib.rs", r#"pub fn f() { println!("{}", file!()); }"#) + }); + let url = git_project.url(); + + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.0.1" + + [dependencies] + bar = {{ git = "{url}" }} + + [profile.dev] + trim-paths = "object" + "# + ), + ) + .file("src/main.rs", "fn main() { bar::f(); }") + .build(); + + let git_checkouts_src = paths::home().join(".cargo/git/checkouts"); + let pkg_remap = format!("{}/bar-[..]/[..]=bar-0.0.1", git_checkouts_src.display()); + + p.cargo("run --verbose -Ztrim-paths") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .with_stdout("bar-0.0.1/src/lib.rs") + .with_stderr(&format!( + "\ +[UPDATING] git repository `{url}` +[COMPILING] bar v0.0.1 ({url}[..]) +[RUNNING] `rustc [..]\ + -Zremap-path-scope=object \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix={pkg_remap} [..] +[COMPILING] foo v0.0.1 ([CWD]) +[RUNNING] `rustc [..]\ + -Zremap-path-scope=object \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix=[CWD]= [..] +[FINISHED] dev [..] +[RUNNING] `target/debug/foo[EXE]`" + )) + .run(); +} + +#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")] +fn path_dependency() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + + [dependencies] + bar = { path = "cocktail-bar" } + + [profile.dev] + trim-paths = "object" + "#, + ) + .file("src/main.rs", "fn main() { bar::f(); }") + .file("cocktail-bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file( + "cocktail-bar/src/lib.rs", + r#"pub fn f() { println!("{}", file!()); }"#, + ) + .build(); + + p.cargo("run --verbose -Ztrim-paths") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .with_stdout("cocktail-bar/src/lib.rs") + .with_stderr(&format!( + "\ +[COMPILING] bar v0.0.1 ([..]/cocktail-bar) +[RUNNING] `rustc [..]\ + -Zremap-path-scope=object \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix=[CWD]= [..] +[COMPILING] foo v0.0.1 ([CWD]) +[RUNNING] `rustc [..]\ + -Zremap-path-scope=object \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix=[CWD]= [..] +[FINISHED] dev [..] +[RUNNING] `target/debug/foo[EXE]`" + )) + .run(); +} + +#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")] +fn path_dependency_outside_workspace() { + let bar = project() + .at("bar") + .file("Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("src/lib.rs", r#"pub fn f() { println!("{}", file!()); }"#) + .build(); + let bar_path = bar.url().to_file_path().unwrap(); + let bar_path = bar_path.display(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + + [dependencies] + bar = { path = "../bar" } + + [profile.dev] + trim-paths = "object" + "#, + ) + .file("src/main.rs", "fn main() { bar::f(); }") + .build(); + + p.cargo("run --verbose -Ztrim-paths") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .with_stdout("bar-0.0.1/src/lib.rs") + .with_stderr(&format!( + "\ +[COMPILING] bar v0.0.1 ([..]/bar) +[RUNNING] `rustc [..]\ + -Zremap-path-scope=object \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix={bar_path}=bar-0.0.1 [..] +[COMPILING] foo v0.0.1 ([CWD]) +[RUNNING] `rustc [..]\ + -Zremap-path-scope=object \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix=[CWD]= [..] +[FINISHED] dev [..] +[RUNNING] `target/debug/foo[EXE]`" + )) + .run(); +} + +#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")] +fn diagnostics_works() { + Package::new("bar", "0.0.1") + .file("Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("src/lib.rs", r#"pub fn f() { let unused = 0; }"#) + .publish(); + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + + [dependencies] + bar = "0.0.1" + + [profile.dev] + trim-paths = "diagnostics" + "#, + ) + .file("src/lib.rs", "") + .build(); + + let registry_src = paths::home().join(".cargo/registry/src"); + let registry_src = registry_src.display(); + let pkg_remap = format!("{registry_src}/[..]/bar-0.0.1=bar-0.0.1"); + + p.cargo("build -vv -Ztrim-paths") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .with_stderr_line_without( + &["[..]bar-0.0.1/src/lib.rs:1[..]"], + &[&format!("{registry_src}")], + ) + .with_stderr_contains("[..]unused_variables[..]") + .with_stderr_contains(&format!( + "\ +[RUNNING] [..]rustc [..]\ + -Zremap-path-scope=diagnostics \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix={pkg_remap} [..]", + )) + .with_stderr_contains( + "\ +[RUNNING] [..]rustc [..]\ + -Zremap-path-scope=diagnostics \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix=[CWD]= [..]", + ) + .run(); +} + +#[cfg(target_os = "linux")] +#[cargo_test(requires_readelf, nightly, reason = "-Zremap-path-scope is unstable")] +fn object_works() { + use std::os::unix::ffi::OsStrExt; + + let run_readelf = |path| { + std::process::Command::new("readelf") + .arg("-wi") + .arg(path) + .output() + .expect("readelf works") + }; + + let registry_src = paths::home().join(".cargo/registry/src"); + let pkg_remap = format!("{}/[..]/bar-0.0.1=bar-0.0.1", registry_src.display()); + let rust_src = "/lib/rustc/src/rust".as_bytes(); + let registry_src_bytes = registry_src.as_os_str().as_bytes(); + + Package::new("bar", "0.0.1") + .file("Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("src/lib.rs", r#"pub fn f() { println!("{}", file!()); }"#) + .publish(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + + [dependencies] + bar = "0.0.1" + "#, + ) + .file("src/main.rs", "fn main() { bar::f(); }") + .build(); + + let pkg_root = p.root(); + let pkg_root = pkg_root.as_os_str().as_bytes(); + + p.cargo("build").run(); + + let bin_path = p.bin("foo"); + assert!(bin_path.is_file()); + let stdout = run_readelf(bin_path).stdout; + // TODO: re-enable this check when rustc bootstrap disables remapping + // <https://github.com/rust-lang/cargo/pull/12625#discussion_r1371714791> + // assert!(memchr::memmem::find(&stdout, rust_src).is_some()); + assert!(memchr::memmem::find(&stdout, registry_src_bytes).is_some()); + assert!(memchr::memmem::find(&stdout, pkg_root).is_some()); + + p.cargo("clean").run(); + + p.change_file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + + [dependencies] + bar = "0.0.1" + + [profile.dev] + trim-paths = "object" + "#, + ); + + p.cargo("build --verbose -Ztrim-paths") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .with_stderr(&format!( + "\ +[COMPILING] bar v0.0.1 +[RUNNING] `rustc [..]\ + -Zremap-path-scope=object \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix={pkg_remap} [..] +[COMPILING] foo v0.0.1 ([CWD]) +[RUNNING] `rustc [..]\ + -Zremap-path-scope=object \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix=[CWD]= [..] +[FINISHED] dev [..]", + )) + .run(); + + let bin_path = p.bin("foo"); + assert!(bin_path.is_file()); + let stdout = run_readelf(bin_path).stdout; + assert!(memchr::memmem::find(&stdout, rust_src).is_none()); + assert!(memchr::memmem::find(&stdout, registry_src_bytes).is_none()); + assert!(memchr::memmem::find(&stdout, pkg_root).is_none()); +} + +// TODO: might want to move to test/testsuite/build_script.rs once stabilized. +#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")] +fn custom_build_env_var_trim_paths() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + "#, + ) + .file("src/lib.rs", "") + .file("build.rs", "") + .build(); + + let test_cases = [ + ("[]", "none"), + ("\"all\"", "all"), + ("\"diagnostics\"", "diagnostics"), + ("\"macro\"", "macro"), + ("\"none\"", "none"), + ("\"object\"", "object"), + ("false", "none"), + ("true", "all"), + ( + r#"["diagnostics", "macro", "object"]"#, + "diagnostics,macro,object", + ), + ]; + + for (opts, expected) in test_cases { + p.change_file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.0.1" + + [profile.dev] + trim-paths = {opts} + "# + ), + ); + + p.change_file( + "build.rs", + &format!( + r#" + fn main() {{ + assert_eq!( + std::env::var("CARGO_TRIM_PATHS").unwrap().as_str(), + "{expected}", + ); + }} + "# + ), + ); + + p.cargo("build -Ztrim-paths") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .run(); + } +} diff --git a/src/tools/cargo/tests/testsuite/pub_priv.rs b/src/tools/cargo/tests/testsuite/pub_priv.rs index 83c6a49f8..b2160e0fa 100644 --- a/src/tools/cargo/tests/testsuite/pub_priv.rs +++ b/src/tools/cargo/tests/testsuite/pub_priv.rs @@ -197,3 +197,52 @@ Caused by: ) .run() } + +#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")] +fn workspace_dep_made_public() { + Package::new("foo1", "0.1.0") + .file("src/lib.rs", "pub struct FromFoo;") + .publish(); + Package::new("foo2", "0.1.0") + .file("src/lib.rs", "pub struct FromFoo;") + .publish(); + Package::new("foo3", "0.1.0") + .file("src/lib.rs", "pub struct FromFoo;") + .publish(); + + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["public-dependency"] + + [package] + name = "foo" + version = "0.0.1" + + [workspace.dependencies] + foo1 = "0.1.0" + foo2 = { version = "0.1.0", public = true } + foo3 = { version = "0.1.0", public = false } + + [dependencies] + foo1 = { workspace = true, public = true } + foo2 = { workspace = true } + foo3 = { workspace = true, public = true } + "#, + ) + .file( + "src/lib.rs", + " + #![deny(exported_private_dependencies)] + pub fn use_priv1(_: foo1::FromFoo) {} + pub fn use_priv2(_: foo2::FromFoo) {} + pub fn use_priv3(_: foo3::FromFoo) {} + ", + ) + .build(); + + p.cargo("check") + .masquerade_as_nightly_cargo(&["public-dependency"]) + .run() +} diff --git a/src/tools/cargo/tests/testsuite/publish.rs b/src/tools/cargo/tests/testsuite/publish.rs index 67569bf3b..5d29ac88a 100644 --- a/src/tools/cargo/tests/testsuite/publish.rs +++ b/src/tools/cargo/tests/testsuite/publish.rs @@ -420,7 +420,7 @@ fn unpublishable_crate() { .with_stderr( "\ [ERROR] `foo` cannot be published. -`package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing. +`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish. ", ) .run(); @@ -794,7 +794,7 @@ fn publish_empty_list() { .with_stderr( "\ [ERROR] `foo` cannot be published. -`package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing. +`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish. ", ) .run(); @@ -1020,7 +1020,7 @@ fn block_publish_no_registry() { .with_stderr( "\ [ERROR] `foo` cannot be published. -`package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing. +`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish. ", ) .run(); @@ -3004,3 +3004,32 @@ Caused by: .with_status(101) .run(); } + +#[cargo_test] +fn versionless_package() { + // Use local registry for faster test times since no publish will occur + let registry = registry::init(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + description = "foo" + "#, + ) + .file("src/main.rs", r#"fn main() { println!("hello"); }"#) + .build(); + + p.cargo("publish") + .replace_crates_io(registry.index_url()) + .with_status(101) + .with_stderr( + "\ +error: `foo` cannot be published. +`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish. +", + ) + .run(); +} diff --git a/src/tools/cargo/tests/testsuite/registry.rs b/src/tools/cargo/tests/testsuite/registry.rs index f485180c9..b5dff2746 100644 --- a/src/tools/cargo/tests/testsuite/registry.rs +++ b/src/tools/cargo/tests/testsuite/registry.rs @@ -3600,4 +3600,55 @@ fn differ_only_by_metadata() { ", ) .run(); + + Package::new("baz", "0.0.1+d").publish(); + + p.cargo("clean").run(); + p.cargo("check") + .with_stderr_contains("[CHECKING] baz v0.0.1+b") + .run(); +} + +#[cargo_test] +fn differ_only_by_metadata_with_lockfile() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies] + baz = "=0.0.1" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + Package::new("baz", "0.0.1+a").publish(); + Package::new("baz", "0.0.1+b").publish(); + Package::new("baz", "0.0.1+c").publish(); + + p.cargo("update --package baz --precise 0.0.1+b") + .with_stderr( + "\ +[UPDATING] [..] index +[..] baz v0.0.1+c -> v0.0.1+b +", + ) + .run(); + + p.cargo("check") + .with_stderr( + "\ +[DOWNLOADING] crates ... +[DOWNLOADED] [..] v0.0.1+b (registry `dummy-registry`) +[CHECKING] baz v0.0.1+b +[CHECKING] foo v0.0.1 ([CWD]) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s +", + ) + .run(); } diff --git a/src/tools/cargo/tests/testsuite/run.rs b/src/tools/cargo/tests/testsuite/run.rs index c58c239ac..c7ddd5d9e 100644 --- a/src/tools/cargo/tests/testsuite/run.rs +++ b/src/tools/cargo/tests/testsuite/run.rs @@ -50,7 +50,7 @@ error: unexpected argument '--silent' found tip: a similar argument exists: '--quiet' -Usage: cargo[EXE] run [OPTIONS] [args]... +Usage: cargo[EXE] run [OPTIONS] [ARGS]... For more information, try '--help'. ", @@ -65,7 +65,7 @@ error: unexpected argument '--silent' found tip: a similar argument exists: '--quiet' -Usage: cargo[EXE] run [OPTIONS] [args]... +Usage: cargo[EXE] run [OPTIONS] [ARGS]... For more information, try '--help'. ", diff --git a/src/tools/cargo/tests/testsuite/rustdoc.rs b/src/tools/cargo/tests/testsuite/rustdoc.rs index 5650f3e0a..7ef768a80 100644 --- a/src/tools/cargo/tests/testsuite/rustdoc.rs +++ b/src/tools/cargo/tests/testsuite/rustdoc.rs @@ -15,6 +15,7 @@ fn rustdoc_simple() { [..] \ -L dependency=[CWD]/target/debug/deps [..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -35,6 +36,7 @@ fn rustdoc_args() { -C metadata=[..] \ -L dependency=[CWD]/target/debug/deps [..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -88,6 +90,7 @@ fn rustdoc_foo_with_bar_dependency() { -L dependency=[CWD]/target/debug/deps \ --extern [..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -127,6 +130,7 @@ fn rustdoc_only_bar_dependency() { -C metadata=[..] \ -L dependency=[CWD]/target/debug/deps [..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/bar/index.html ", ) .run(); @@ -150,6 +154,7 @@ fn rustdoc_same_name_documents_lib() { -C metadata=[..] \ -L dependency=[CWD]/target/debug/deps [..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); @@ -225,7 +230,8 @@ fn rustdoc_target() { [..] \ -L dependency=[CWD]/target/{target}/debug/deps \ -L dependency=[CWD]/target/debug/deps[..]` -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]", +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/[..]/doc/foo/index.html", target = cross_compile::alternate() )) .run(); diff --git a/src/tools/cargo/tests/testsuite/rustdocflags.rs b/src/tools/cargo/tests/testsuite/rustdocflags.rs index c37d5a826..e7c2aa263 100644 --- a/src/tools/cargo/tests/testsuite/rustdocflags.rs +++ b/src/tools/cargo/tests/testsuite/rustdocflags.rs @@ -48,7 +48,10 @@ fn rerun() { p.cargo("doc").env("RUSTDOCFLAGS", "--cfg=foo").run(); p.cargo("doc") .env("RUSTDOCFLAGS", "--cfg=foo") - .with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]") + .with_stderr( + "[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html", + ) .run(); p.cargo("doc") .env("RUSTDOCFLAGS", "--cfg=bar") @@ -56,6 +59,7 @@ fn rerun() { "\ [DOCUMENTING] foo v0.0.1 ([..]) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[GENERATED] [CWD]/target/doc/foo/index.html ", ) .run(); diff --git a/src/tools/cargo/tests/testsuite/script.rs b/src/tools/cargo/tests/testsuite/script.rs index 96f3a5eb4..0b1e5a6b9 100644 --- a/src/tools/cargo/tests/testsuite/script.rs +++ b/src/tools/cargo/tests/testsuite/script.rs @@ -108,6 +108,7 @@ error: no such command: `echo` <tab>Did you mean `bench`? <tab>View all installed commands with `cargo --list` +<tab>Find a package to install `echo` with `cargo search cargo-echo` ", ) .run(); diff --git a/src/tools/cargo/tests/testsuite/search.rs b/src/tools/cargo/tests/testsuite/search.rs index 4c3155c8f..c76397ac7 100644 --- a/src/tools/cargo/tests/testsuite/search.rs +++ b/src/tools/cargo/tests/testsuite/search.rs @@ -1,5 +1,6 @@ //! Tests for the `cargo search` command. +use cargo::util::cache_lock::CacheLockMode; use cargo_test_support::cargo_process; use cargo_test_support::paths; use cargo_test_support::registry::{RegistryBuilder, Response}; @@ -100,7 +101,9 @@ fn not_update() { paths::root(), paths::home().join(".cargo"), ); - let lock = cfg.acquire_package_cache_lock().unwrap(); + let lock = cfg + .acquire_package_cache_lock(CacheLockMode::DownloadExclusive) + .unwrap(); let mut regsrc = RegistrySource::remote(sid, &HashSet::new(), &cfg).unwrap(); regsrc.invalidate_cache(); regsrc.block_until_ready().unwrap(); diff --git a/src/tools/cargo/tests/testsuite/update.rs b/src/tools/cargo/tests/testsuite/update.rs index fe1d86bd7..e636435b0 100644 --- a/src/tools/cargo/tests/testsuite/update.rs +++ b/src/tools/cargo/tests/testsuite/update.rs @@ -392,6 +392,104 @@ fn update_precise() { } #[cargo_test] +fn update_precise_mismatched() { + Package::new("serde", "1.2.0").publish(); + Package::new("serde", "1.2.1").publish(); + Package::new("serde", "1.6.0").publish(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "bar" + version = "0.0.1" + authors = [] + + [dependencies] + serde = "~1.2" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check").run(); + + // `1.6.0` does not match `"~1.2"` + p.cargo("update serde:1.2 --precise 1.6.0") + .with_stderr( + "\ +[UPDATING] `[..]` index +[ERROR] failed to select a version for the requirement `serde = \"~1.2\"` +candidate versions found which didn't match: 1.6.0 +location searched: `[..]` index (which is replacing registry `crates-io`) +required by package `bar v0.0.1 ([..]/foo)` +perhaps a crate was updated and forgotten to be re-vendored? +", + ) + .with_status(101) + .run(); + + // `1.9.0` does not exist + p.cargo("update serde:1.2 --precise 1.9.0") + // This terrible error message has been the same for a long time. A fix is more than welcome! + .with_stderr( + "\ +[UPDATING] `[..]` index +[ERROR] no matching package named `serde` found +location searched: registry `crates-io` +required by package `bar v0.0.1 ([..]/foo)` +", + ) + .with_status(101) + .run(); +} + +#[cargo_test] +fn update_precise_build_metadata() { + Package::new("serde", "0.0.1+first").publish(); + Package::new("serde", "0.0.1+second").publish(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.0" + + [dependencies] + serde = "0.0.1" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("generate-lockfile").run(); + p.cargo("update serde --precise 0.0.1+first").run(); + + p.cargo("update serde --precise 0.0.1+second") + .with_stderr( + "\ +[UPDATING] `[..]` index +[UPDATING] serde v0.0.1+first -> v0.0.1+second +", + ) + .run(); + + // This is not considered "Downgrading". Build metadata are not assumed to + // be ordered. + p.cargo("update serde --precise 0.0.1+first") + .with_stderr( + "\ +[UPDATING] `[..]` index +[UPDATING] serde v0.0.1+second -> v0.0.1+first +", + ) + .run(); +} + +#[cargo_test] fn update_precise_do_not_force_update_deps() { Package::new("log", "0.1.0").publish(); Package::new("serde", "0.2.1").dep("log", "0.1").publish(); diff --git a/src/tools/cargo/tests/testsuite/version.rs b/src/tools/cargo/tests/testsuite/version.rs index f880c75a6..110e61003 100644 --- a/src/tools/cargo/tests/testsuite/version.rs +++ b/src/tools/cargo/tests/testsuite/version.rs @@ -13,6 +13,10 @@ fn simple() { p.cargo("--version") .with_stdout(&format!("cargo {}\n", cargo::version())) .run(); + + p.cargo("-V") + .with_stdout(&format!("cargo {}\n", cargo::version())) + .run(); } #[cargo_test] diff --git a/src/tools/cargo/tests/testsuite/warn_on_failure.rs b/src/tools/cargo/tests/testsuite/warn_on_failure.rs index 19cb01813..f2c2bb071 100644 --- a/src/tools/cargo/tests/testsuite/warn_on_failure.rs +++ b/src/tools/cargo/tests/testsuite/warn_on_failure.rs @@ -105,7 +105,7 @@ fn warning_on_lib_failure() { .with_stderr_contains("[UPDATING] `[..]` index") .with_stderr_contains("[DOWNLOADED] bar v0.0.1 ([..])") .with_stderr_contains("[COMPILING] bar v0.0.1") - .with_stderr_contains(&format!("[WARNING] {}", WARNING1)) - .with_stderr_contains(&format!("[WARNING] {}", WARNING2)) + .with_stderr_contains(&format!("[WARNING] bar@0.0.1: {}", WARNING1)) + .with_stderr_contains(&format!("[WARNING] bar@0.0.1: {}", WARNING2)) .run(); } diff --git a/src/tools/cargo/tests/testsuite/workspaces.rs b/src/tools/cargo/tests/testsuite/workspaces.rs index 4f8997b38..94b5142f4 100644 --- a/src/tools/cargo/tests/testsuite/workspaces.rs +++ b/src/tools/cargo/tests/testsuite/workspaces.rs @@ -1046,7 +1046,7 @@ fn members_include_path_deps() { } #[cargo_test] -fn new_warns_you_this_will_not_work() { +fn new_creates_members_list() { let p = project() .file( "Cargo.toml", @@ -1063,20 +1063,7 @@ fn new_warns_you_this_will_not_work() { let p = p.build(); p.cargo("new --lib bar") - .with_stderr( - "\ -warning: compiling this new package may not work due to invalid workspace configuration - -current package believes it's in a workspace when it's not: -current: [..] -workspace: [..] - -this may be fixable by ensuring that this crate is depended on by the workspace \ -root: [..] -[..] -[CREATED] library `bar` package -", - ) + .with_stderr(" Created library `bar` package") .run(); } |