diff --git a/src/bin/cargo/commands/add.rs b/src/bin/cargo/commands/add.rs index 32c7699e775..1ff2aad1944 100644 --- a/src/bin/cargo/commands/add.rs +++ b/src/bin/cargo/commands/add.rs @@ -7,6 +7,7 @@ use cargo::ops::cargo_add::add; use cargo::ops::cargo_add::AddOptions; use cargo::ops::cargo_add::DepOp; use cargo::ops::cargo_add::DepTable; +use cargo::ops::resolve_ws; use cargo::util::command_prelude::*; use cargo::util::interning::InternedString; use cargo::CargoResult; @@ -193,6 +194,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { }; add(&ws, &options)?; + if !dry_run { + // Reload the workspace since we've changed dependencies + let ws = args.workspace(config)?; + resolve_ws(&ws)?; + } + Ok(()) } diff --git a/src/cargo/ops/cargo_add/manifest.rs b/src/cargo/ops/cargo_add/manifest.rs index b90b7808392..1c96b477062 100644 --- a/src/cargo/ops/cargo_add/manifest.rs +++ b/src/cargo/ops/cargo_add/manifest.rs @@ -238,8 +238,7 @@ impl str::FromStr for Manifest { impl std::fmt::Display for Manifest { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let s = self.data.to_string(); - s.fmt(f) + self.data.fmt(f) } } @@ -433,6 +432,12 @@ impl LocalManifest { } } +impl std::fmt::Display for LocalManifest { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.manifest.fmt(f) + } +} + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] enum DependencyStatus { None, diff --git a/src/cargo/ops/cargo_add/mod.rs b/src/cargo/ops/cargo_add/mod.rs index a1cc0d272aa..c584a03f858 100644 --- a/src/cargo/ops/cargo_add/mod.rs +++ b/src/cargo/ops/cargo_add/mod.rs @@ -62,6 +62,7 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<( let manifest_path = options.spec.manifest_path().to_path_buf(); let mut manifest = LocalManifest::try_new(&manifest_path)?; + let original_raw_manifest = manifest.to_string(); let legacy = manifest.get_legacy_sections(); if !legacy.is_empty() { anyhow::bail!( @@ -142,6 +143,16 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<( } } + if options.config.locked() { + let new_raw_manifest = manifest.to_string(); + if original_raw_manifest != new_raw_manifest { + anyhow::bail!( + "the manifest file {} needs to be updated but --locked was passed to prevent this", + manifest.path.display() + ); + } + } + if options.dry_run { options.config.shell().warn("aborting add due to dry run")?; } else { diff --git a/tests/testsuite/cargo_add/build_prefer_existing_version/in/dependency/Cargo.toml b/tests/testsuite/cargo_add/build_prefer_existing_version/in/dependency/Cargo.toml index cbe244113c1..58b909ceff0 100644 --- a/tests/testsuite/cargo_add/build_prefer_existing_version/in/dependency/Cargo.toml +++ b/tests/testsuite/cargo_add/build_prefer_existing_version/in/dependency/Cargo.toml @@ -3,3 +3,7 @@ [package] name = "cargo-list-test-fixture-dependency" version = "0.0.0" + +[features] +one = [] +two = [] diff --git a/tests/testsuite/cargo_add/build_prefer_existing_version/out/dependency/Cargo.toml b/tests/testsuite/cargo_add/build_prefer_existing_version/out/dependency/Cargo.toml index cbe244113c1..58b909ceff0 100644 --- a/tests/testsuite/cargo_add/build_prefer_existing_version/out/dependency/Cargo.toml +++ b/tests/testsuite/cargo_add/build_prefer_existing_version/out/dependency/Cargo.toml @@ -3,3 +3,7 @@ [package] name = "cargo-list-test-fixture-dependency" version = "0.0.0" + +[features] +one = [] +two = [] diff --git a/tests/testsuite/cargo_add/build_prefer_existing_version/stderr.log b/tests/testsuite/cargo_add/build_prefer_existing_version/stderr.log index 00f39cd5b98..554aa2ef31d 100644 --- a/tests/testsuite/cargo_add/build_prefer_existing_version/stderr.log +++ b/tests/testsuite/cargo_add/build_prefer_existing_version/stderr.log @@ -1 +1,4 @@ Adding cargo-list-test-fixture-dependency (local) to build-dependencies. + Features: + - one + - two diff --git a/tests/testsuite/cargo_add/dev_prefer_existing_version/in/dependency/Cargo.toml b/tests/testsuite/cargo_add/dev_prefer_existing_version/in/dependency/Cargo.toml index cbe244113c1..58b909ceff0 100644 --- a/tests/testsuite/cargo_add/dev_prefer_existing_version/in/dependency/Cargo.toml +++ b/tests/testsuite/cargo_add/dev_prefer_existing_version/in/dependency/Cargo.toml @@ -3,3 +3,7 @@ [package] name = "cargo-list-test-fixture-dependency" version = "0.0.0" + +[features] +one = [] +two = [] diff --git a/tests/testsuite/cargo_add/dev_prefer_existing_version/out/dependency/Cargo.toml b/tests/testsuite/cargo_add/dev_prefer_existing_version/out/dependency/Cargo.toml index cbe244113c1..58b909ceff0 100644 --- a/tests/testsuite/cargo_add/dev_prefer_existing_version/out/dependency/Cargo.toml +++ b/tests/testsuite/cargo_add/dev_prefer_existing_version/out/dependency/Cargo.toml @@ -3,3 +3,7 @@ [package] name = "cargo-list-test-fixture-dependency" version = "0.0.0" + +[features] +one = [] +two = [] diff --git a/tests/testsuite/cargo_add/dev_prefer_existing_version/stderr.log b/tests/testsuite/cargo_add/dev_prefer_existing_version/stderr.log index d8093d6aece..06673543a9f 100644 --- a/tests/testsuite/cargo_add/dev_prefer_existing_version/stderr.log +++ b/tests/testsuite/cargo_add/dev_prefer_existing_version/stderr.log @@ -1 +1,4 @@ Adding cargo-list-test-fixture-dependency (local) to dev-dependencies. + Features: + - one + - two diff --git a/tests/testsuite/cargo_add/git/stderr.log b/tests/testsuite/cargo_add/git/stderr.log index fdfb1a952a1..839d8bb3272 100644 --- a/tests/testsuite/cargo_add/git/stderr.log +++ b/tests/testsuite/cargo_add/git/stderr.log @@ -1,2 +1,3 @@ Updating git repository `[ROOTURL]/git-package` Adding git-package (git) to dependencies. + Updating git repository `[ROOTURL]/git-package` diff --git a/tests/testsuite/cargo_add/git_branch/stderr.log b/tests/testsuite/cargo_add/git_branch/stderr.log index fdfb1a952a1..839d8bb3272 100644 --- a/tests/testsuite/cargo_add/git_branch/stderr.log +++ b/tests/testsuite/cargo_add/git_branch/stderr.log @@ -1,2 +1,3 @@ Updating git repository `[ROOTURL]/git-package` Adding git-package (git) to dependencies. + Updating git repository `[ROOTURL]/git-package` diff --git a/tests/testsuite/cargo_add/git_dev/stderr.log b/tests/testsuite/cargo_add/git_dev/stderr.log index 4ba31625b58..8e53bb4beea 100644 --- a/tests/testsuite/cargo_add/git_dev/stderr.log +++ b/tests/testsuite/cargo_add/git_dev/stderr.log @@ -1,2 +1,3 @@ Updating git repository `[ROOTURL]/git-package` Adding git-package (git) to dev-dependencies. + Updating git repository `[ROOTURL]/git-package` diff --git a/tests/testsuite/cargo_add/git_inferred_name/stderr.log b/tests/testsuite/cargo_add/git_inferred_name/stderr.log index 48f251ea11d..b5e8b1c9ba3 100644 --- a/tests/testsuite/cargo_add/git_inferred_name/stderr.log +++ b/tests/testsuite/cargo_add/git_inferred_name/stderr.log @@ -1,3 +1,4 @@ Updating git repository `[ROOTURL]/git-package` Updating git repository `[ROOTURL]/git-package` Adding git-package (git) to dependencies. + Updating git repository `[ROOTURL]/git-package` diff --git a/tests/testsuite/cargo_add/git_multiple_names/stderr.log b/tests/testsuite/cargo_add/git_multiple_names/stderr.log index e67710147da..454f0c797ee 100644 --- a/tests/testsuite/cargo_add/git_multiple_names/stderr.log +++ b/tests/testsuite/cargo_add/git_multiple_names/stderr.log @@ -1,3 +1,4 @@ Updating git repository `[ROOTURL]/git-package` Adding my-package1 (git) to dependencies. Adding my-package2 (git) to dependencies. + Updating git repository `[ROOTURL]/git-package` diff --git a/tests/testsuite/cargo_add/git_registry/mod.rs b/tests/testsuite/cargo_add/git_registry/mod.rs index 20ebb39a848..b546f63abef 100644 --- a/tests/testsuite/cargo_add/git_registry/mod.rs +++ b/tests/testsuite/cargo_add/git_registry/mod.rs @@ -32,7 +32,7 @@ fn git_registry() { ]) .current_dir(cwd) .assert() - .success() + .failure() .stdout_matches_path(curr_dir!().join("stdout.log")) .stderr_matches_path(curr_dir!().join("stderr.log")); diff --git a/tests/testsuite/cargo_add/git_registry/stderr.log b/tests/testsuite/cargo_add/git_registry/stderr.log index 548debfadf6..c554c7ec082 100644 --- a/tests/testsuite/cargo_add/git_registry/stderr.log +++ b/tests/testsuite/cargo_add/git_registry/stderr.log @@ -1,2 +1,6 @@ Updating git repository `[ROOTURL]/versioned-package` Adding versioned-package (git) to dependencies. +error: failed to parse manifest at `[ROOT]/case/Cargo.toml` + +Caused by: + dependency (versioned-package) specification is ambiguous. Only one of `git` or `registry` is allowed. diff --git a/tests/testsuite/cargo_add/git_rev/stderr.log b/tests/testsuite/cargo_add/git_rev/stderr.log index fdfb1a952a1..839d8bb3272 100644 --- a/tests/testsuite/cargo_add/git_rev/stderr.log +++ b/tests/testsuite/cargo_add/git_rev/stderr.log @@ -1,2 +1,3 @@ Updating git repository `[ROOTURL]/git-package` Adding git-package (git) to dependencies. + Updating git repository `[ROOTURL]/git-package` diff --git a/tests/testsuite/cargo_add/git_tag/stderr.log b/tests/testsuite/cargo_add/git_tag/stderr.log index fdfb1a952a1..839d8bb3272 100644 --- a/tests/testsuite/cargo_add/git_tag/stderr.log +++ b/tests/testsuite/cargo_add/git_tag/stderr.log @@ -1,2 +1,3 @@ Updating git repository `[ROOTURL]/git-package` Adding git-package (git) to dependencies. + Updating git repository `[ROOTURL]/git-package` diff --git a/tests/testsuite/cargo_add/list_features_path/in/dependency/Cargo.toml b/tests/testsuite/cargo_add/list_features_path/in/dependency/Cargo.toml index 34157f41182..18041a53fd6 100644 --- a/tests/testsuite/cargo_add/list_features_path/in/dependency/Cargo.toml +++ b/tests/testsuite/cargo_add/list_features_path/in/dependency/Cargo.toml @@ -3,8 +3,7 @@ name = "your-face" version = "0.1.3" [dependencies] -toml_edit = "0.1.5" -atty = "0.2.13" +my-package = "0.1.1" optional-dependency = { path = "../optional", optional = true } [features] diff --git a/tests/testsuite/cargo_add/list_features_path/in/optional/Cargo.toml b/tests/testsuite/cargo_add/list_features_path/in/optional/Cargo.toml index 0216dba8987..cb61a05144c 100644 --- a/tests/testsuite/cargo_add/list_features_path/in/optional/Cargo.toml +++ b/tests/testsuite/cargo_add/list_features_path/in/optional/Cargo.toml @@ -1,7 +1,6 @@ [package] -name = "optional-dep" +name = "optional-dependency" version = "0.1.3" [dependencies] -toml_edit = "0.1.5" -atty = "0.2.13" +my-package = "0.1.1" diff --git a/tests/testsuite/cargo_add/list_features_path/out/dependency/Cargo.toml b/tests/testsuite/cargo_add/list_features_path/out/dependency/Cargo.toml index 34157f41182..18041a53fd6 100644 --- a/tests/testsuite/cargo_add/list_features_path/out/dependency/Cargo.toml +++ b/tests/testsuite/cargo_add/list_features_path/out/dependency/Cargo.toml @@ -3,8 +3,7 @@ name = "your-face" version = "0.1.3" [dependencies] -toml_edit = "0.1.5" -atty = "0.2.13" +my-package = "0.1.1" optional-dependency = { path = "../optional", optional = true } [features] diff --git a/tests/testsuite/cargo_add/list_features_path/stderr.log b/tests/testsuite/cargo_add/list_features_path/stderr.log index 27378049be0..af6747fe836 100644 --- a/tests/testsuite/cargo_add/list_features_path/stderr.log +++ b/tests/testsuite/cargo_add/list_features_path/stderr.log @@ -4,3 +4,4 @@ + nose - eyes - optional-dependency + Updating `dummy-registry` index diff --git a/tests/testsuite/cargo_add/list_features_path_no_default/in/dependency/Cargo.toml b/tests/testsuite/cargo_add/list_features_path_no_default/in/dependency/Cargo.toml index 34157f41182..18041a53fd6 100644 --- a/tests/testsuite/cargo_add/list_features_path_no_default/in/dependency/Cargo.toml +++ b/tests/testsuite/cargo_add/list_features_path_no_default/in/dependency/Cargo.toml @@ -3,8 +3,7 @@ name = "your-face" version = "0.1.3" [dependencies] -toml_edit = "0.1.5" -atty = "0.2.13" +my-package = "0.1.1" optional-dependency = { path = "../optional", optional = true } [features] diff --git a/tests/testsuite/cargo_add/list_features_path_no_default/in/optional/Cargo.toml b/tests/testsuite/cargo_add/list_features_path_no_default/in/optional/Cargo.toml index 0216dba8987..cb61a05144c 100644 --- a/tests/testsuite/cargo_add/list_features_path_no_default/in/optional/Cargo.toml +++ b/tests/testsuite/cargo_add/list_features_path_no_default/in/optional/Cargo.toml @@ -1,7 +1,6 @@ [package] -name = "optional-dep" +name = "optional-dependency" version = "0.1.3" [dependencies] -toml_edit = "0.1.5" -atty = "0.2.13" +my-package = "0.1.1" diff --git a/tests/testsuite/cargo_add/list_features_path_no_default/out/dependency/Cargo.toml b/tests/testsuite/cargo_add/list_features_path_no_default/out/dependency/Cargo.toml index 34157f41182..18041a53fd6 100644 --- a/tests/testsuite/cargo_add/list_features_path_no_default/out/dependency/Cargo.toml +++ b/tests/testsuite/cargo_add/list_features_path_no_default/out/dependency/Cargo.toml @@ -3,8 +3,7 @@ name = "your-face" version = "0.1.3" [dependencies] -toml_edit = "0.1.5" -atty = "0.2.13" +my-package = "0.1.1" optional-dependency = { path = "../optional", optional = true } [features] diff --git a/tests/testsuite/cargo_add/list_features_path_no_default/stderr.log b/tests/testsuite/cargo_add/list_features_path_no_default/stderr.log index cc6c8346279..7f47a220ec0 100644 --- a/tests/testsuite/cargo_add/list_features_path_no_default/stderr.log +++ b/tests/testsuite/cargo_add/list_features_path_no_default/stderr.log @@ -4,3 +4,4 @@ - mouth - nose - optional-dependency + Updating `dummy-registry` index diff --git a/tests/testsuite/cargo_add/locked_changed/in b/tests/testsuite/cargo_add/locked_changed/in new file mode 120000 index 00000000000..6c6a27fcfb5 --- /dev/null +++ b/tests/testsuite/cargo_add/locked_changed/in @@ -0,0 +1 @@ +../add-basic.in \ No newline at end of file diff --git a/tests/testsuite/cargo_add/locked_changed/mod.rs b/tests/testsuite/cargo_add/locked_changed/mod.rs new file mode 100644 index 00000000000..f4156f8e5f0 --- /dev/null +++ b/tests/testsuite/cargo_add/locked_changed/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::prelude::*; +use cargo_test_support::Project; + +use crate::cargo_add::init_registry; +use cargo_test_support::curr_dir; + +#[cargo_test] +fn locked_changed() { + init_registry(); + 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("my-package --locked") + .current_dir(cwd) + .assert() + .failure() + .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/tests/testsuite/cargo_add/locked_changed/out/Cargo.toml b/tests/testsuite/cargo_add/locked_changed/out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/testsuite/cargo_add/locked_changed/out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/testsuite/cargo_add/locked_changed/stderr.log b/tests/testsuite/cargo_add/locked_changed/stderr.log new file mode 100644 index 00000000000..8af16837396 --- /dev/null +++ b/tests/testsuite/cargo_add/locked_changed/stderr.log @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package v99999.0.0 to dependencies. +error: the manifest file [ROOT]/case/Cargo.toml needs to be updated but --locked was passed to prevent this diff --git a/tests/testsuite/cargo_add/locked_changed/stdout.log b/tests/testsuite/cargo_add/locked_changed/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_add/locked_unchanged/in/Cargo.lock b/tests/testsuite/cargo_add/locked_unchanged/in/Cargo.lock new file mode 100644 index 00000000000..011b335926e --- /dev/null +++ b/tests/testsuite/cargo_add/locked_unchanged/in/Cargo.lock @@ -0,0 +1,16 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cargo-list-test-fixture" +version = "0.0.0" +dependencies = [ + "my-package", +] + +[[package]] +name = "my-package" +version = "99999.0.0+my-package" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62c45acf9e11d2f97f5b318143219c0b4102eafef1c22a4b545b47104691d915" diff --git a/tests/testsuite/cargo_add/locked_unchanged/in/Cargo.toml b/tests/testsuite/cargo_add/locked_unchanged/in/Cargo.toml new file mode 100644 index 00000000000..5964c87be74 --- /dev/null +++ b/tests/testsuite/cargo_add/locked_unchanged/in/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package = "99999.0.0" diff --git a/tests/testsuite/cargo_add/locked_unchanged/in/src/lib.rs b/tests/testsuite/cargo_add/locked_unchanged/in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_add/locked_unchanged/mod.rs b/tests/testsuite/cargo_add/locked_unchanged/mod.rs new file mode 100644 index 00000000000..8352155f93e --- /dev/null +++ b/tests/testsuite/cargo_add/locked_unchanged/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::prelude::*; +use cargo_test_support::Project; + +use crate::cargo_add::init_registry; +use cargo_test_support::curr_dir; + +#[cargo_test] +fn locked_unchanged() { + init_registry(); + 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("my-package --locked") + .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/tests/testsuite/cargo_add/locked_unchanged/out/Cargo.toml b/tests/testsuite/cargo_add/locked_unchanged/out/Cargo.toml new file mode 100644 index 00000000000..5964c87be74 --- /dev/null +++ b/tests/testsuite/cargo_add/locked_unchanged/out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package = "99999.0.0" diff --git a/tests/testsuite/cargo_add/locked_unchanged/stderr.log b/tests/testsuite/cargo_add/locked_unchanged/stderr.log new file mode 100644 index 00000000000..fd6b711e386 --- /dev/null +++ b/tests/testsuite/cargo_add/locked_unchanged/stderr.log @@ -0,0 +1,2 @@ + Updating `dummy-registry` index + Adding my-package v99999.0.0 to dependencies. diff --git a/tests/testsuite/cargo_add/locked_unchanged/stdout.log b/tests/testsuite/cargo_add/locked_unchanged/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_add/lockfile_updated/in/Cargo.lock b/tests/testsuite/cargo_add/lockfile_updated/in/Cargo.lock new file mode 100644 index 00000000000..d9bcc988d3f --- /dev/null +++ b/tests/testsuite/cargo_add/lockfile_updated/in/Cargo.lock @@ -0,0 +1,17 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cargo-list-test-fixture" +version = "0.0.0" +dependencies = [ + "my-package", + "unrelateed-crate", +] + +[[package]] +name = "unrelateed-crate" +version = "0.2.0+my-package" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "266de4849a570b5dfda5e8e082a2aff885e9d2d4965dae8f8b6c8535e1ec731f" diff --git a/tests/testsuite/cargo_add/lockfile_updated/in/Cargo.toml b/tests/testsuite/cargo_add/lockfile_updated/in/Cargo.toml new file mode 100644 index 00000000000..95276d7c584 --- /dev/null +++ b/tests/testsuite/cargo_add/lockfile_updated/in/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +unrelateed-crate = "0.2.0" diff --git a/tests/testsuite/cargo_add/lockfile_updated/in/src/lib.rs b/tests/testsuite/cargo_add/lockfile_updated/in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_add/lockfile_updated/mod.rs b/tests/testsuite/cargo_add/lockfile_updated/mod.rs new file mode 100644 index 00000000000..41d39efdf5d --- /dev/null +++ b/tests/testsuite/cargo_add/lockfile_updated/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::prelude::*; +use cargo_test_support::Project; + +use crate::cargo_add::init_registry; +use cargo_test_support::curr_dir; + +#[cargo_test] +fn lockfile_updated() { + init_registry(); + 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("my-package") + .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/tests/testsuite/cargo_add/lockfile_updated/out/Cargo.lock b/tests/testsuite/cargo_add/lockfile_updated/out/Cargo.lock new file mode 100644 index 00000000000..4b5fb465f10 --- /dev/null +++ b/tests/testsuite/cargo_add/lockfile_updated/out/Cargo.lock @@ -0,0 +1,23 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cargo-list-test-fixture" +version = "0.0.0" +dependencies = [ + "my-package", + "unrelateed-crate", +] + +[[package]] +name = "my-package" +version = "99999.0.0+my-package" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62c45acf9e11d2f97f5b318143219c0b4102eafef1c22a4b545b47104691d915" + +[[package]] +name = "unrelateed-crate" +version = "0.2.0+my-package" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "266de4849a570b5dfda5e8e082a2aff885e9d2d4965dae8f8b6c8535e1ec731f" diff --git a/tests/testsuite/cargo_add/lockfile_updated/out/Cargo.toml b/tests/testsuite/cargo_add/lockfile_updated/out/Cargo.toml new file mode 100644 index 00000000000..3176a986ae7 --- /dev/null +++ b/tests/testsuite/cargo_add/lockfile_updated/out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package = "99999.0.0" +unrelateed-crate = "0.2.0" diff --git a/tests/testsuite/cargo_add/lockfile_updated/stderr.log b/tests/testsuite/cargo_add/lockfile_updated/stderr.log new file mode 100644 index 00000000000..fd6b711e386 --- /dev/null +++ b/tests/testsuite/cargo_add/lockfile_updated/stderr.log @@ -0,0 +1,2 @@ + Updating `dummy-registry` index + Adding my-package v99999.0.0 to dependencies. diff --git a/tests/testsuite/cargo_add/lockfile_updated/stdout.log b/tests/testsuite/cargo_add/lockfile_updated/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_add/mod.rs b/tests/testsuite/cargo_add/mod.rs index 1eb682ef2ed..ae32bdd2de3 100644 --- a/tests/testsuite/cargo_add/mod.rs +++ b/tests/testsuite/cargo_add/mod.rs @@ -48,6 +48,9 @@ mod invalid_vers; mod list_features; mod list_features_path; mod list_features_path_no_default; +mod locked_changed; +mod locked_unchanged; +mod lockfile_updated; mod manifest_path_package; mod merge_activated_features; mod multiple_conflicts_with_features; @@ -131,6 +134,9 @@ fn add_registry_packages(alt: bool) { cargo_test_support::registry::Package::new(name, "0.1.1+my-package") .alternative(alt) .publish(); + cargo_test_support::registry::Package::new(name, "0.2.0+my-package") + .alternative(alt) + .publish(); cargo_test_support::registry::Package::new(name, "0.2.3+my-package") .alternative(alt) .publish(); diff --git a/tests/testsuite/cargo_add/overwrite_optional_with_no_optional/in/Cargo.toml b/tests/testsuite/cargo_add/overwrite_optional_with_no_optional/in/Cargo.toml index 195d5c7e061..5ef95320946 100644 --- a/tests/testsuite/cargo_add/overwrite_optional_with_no_optional/in/Cargo.toml +++ b/tests/testsuite/cargo_add/overwrite_optional_with_no_optional/in/Cargo.toml @@ -5,9 +5,9 @@ name = "cargo-list-test-fixture" version = "0.0.0" [features] -default = ["my-package1"] -other = ["my-package1/nose"] +default = ["your-face"] +other = ["your-face/nose"] [dependencies] -my-package1 = { version = "99999.0.0", optional = true } +your-face = { version = "99999.0.0", optional = true } my-package2 = { version = "0.4.1", optional = true } diff --git a/tests/testsuite/cargo_add/overwrite_optional_with_no_optional/mod.rs b/tests/testsuite/cargo_add/overwrite_optional_with_no_optional/mod.rs index 48f3e0bfa6d..fce33e2a66b 100644 --- a/tests/testsuite/cargo_add/overwrite_optional_with_no_optional/mod.rs +++ b/tests/testsuite/cargo_add/overwrite_optional_with_no_optional/mod.rs @@ -14,7 +14,7 @@ fn overwrite_optional_with_no_optional() { snapbox::cmd::Command::cargo_ui() .arg("add") - .arg_line("my-package1 my-package2@0.4.1 --no-optional") + .arg_line("your-face my-package2@0.4.1 --no-optional") .current_dir(cwd) .assert() .success() diff --git a/tests/testsuite/cargo_add/overwrite_optional_with_no_optional/out/Cargo.toml b/tests/testsuite/cargo_add/overwrite_optional_with_no_optional/out/Cargo.toml index 6301685d17e..bf6c52963b8 100644 --- a/tests/testsuite/cargo_add/overwrite_optional_with_no_optional/out/Cargo.toml +++ b/tests/testsuite/cargo_add/overwrite_optional_with_no_optional/out/Cargo.toml @@ -6,8 +6,8 @@ version = "0.0.0" [features] default = [] -other = ["my-package1/nose"] +other = ["your-face/nose"] [dependencies] -my-package1 = { version = "99999.0.0" } +your-face = { version = "99999.0.0" } my-package2 = { version = "0.4.1" } diff --git a/tests/testsuite/cargo_add/overwrite_optional_with_no_optional/stderr.log b/tests/testsuite/cargo_add/overwrite_optional_with_no_optional/stderr.log index fb8d4903d7b..5fe113e86c7 100644 --- a/tests/testsuite/cargo_add/overwrite_optional_with_no_optional/stderr.log +++ b/tests/testsuite/cargo_add/overwrite_optional_with_no_optional/stderr.log @@ -1,3 +1,8 @@ Updating `dummy-registry` index - Adding my-package1 v99999.0.0 to dependencies. + Adding your-face v99999.0.0 to dependencies. + Features: + - ears + - eyes + - mouth + - nose Adding my-package2 v0.4.1 to dependencies. diff --git a/tests/testsuite/cargo_add/overwrite_version_with_git/stderr.log b/tests/testsuite/cargo_add/overwrite_version_with_git/stderr.log index c5013969264..1b77cbe0e35 100644 --- a/tests/testsuite/cargo_add/overwrite_version_with_git/stderr.log +++ b/tests/testsuite/cargo_add/overwrite_version_with_git/stderr.log @@ -1,2 +1,3 @@ Updating git repository `[ROOTURL]/versioned-package` Adding versioned-package (git) to optional dependencies. + Updating git repository `[ROOTURL]/versioned-package` diff --git a/tests/testsuite/cargo_add/preserve_sorted/in/Cargo.toml b/tests/testsuite/cargo_add/preserve_sorted/in/Cargo.toml index 2716d647883..550e41b07e9 100644 --- a/tests/testsuite/cargo_add/preserve_sorted/in/Cargo.toml +++ b/tests/testsuite/cargo_add/preserve_sorted/in/Cargo.toml @@ -5,5 +5,5 @@ name = "cargo-list-test-fixture" version = "0.0.0" [dependencies] -atty = "0.2.13" -toml_edit = "0.1.5" +my-package = "0.1.1" +versioned-package = "0.1.1" diff --git a/tests/testsuite/cargo_add/preserve_sorted/out/Cargo.toml b/tests/testsuite/cargo_add/preserve_sorted/out/Cargo.toml index 88222bd2a22..cacd510ccdf 100644 --- a/tests/testsuite/cargo_add/preserve_sorted/out/Cargo.toml +++ b/tests/testsuite/cargo_add/preserve_sorted/out/Cargo.toml @@ -5,6 +5,6 @@ name = "cargo-list-test-fixture" version = "0.0.0" [dependencies] -atty = "0.2.13" +my-package = "0.1.1" toml = "99999.0.0" -toml_edit = "0.1.5" +versioned-package = "0.1.1" diff --git a/tests/testsuite/cargo_add/preserve_unsorted/in/Cargo.toml b/tests/testsuite/cargo_add/preserve_unsorted/in/Cargo.toml index 5957df98b62..f803120a3a0 100644 --- a/tests/testsuite/cargo_add/preserve_unsorted/in/Cargo.toml +++ b/tests/testsuite/cargo_add/preserve_unsorted/in/Cargo.toml @@ -5,5 +5,5 @@ name = "cargo-list-test-fixture" version = "0.0.0" [dependencies] -toml_edit = "0.1.5" -atty = "0.2.13" +versioned-package = "0.1.1" +my-package = "0.1.1" diff --git a/tests/testsuite/cargo_add/preserve_unsorted/out/Cargo.toml b/tests/testsuite/cargo_add/preserve_unsorted/out/Cargo.toml index e01b9255ecc..244a06ab9ae 100644 --- a/tests/testsuite/cargo_add/preserve_unsorted/out/Cargo.toml +++ b/tests/testsuite/cargo_add/preserve_unsorted/out/Cargo.toml @@ -5,6 +5,6 @@ name = "cargo-list-test-fixture" version = "0.0.0" [dependencies] -toml_edit = "0.1.5" -atty = "0.2.13" +versioned-package = "0.1.1" +my-package = "0.1.1" toml = "99999.0.0"