diff --git a/src/bin/cargo/commands/mod.rs b/src/bin/cargo/commands/mod.rs index 11534d3dd90..da3109260a4 100644 --- a/src/bin/cargo/commands/mod.rs +++ b/src/bin/cargo/commands/mod.rs @@ -26,6 +26,7 @@ pub fn builtin() -> Vec { pkgid::cli(), publish::cli(), read_manifest::cli(), + remove::cli(), report::cli(), run::cli(), rustc::cli(), @@ -68,6 +69,7 @@ pub fn builtin_exec(cmd: &str) -> Option CliResu "pkgid" => pkgid::exec, "publish" => publish::exec, "read-manifest" => read_manifest::exec, + "remove" => remove::exec, "report" => report::exec, "run" => run::exec, "rustc" => rustc::exec, @@ -110,6 +112,7 @@ pub mod package; pub mod pkgid; pub mod publish; pub mod read_manifest; +pub mod remove; pub mod report; pub mod run; pub mod rustc; diff --git a/src/bin/cargo/commands/remove.rs b/src/bin/cargo/commands/remove.rs new file mode 100644 index 00000000000..56d60c8b161 --- /dev/null +++ b/src/bin/cargo/commands/remove.rs @@ -0,0 +1,116 @@ +use cargo::core::dependency::DepKind; +use cargo::ops::cargo_remove::remove; +use cargo::ops::cargo_remove::RemoveOptions; +use cargo::ops::resolve_ws; +use cargo::util::command_prelude::*; +use cargo::util::toml_mut::manifest::DepTable; + +pub fn cli() -> clap::Command { + clap::Command::new("remove") + // Subcommand aliases are handled in `aliased_command()`. + // .alias("rm") + .about("Remove dependencies from a Cargo.toml manifest file") + .args([clap::Arg::new("dependencies") + .action(clap::ArgAction::Append) + .required(true) + .num_args(1..) + .value_name("DEP_ID") + .help("Dependencies to be removed")]) + .arg_package("Package to remove from") + .arg_manifest_path() + .arg_quiet() + .arg_dry_run("Don't actually write the manifest") + .next_help_heading("SECTION") + .args([ + clap::Arg::new("dev") + .long("dev") + .conflicts_with("build") + .action(clap::ArgAction::SetTrue) + .group("section") + .help("Remove as development dependency"), + clap::Arg::new("build") + .long("build") + .conflicts_with("dev") + .action(clap::ArgAction::SetTrue) + .group("section") + .help("Remove as build dependency"), + clap::Arg::new("target") + .long("target") + .num_args(1) + .value_name("TARGET") + .value_parser(clap::builder::NonEmptyStringValueParser::new()) + .help("Remove as dependency from the given target platform"), + ]) +} + +pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { + let dry_run = args.dry_run(); + + let workspace = args.workspace(config)?; + let packages = args.packages_from_flags()?; + let packages = packages.get_packages(&workspace)?; + let spec = match packages.len() { + 0 => { + return Err(CliError::new( + anyhow::format_err!("no packages selected. Please specify one with `-p `"), + 101, + )); + } + 1 => packages[0], + len => { + return Err(CliError::new( + anyhow::format_err!( + "{len} packages selected. Please specify one with `-p `", + ), + 101, + )); + } + }; + + let dependencies = args + .get_many::("dependencies") + .expect("required(true)") + .cloned() + .collect(); + + let section = parse_section(args); + + let options = RemoveOptions { + config, + spec, + dependencies, + section, + dry_run, + }; + remove(&options)?; + + if !dry_run { + // Reload the workspace since we've changed dependencies + let ws = args.workspace(config)?; + resolve_ws(&ws)?; + } + + Ok(()) +} + +fn parse_section(args: &ArgMatches) -> DepTable { + let dev = args.flag("dev"); + let build = args.flag("build"); + + let kind = if dev { + DepKind::Development + } else if build { + DepKind::Build + } else { + DepKind::Normal + }; + + let mut table = DepTable::new().set_kind(kind); + + if let Some(target) = args.get_one::("target") { + assert!(!target.is_empty(), "Target specification may not be empty"); + table = table.set_target(target); + } + + table +} diff --git a/src/bin/cargo/main.rs b/src/bin/cargo/main.rs index 3c0c943e9f1..70adebb9431 100644 --- a/src/bin/cargo/main.rs +++ b/src/bin/cargo/main.rs @@ -39,12 +39,13 @@ fn main() { /// Table for defining the aliases which come builtin in `Cargo`. /// The contents are structured as: `(alias, aliased_command, description)`. -const BUILTIN_ALIASES: [(&str, &str, &str); 5] = [ +const BUILTIN_ALIASES: [(&str, &str, &str); 6] = [ ("b", "build", "alias: build"), ("c", "check", "alias: check"), ("d", "doc", "alias: doc"), ("r", "run", "alias: run"), ("t", "test", "alias: test"), + ("rm", "remove", "alias: remove"), ]; /// Function which contains the list of all of the builtin aliases and it's diff --git a/src/cargo/ops/cargo_remove.rs b/src/cargo/ops/cargo_remove.rs new file mode 100644 index 00000000000..4866caeddac --- /dev/null +++ b/src/cargo/ops/cargo_remove.rs @@ -0,0 +1,65 @@ +//! Core of cargo-remove command + +use crate::core::Package; +use crate::util::toml_mut::manifest::DepTable; +use crate::util::toml_mut::manifest::LocalManifest; +use crate::CargoResult; +use crate::Config; + +/// Remove a dependency from a Cargo.toml manifest file. +#[derive(Debug)] +pub struct RemoveOptions<'a> { + /// Configuration information for Cargo operations + pub config: &'a Config, + /// Package to remove dependencies from + pub spec: &'a Package, + /// Dependencies to remove + pub dependencies: Vec, + /// Which dependency section to remove these from + pub section: DepTable, + /// Whether or not to actually write the manifest + pub dry_run: bool, +} + +/// Remove dependencies from a manifest +pub fn remove(options: &RemoveOptions<'_>) -> CargoResult<()> { + let dep_table = options + .section + .to_table() + .into_iter() + .map(String::from) + .collect::>(); + + let manifest_path = options.spec.manifest_path().to_path_buf(); + let mut manifest = LocalManifest::try_new(&manifest_path)?; + + for dep in &options.dependencies { + let section = if dep_table.len() >= 3 { + format!("{} for target `{}`", &dep_table[2], &dep_table[1]) + } else { + dep_table[0].clone() + }; + options + .config + .shell() + .status("Removing", format!("{dep} from {section}"))?; + + manifest.remove_from_table(&dep_table, dep)?; + + // Now that we have removed the crate, if that was the last reference to that + // crate, then we need to drop any explicitly activated features on + // that crate. + manifest.gc_dep(dep); + } + + if options.dry_run { + options + .config + .shell() + .warn("aborting remove due to dry run")?; + } else { + manifest.write()?; + } + + Ok(()) +} diff --git a/src/cargo/ops/mod.rs b/src/cargo/ops/mod.rs index d9895ea0882..ea04aa0be32 100644 --- a/src/cargo/ops/mod.rs +++ b/src/cargo/ops/mod.rs @@ -45,6 +45,7 @@ mod cargo_output_metadata; mod cargo_package; mod cargo_pkgid; mod cargo_read_manifest; +pub mod cargo_remove; mod cargo_run; mod cargo_test; mod cargo_uninstall; diff --git a/src/cargo/util/toml_mut/manifest.rs b/src/cargo/util/toml_mut/manifest.rs index c9a5f5d2cfa..9d98d581b63 100644 --- a/src/cargo/util/toml_mut/manifest.rs +++ b/src/cargo/util/toml_mut/manifest.rs @@ -368,6 +368,26 @@ impl LocalManifest { Ok(()) } + /// Remove entry from a Cargo.toml. + pub fn remove_from_table(&mut self, table_path: &[String], name: &str) -> CargoResult<()> { + let parent_table = self.get_table_mut(table_path)?; + + let dep = parent_table + .get_mut(name) + .filter(|t| !t.is_none()) + .ok_or_else(|| non_existent_dependency_err(name, table_path.join(".")))?; + + // remove the dependency + *dep = toml_edit::Item::None; + + // remove table if empty + if parent_table.as_table_like().unwrap().is_empty() { + *parent_table = toml_edit::Item::None; + } + + Ok(()) + } + /// Remove references to `dep_key` if its no longer present. pub fn gc_dep(&mut self, dep_key: &str) { let explicit_dep_activation = self.is_explicit_dep_activation(dep_key); @@ -504,6 +524,8 @@ fn fix_feature_activations( } } } + + feature_values.fmt(); } pub fn str_or_1_len_table(item: &toml_edit::Item) -> bool { @@ -517,3 +539,10 @@ fn parse_manifest_err() -> anyhow::Error { fn non_existent_table_err(table: impl std::fmt::Display) -> anyhow::Error { anyhow::format_err!("the table `{table}` could not be found.") } + +fn non_existent_dependency_err( + name: impl std::fmt::Display, + table: impl std::fmt::Display, +) -> anyhow::Error { + anyhow::format_err!("the dependency `{name}` could not be found in `{table}`.") +} diff --git a/tests/testsuite/cargo_remove/avoid_empty_tables/in b/tests/testsuite/cargo_remove/avoid_empty_tables/in new file mode 120000 index 00000000000..7fd0ba5ebcc --- /dev/null +++ b/tests/testsuite/cargo_remove/avoid_empty_tables/in @@ -0,0 +1 @@ +../remove-basic.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/avoid_empty_tables/mod.rs b/tests/testsuite/cargo_remove/avoid_empty_tables/mod.rs new file mode 100644 index 00000000000..59a2333d6f7 --- /dev/null +++ b/tests/testsuite/cargo_remove/avoid_empty_tables/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["clippy"]) + .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_remove/avoid_empty_tables/out/Cargo.toml b/tests/testsuite/cargo_remove/avoid_empty_tables/out/Cargo.toml new file mode 100644 index 00000000000..09a9ee86e81 --- /dev/null +++ b/tests/testsuite/cargo_remove/avoid_empty_tables/out/Cargo.toml @@ -0,0 +1,23 @@ +[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 = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/avoid_empty_tables/stderr.log b/tests/testsuite/cargo_remove/avoid_empty_tables/stderr.log new file mode 100644 index 00000000000..dd71023a864 --- /dev/null +++ b/tests/testsuite/cargo_remove/avoid_empty_tables/stderr.log @@ -0,0 +1,2 @@ + Removing clippy from dependencies + Updating `dummy-registry` index diff --git a/tests/testsuite/cargo_remove/avoid_empty_tables/stdout.log b/tests/testsuite/cargo_remove/avoid_empty_tables/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/build/in b/tests/testsuite/cargo_remove/build/in new file mode 120000 index 00000000000..7fd0ba5ebcc --- /dev/null +++ b/tests/testsuite/cargo_remove/build/in @@ -0,0 +1 @@ +../remove-basic.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/build/mod.rs b/tests/testsuite/cargo_remove/build/mod.rs new file mode 100644 index 00000000000..f4c9dcb94de --- /dev/null +++ b/tests/testsuite/cargo_remove/build/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["--build", "semver"]) + .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_remove/build/out/Cargo.toml b/tests/testsuite/cargo_remove/build/out/Cargo.toml new file mode 100644 index 00000000000..babdc0a9990 --- /dev/null +++ b/tests/testsuite/cargo_remove/build/out/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "cargo-remove-test-fixture" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[dependencies] +docopt = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/build/stderr.log b/tests/testsuite/cargo_remove/build/stderr.log new file mode 100644 index 00000000000..f037ebe28ce --- /dev/null +++ b/tests/testsuite/cargo_remove/build/stderr.log @@ -0,0 +1,2 @@ + Removing semver from build-dependencies + Updating `dummy-registry` index diff --git a/tests/testsuite/cargo_remove/build/stdout.log b/tests/testsuite/cargo_remove/build/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/dev/in b/tests/testsuite/cargo_remove/dev/in new file mode 120000 index 00000000000..7fd0ba5ebcc --- /dev/null +++ b/tests/testsuite/cargo_remove/dev/in @@ -0,0 +1 @@ +../remove-basic.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/dev/mod.rs b/tests/testsuite/cargo_remove/dev/mod.rs new file mode 100644 index 00000000000..7d61fa95405 --- /dev/null +++ b/tests/testsuite/cargo_remove/dev/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["--dev", "regex"]) + .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_remove/dev/out/Cargo.toml b/tests/testsuite/cargo_remove/dev/out/Cargo.toml new file mode 100644 index 00000000000..40744a56671 --- /dev/null +++ b/tests/testsuite/cargo_remove/dev/out/Cargo.toml @@ -0,0 +1,23 @@ +[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 = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/dev/stderr.log b/tests/testsuite/cargo_remove/dev/stderr.log new file mode 100644 index 00000000000..c629b26b19d --- /dev/null +++ b/tests/testsuite/cargo_remove/dev/stderr.log @@ -0,0 +1,2 @@ + Removing regex from dev-dependencies + Updating `dummy-registry` index diff --git a/tests/testsuite/cargo_remove/dev/stdout.log b/tests/testsuite/cargo_remove/dev/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/dry_run/in b/tests/testsuite/cargo_remove/dry_run/in new file mode 120000 index 00000000000..7fd0ba5ebcc --- /dev/null +++ b/tests/testsuite/cargo_remove/dry_run/in @@ -0,0 +1 @@ +../remove-basic.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/dry_run/mod.rs b/tests/testsuite/cargo_remove/dry_run/mod.rs new file mode 100644 index 00000000000..dca18931550 --- /dev/null +++ b/tests/testsuite/cargo_remove/dry_run/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["semver", "--dry-run"]) + .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_remove/dry_run/out/Cargo.toml b/tests/testsuite/cargo_remove/dry_run/out/Cargo.toml new file mode 100644 index 00000000000..340f06cda79 --- /dev/null +++ b/tests/testsuite/cargo_remove/dry_run/out/Cargo.toml @@ -0,0 +1,24 @@ +[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 = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/dry_run/out/src/lib.rs b/tests/testsuite/cargo_remove/dry_run/out/src/lib.rs new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tests/testsuite/cargo_remove/dry_run/out/src/lib.rs @@ -0,0 +1 @@ + diff --git a/tests/testsuite/cargo_remove/dry_run/stderr.log b/tests/testsuite/cargo_remove/dry_run/stderr.log new file mode 100644 index 00000000000..8b118911c61 --- /dev/null +++ b/tests/testsuite/cargo_remove/dry_run/stderr.log @@ -0,0 +1,2 @@ + Removing semver from dependencies +warning: aborting remove due to dry run diff --git a/tests/testsuite/cargo_remove/dry_run/stdout.log b/tests/testsuite/cargo_remove/dry_run/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/invalid_arg/in b/tests/testsuite/cargo_remove/invalid_arg/in new file mode 120000 index 00000000000..7fd0ba5ebcc --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_arg/in @@ -0,0 +1 @@ +../remove-basic.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/invalid_arg/mod.rs b/tests/testsuite/cargo_remove/invalid_arg/mod.rs new file mode 100644 index 00000000000..eac3c8b4643 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_arg/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["foo", "--flag"]) + .current_dir(cwd) + .assert() + .code(1) + .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_remove/invalid_arg/out/Cargo.toml b/tests/testsuite/cargo_remove/invalid_arg/out/Cargo.toml new file mode 100644 index 00000000000..340f06cda79 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_arg/out/Cargo.toml @@ -0,0 +1,24 @@ +[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 = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/invalid_arg/stderr.log b/tests/testsuite/cargo_remove/invalid_arg/stderr.log new file mode 100644 index 00000000000..683247216fa --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_arg/stderr.log @@ -0,0 +1,7 @@ +error: Found argument '--flag' which wasn't expected, or isn't valid in this context + + If you tried to supply '--flag' as a value rather than a flag, use '-- --flag' + +Usage: cargo[EXE] remove ... + +For more information try '--help' diff --git a/tests/testsuite/cargo_remove/invalid_arg/stdout.log b/tests/testsuite/cargo_remove/invalid_arg/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/invalid_dep/in b/tests/testsuite/cargo_remove/invalid_dep/in new file mode 120000 index 00000000000..7fd0ba5ebcc --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_dep/in @@ -0,0 +1 @@ +../remove-basic.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/invalid_dep/mod.rs b/tests/testsuite/cargo_remove/invalid_dep/mod.rs new file mode 100644 index 00000000000..c4dbeae910a --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_dep/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["invalid_dependency_name"]) + .current_dir(cwd) + .assert() + .code(101) + .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_remove/invalid_dep/out/Cargo.toml b/tests/testsuite/cargo_remove/invalid_dep/out/Cargo.toml new file mode 100644 index 00000000000..340f06cda79 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_dep/out/Cargo.toml @@ -0,0 +1,24 @@ +[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 = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/invalid_dep/stderr.log b/tests/testsuite/cargo_remove/invalid_dep/stderr.log new file mode 100644 index 00000000000..eea124d6580 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_dep/stderr.log @@ -0,0 +1,2 @@ + Removing invalid_dependency_name from dependencies +error: the dependency `invalid_dependency_name` could not be found in `dependencies`. diff --git a/tests/testsuite/cargo_remove/invalid_dep/stdout.log b/tests/testsuite/cargo_remove/invalid_dep/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/invalid_package/in b/tests/testsuite/cargo_remove/invalid_package/in new file mode 120000 index 00000000000..e2165e8cb72 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_package/in @@ -0,0 +1 @@ +../remove-package.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/invalid_package/mod.rs b/tests/testsuite/cargo_remove/invalid_package/mod.rs new file mode 100644 index 00000000000..bff09882ed9 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_package/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["docopt", "--package", "dep-c"]) + .current_dir(cwd) + .assert() + .code(101) + .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_remove/invalid_package/out/Cargo.toml b/tests/testsuite/cargo_remove/invalid_package/out/Cargo.toml new file mode 100644 index 00000000000..73385711332 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_package/out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] +members = [ + "dep-a", + "dep-b" +] diff --git a/tests/testsuite/cargo_remove/invalid_package/out/dep-a/Cargo.toml b/tests/testsuite/cargo_remove/invalid_package/out/dep-a/Cargo.toml new file mode 100644 index 00000000000..7e87ce314da --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_package/out/dep-a/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "dep-a" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[build-dependencies] +semver = "0.1.0" + +[dependencies] +docopt = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/invalid_package/out/dep-a/src/lib.rs b/tests/testsuite/cargo_remove/invalid_package/out/dep-a/src/lib.rs new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_package/out/dep-a/src/lib.rs @@ -0,0 +1 @@ + diff --git a/tests/testsuite/cargo_remove/invalid_package/out/dep-b/Cargo.toml b/tests/testsuite/cargo_remove/invalid_package/out/dep-b/Cargo.toml new file mode 100644 index 00000000000..37d2d3ddf0b --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_package/out/dep-b/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "dep-b" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[build-dependencies] +semver = "0.1.0" + +[dependencies] +docopt = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/invalid_package/out/dep-b/src/lib.rs b/tests/testsuite/cargo_remove/invalid_package/out/dep-b/src/lib.rs new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_package/out/dep-b/src/lib.rs @@ -0,0 +1 @@ + diff --git a/tests/testsuite/cargo_remove/invalid_package/stderr.log b/tests/testsuite/cargo_remove/invalid_package/stderr.log new file mode 100644 index 00000000000..683512ca007 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_package/stderr.log @@ -0,0 +1 @@ +error: package(s) `dep-c` not found in workspace `[ROOT]/case` diff --git a/tests/testsuite/cargo_remove/invalid_package/stdout.log b/tests/testsuite/cargo_remove/invalid_package/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/invalid_package_multiple/in b/tests/testsuite/cargo_remove/invalid_package_multiple/in new file mode 120000 index 00000000000..e2165e8cb72 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_package_multiple/in @@ -0,0 +1 @@ +../remove-package.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/invalid_package_multiple/mod.rs b/tests/testsuite/cargo_remove/invalid_package_multiple/mod.rs new file mode 100644 index 00000000000..5093d5d2dc7 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_package_multiple/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["docopt"]) + .current_dir(cwd) + .assert() + .code(101) + .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_remove/invalid_package_multiple/out/Cargo.toml b/tests/testsuite/cargo_remove/invalid_package_multiple/out/Cargo.toml new file mode 100644 index 00000000000..73385711332 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_package_multiple/out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] +members = [ + "dep-a", + "dep-b" +] diff --git a/tests/testsuite/cargo_remove/invalid_package_multiple/out/dep-a/Cargo.toml b/tests/testsuite/cargo_remove/invalid_package_multiple/out/dep-a/Cargo.toml new file mode 100644 index 00000000000..7e87ce314da --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_package_multiple/out/dep-a/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "dep-a" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[build-dependencies] +semver = "0.1.0" + +[dependencies] +docopt = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/invalid_package_multiple/out/dep-a/src/lib.rs b/tests/testsuite/cargo_remove/invalid_package_multiple/out/dep-a/src/lib.rs new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_package_multiple/out/dep-a/src/lib.rs @@ -0,0 +1 @@ + diff --git a/tests/testsuite/cargo_remove/invalid_package_multiple/out/dep-b/Cargo.toml b/tests/testsuite/cargo_remove/invalid_package_multiple/out/dep-b/Cargo.toml new file mode 100644 index 00000000000..37d2d3ddf0b --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_package_multiple/out/dep-b/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "dep-b" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[build-dependencies] +semver = "0.1.0" + +[dependencies] +docopt = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/invalid_package_multiple/out/dep-b/src/lib.rs b/tests/testsuite/cargo_remove/invalid_package_multiple/out/dep-b/src/lib.rs new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_package_multiple/out/dep-b/src/lib.rs @@ -0,0 +1 @@ + diff --git a/tests/testsuite/cargo_remove/invalid_package_multiple/stderr.log b/tests/testsuite/cargo_remove/invalid_package_multiple/stderr.log new file mode 100644 index 00000000000..b18ca3b8b0e --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_package_multiple/stderr.log @@ -0,0 +1 @@ +error: 2 packages selected. Please specify one with `-p ` diff --git a/tests/testsuite/cargo_remove/invalid_package_multiple/stdout.log b/tests/testsuite/cargo_remove/invalid_package_multiple/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/invalid_section/in b/tests/testsuite/cargo_remove/invalid_section/in new file mode 120000 index 00000000000..7fd0ba5ebcc --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_section/in @@ -0,0 +1 @@ +../remove-basic.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/invalid_section/mod.rs b/tests/testsuite/cargo_remove/invalid_section/mod.rs new file mode 100644 index 00000000000..80d42be1d6a --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_section/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["--build", "docopt"]) + .current_dir(cwd) + .assert() + .code(101) + .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_remove/invalid_section/out/Cargo.toml b/tests/testsuite/cargo_remove/invalid_section/out/Cargo.toml new file mode 100644 index 00000000000..340f06cda79 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_section/out/Cargo.toml @@ -0,0 +1,24 @@ +[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 = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/invalid_section/stderr.log b/tests/testsuite/cargo_remove/invalid_section/stderr.log new file mode 100644 index 00000000000..fff5ff00ae7 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_section/stderr.log @@ -0,0 +1,2 @@ + Removing docopt from build-dependencies +error: the dependency `docopt` could not be found in `build-dependencies`. diff --git a/tests/testsuite/cargo_remove/invalid_section/stdout.log b/tests/testsuite/cargo_remove/invalid_section/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/invalid_section_dep/in b/tests/testsuite/cargo_remove/invalid_section_dep/in new file mode 120000 index 00000000000..7fd0ba5ebcc --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_section_dep/in @@ -0,0 +1 @@ +../remove-basic.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/invalid_section_dep/mod.rs b/tests/testsuite/cargo_remove/invalid_section_dep/mod.rs new file mode 100644 index 00000000000..7be8fd6284a --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_section_dep/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["--dev", "semver", "regex"]) + .current_dir(cwd) + .assert() + .code(101) + .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_remove/invalid_section_dep/out/Cargo.toml b/tests/testsuite/cargo_remove/invalid_section_dep/out/Cargo.toml new file mode 100644 index 00000000000..340f06cda79 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_section_dep/out/Cargo.toml @@ -0,0 +1,24 @@ +[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 = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/invalid_section_dep/stderr.log b/tests/testsuite/cargo_remove/invalid_section_dep/stderr.log new file mode 100644 index 00000000000..1926f9577e4 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_section_dep/stderr.log @@ -0,0 +1,2 @@ + Removing semver from dev-dependencies +error: the dependency `semver` could not be found in `dev-dependencies`. diff --git a/tests/testsuite/cargo_remove/invalid_section_dep/stdout.log b/tests/testsuite/cargo_remove/invalid_section_dep/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/invalid_target/in b/tests/testsuite/cargo_remove/invalid_target/in new file mode 120000 index 00000000000..d5742d03887 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_target/in @@ -0,0 +1 @@ +../remove-target.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/invalid_target/mod.rs b/tests/testsuite/cargo_remove/invalid_target/mod.rs new file mode 100644 index 00000000000..34deb6cb848 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_target/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["--target", "powerpc-unknown-linux-gnu", "dbus"]) + .current_dir(cwd) + .assert() + .code(101) + .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_remove/invalid_target/out/Cargo.toml b/tests/testsuite/cargo_remove/invalid_target/out/Cargo.toml new file mode 100644 index 00000000000..14747c70b50 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_target/out/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "cargo-remove-target-test-fixture" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[target.x86_64-unknown-freebsd.build-dependencies] +semver = "0.1.0" + +[target.x86_64-unknown-linux-gnu.build-dependencies] +semver = "0.1.0" + +[dependencies] +docopt = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[target.x86_64-unknown-linux-gnu.dependencies] +dbus = "0.6.2" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[target.x86_64-unknown-linux-gnu.dev-dependencies] +ncurses = "20.0" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/invalid_target/stderr.log b/tests/testsuite/cargo_remove/invalid_target/stderr.log new file mode 100644 index 00000000000..5075b80b70c --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_target/stderr.log @@ -0,0 +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`. diff --git a/tests/testsuite/cargo_remove/invalid_target/stdout.log b/tests/testsuite/cargo_remove/invalid_target/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/invalid_target_dep/in b/tests/testsuite/cargo_remove/invalid_target_dep/in new file mode 120000 index 00000000000..d5742d03887 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_target_dep/in @@ -0,0 +1 @@ +../remove-target.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/invalid_target_dep/mod.rs b/tests/testsuite/cargo_remove/invalid_target_dep/mod.rs new file mode 100644 index 00000000000..e04418fa859 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_target_dep/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["--target", "x86_64-unknown-linux-gnu", "toml"]) + .current_dir(cwd) + .assert() + .code(101) + .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_remove/invalid_target_dep/out/Cargo.toml b/tests/testsuite/cargo_remove/invalid_target_dep/out/Cargo.toml new file mode 100644 index 00000000000..14747c70b50 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_target_dep/out/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "cargo-remove-target-test-fixture" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[target.x86_64-unknown-freebsd.build-dependencies] +semver = "0.1.0" + +[target.x86_64-unknown-linux-gnu.build-dependencies] +semver = "0.1.0" + +[dependencies] +docopt = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[target.x86_64-unknown-linux-gnu.dependencies] +dbus = "0.6.2" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[target.x86_64-unknown-linux-gnu.dev-dependencies] +ncurses = "20.0" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/invalid_target_dep/stderr.log b/tests/testsuite/cargo_remove/invalid_target_dep/stderr.log new file mode 100644 index 00000000000..54bfe085f15 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_target_dep/stderr.log @@ -0,0 +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`. diff --git a/tests/testsuite/cargo_remove/invalid_target_dep/stdout.log b/tests/testsuite/cargo_remove/invalid_target_dep/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/mod.rs b/tests/testsuite/cargo_remove/mod.rs new file mode 100644 index 00000000000..75178531ee3 --- /dev/null +++ b/tests/testsuite/cargo_remove/mod.rs @@ -0,0 +1,82 @@ +mod avoid_empty_tables; +mod build; +mod dev; +mod dry_run; +mod invalid_arg; +mod invalid_dep; +mod invalid_package; +mod invalid_package_multiple; +mod invalid_section; +mod invalid_section_dep; +mod invalid_target; +mod invalid_target_dep; +mod multiple_deps; +mod multiple_dev; +mod no_arg; +mod offline; +mod optional_dep_feature; +mod optional_feature; +mod package; +mod remove_basic; +mod target; +mod target_build; +mod target_dev; +mod update_lock_file; + +fn init_registry() { + cargo_test_support::registry::init(); + add_registry_packages(false); +} + +fn add_registry_packages(alt: bool) { + for name in [ + "clippy", + "dbus", + "docopt", + "ncurses", + "pad", + "regex", + "rustc-serialize", + "toml", + ] { + 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(); + cargo_test_support::registry::Package::new(name, "0.4.1+my-package") + .alternative(alt) + .publish(); + cargo_test_support::registry::Package::new(name, "0.6.2+my-package") + .alternative(alt) + .publish(); + cargo_test_support::registry::Package::new(name, "0.9.9+my-package") + .alternative(alt) + .publish(); + cargo_test_support::registry::Package::new(name, "1.0.90+my-package") + .alternative(alt) + .publish(); + cargo_test_support::registry::Package::new(name, "20.0.0+my-package") + .alternative(alt) + .publish(); + } + + for name in ["semver", "serde"] { + cargo_test_support::registry::Package::new(name, "0.1.1") + .alternative(alt) + .feature("std", &[]) + .publish(); + cargo_test_support::registry::Package::new(name, "0.9.0") + .alternative(alt) + .feature("std", &[]) + .publish(); + cargo_test_support::registry::Package::new(name, "1.0.90") + .alternative(alt) + .feature("std", &[]) + .publish(); + } +} diff --git a/tests/testsuite/cargo_remove/multiple_deps/in b/tests/testsuite/cargo_remove/multiple_deps/in new file mode 120000 index 00000000000..7fd0ba5ebcc --- /dev/null +++ b/tests/testsuite/cargo_remove/multiple_deps/in @@ -0,0 +1 @@ +../remove-basic.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/multiple_deps/mod.rs b/tests/testsuite/cargo_remove/multiple_deps/mod.rs new file mode 100644 index 00000000000..35922b73894 --- /dev/null +++ b/tests/testsuite/cargo_remove/multiple_deps/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["docopt", "semver"]) + .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_remove/multiple_deps/out/Cargo.toml b/tests/testsuite/cargo_remove/multiple_deps/out/Cargo.toml new file mode 100644 index 00000000000..53cde082936 --- /dev/null +++ b/tests/testsuite/cargo_remove/multiple_deps/out/Cargo.toml @@ -0,0 +1,22 @@ +[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 = "0.4" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/multiple_deps/stderr.log b/tests/testsuite/cargo_remove/multiple_deps/stderr.log new file mode 100644 index 00000000000..1eb59aca1b7 --- /dev/null +++ b/tests/testsuite/cargo_remove/multiple_deps/stderr.log @@ -0,0 +1,3 @@ + Removing docopt from dependencies + Removing semver from dependencies + Updating `dummy-registry` index diff --git a/tests/testsuite/cargo_remove/multiple_deps/stdout.log b/tests/testsuite/cargo_remove/multiple_deps/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/multiple_dev/in b/tests/testsuite/cargo_remove/multiple_dev/in new file mode 120000 index 00000000000..7fd0ba5ebcc --- /dev/null +++ b/tests/testsuite/cargo_remove/multiple_dev/in @@ -0,0 +1 @@ +../remove-basic.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/multiple_dev/mod.rs b/tests/testsuite/cargo_remove/multiple_dev/mod.rs new file mode 100644 index 00000000000..5eac7e2f8f5 --- /dev/null +++ b/tests/testsuite/cargo_remove/multiple_dev/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["--dev", "regex", "serde"]) + .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_remove/multiple_dev/out/Cargo.toml b/tests/testsuite/cargo_remove/multiple_dev/out/Cargo.toml new file mode 100644 index 00000000000..d961b2bb135 --- /dev/null +++ b/tests/testsuite/cargo_remove/multiple_dev/out/Cargo.toml @@ -0,0 +1,20 @@ +[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 = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[features] +std = ["semver/std"] diff --git a/tests/testsuite/cargo_remove/multiple_dev/stderr.log b/tests/testsuite/cargo_remove/multiple_dev/stderr.log new file mode 100644 index 00000000000..a3042dcc3cd --- /dev/null +++ b/tests/testsuite/cargo_remove/multiple_dev/stderr.log @@ -0,0 +1,3 @@ + Removing regex from dev-dependencies + Removing serde from dev-dependencies + Updating `dummy-registry` index diff --git a/tests/testsuite/cargo_remove/multiple_dev/stdout.log b/tests/testsuite/cargo_remove/multiple_dev/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/no_arg/in b/tests/testsuite/cargo_remove/no_arg/in new file mode 120000 index 00000000000..7fd0ba5ebcc --- /dev/null +++ b/tests/testsuite/cargo_remove/no_arg/in @@ -0,0 +1 @@ +../remove-basic.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/no_arg/mod.rs b/tests/testsuite/cargo_remove/no_arg/mod.rs new file mode 100644 index 00000000000..d0c66f9b05a --- /dev/null +++ b/tests/testsuite/cargo_remove/no_arg/mod.rs @@ -0,0 +1,24 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .current_dir(cwd) + .assert() + .code(1) + .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_remove/no_arg/out/Cargo.toml b/tests/testsuite/cargo_remove/no_arg/out/Cargo.toml new file mode 100644 index 00000000000..340f06cda79 --- /dev/null +++ b/tests/testsuite/cargo_remove/no_arg/out/Cargo.toml @@ -0,0 +1,24 @@ +[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 = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/no_arg/stderr.log b/tests/testsuite/cargo_remove/no_arg/stderr.log new file mode 100644 index 00000000000..fbb7e3ce24e --- /dev/null +++ b/tests/testsuite/cargo_remove/no_arg/stderr.log @@ -0,0 +1,6 @@ +error: The following required arguments were not provided: + ... + +Usage: cargo[EXE] remove ... + +For more information try '--help' diff --git a/tests/testsuite/cargo_remove/no_arg/stdout.log b/tests/testsuite/cargo_remove/no_arg/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/offline/in b/tests/testsuite/cargo_remove/offline/in new file mode 120000 index 00000000000..7fd0ba5ebcc --- /dev/null +++ b/tests/testsuite/cargo_remove/offline/in @@ -0,0 +1 @@ +../remove-basic.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/offline/mod.rs b/tests/testsuite/cargo_remove/offline/mod.rs new file mode 100644 index 00000000000..ab86ed55545 --- /dev/null +++ b/tests/testsuite/cargo_remove/offline/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; +use cargo_test_support::TestEnv; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + init_registry(); + let project = Project::from_template(curr_dir!().join("in")); + let project_root = project.root(); + let cwd = &project_root; + + // run the metadata command to populate the cache + let cargo = std::env::var_os("CARGO").unwrap(); + snapbox::cmd::Command::new(cargo) + .test_env() + .arg("metadata") + .current_dir(cwd) + .assert() + .success(); + + snapbox::cmd::Command::cargo_ui() + .arg("remove") + .args(["docopt", "--offline"]) + .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_remove/offline/out/Cargo.toml b/tests/testsuite/cargo_remove/offline/out/Cargo.toml new file mode 100644 index 00000000000..b8628eed1c2 --- /dev/null +++ b/tests/testsuite/cargo_remove/offline/out/Cargo.toml @@ -0,0 +1,23 @@ +[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 = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/offline/stderr.log b/tests/testsuite/cargo_remove/offline/stderr.log new file mode 100644 index 00000000000..7083976b17d --- /dev/null +++ b/tests/testsuite/cargo_remove/offline/stderr.log @@ -0,0 +1 @@ + Removing docopt from dependencies diff --git a/tests/testsuite/cargo_remove/offline/stdout.log b/tests/testsuite/cargo_remove/offline/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/optional_dep_feature/in b/tests/testsuite/cargo_remove/optional_dep_feature/in new file mode 120000 index 00000000000..7fd0ba5ebcc --- /dev/null +++ b/tests/testsuite/cargo_remove/optional_dep_feature/in @@ -0,0 +1 @@ +../remove-basic.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/optional_dep_feature/mod.rs b/tests/testsuite/cargo_remove/optional_dep_feature/mod.rs new file mode 100644 index 00000000000..cae736b347d --- /dev/null +++ b/tests/testsuite/cargo_remove/optional_dep_feature/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["--dev", "serde"]) + .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_remove/optional_dep_feature/out/Cargo.toml b/tests/testsuite/cargo_remove/optional_dep_feature/out/Cargo.toml new file mode 100644 index 00000000000..63112d33424 --- /dev/null +++ b/tests/testsuite/cargo_remove/optional_dep_feature/out/Cargo.toml @@ -0,0 +1,23 @@ +[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 = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +regex = "0.1.1" + +[features] +std = ["semver/std"] diff --git a/tests/testsuite/cargo_remove/optional_dep_feature/stderr.log b/tests/testsuite/cargo_remove/optional_dep_feature/stderr.log new file mode 100644 index 00000000000..72c9f92172d --- /dev/null +++ b/tests/testsuite/cargo_remove/optional_dep_feature/stderr.log @@ -0,0 +1,2 @@ + Removing serde from dev-dependencies + Updating `dummy-registry` index diff --git a/tests/testsuite/cargo_remove/optional_dep_feature/stdout.log b/tests/testsuite/cargo_remove/optional_dep_feature/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/optional_feature/in b/tests/testsuite/cargo_remove/optional_feature/in new file mode 120000 index 00000000000..7fd0ba5ebcc --- /dev/null +++ b/tests/testsuite/cargo_remove/optional_feature/in @@ -0,0 +1 @@ +../remove-basic.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/optional_feature/mod.rs b/tests/testsuite/cargo_remove/optional_feature/mod.rs new file mode 100644 index 00000000000..af54226bba5 --- /dev/null +++ b/tests/testsuite/cargo_remove/optional_feature/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["semver"]) + .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_remove/optional_feature/out/Cargo.toml b/tests/testsuite/cargo_remove/optional_feature/out/Cargo.toml new file mode 100644 index 00000000000..9ac0b1b3252 --- /dev/null +++ b/tests/testsuite/cargo_remove/optional_feature/out/Cargo.toml @@ -0,0 +1,23 @@ +[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 = "0.6" +rustc-serialize = "0.4" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/optional_feature/stderr.log b/tests/testsuite/cargo_remove/optional_feature/stderr.log new file mode 100644 index 00000000000..2dc546fa718 --- /dev/null +++ b/tests/testsuite/cargo_remove/optional_feature/stderr.log @@ -0,0 +1,2 @@ + Removing semver from dependencies + Updating `dummy-registry` index diff --git a/tests/testsuite/cargo_remove/optional_feature/stdout.log b/tests/testsuite/cargo_remove/optional_feature/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/package/in b/tests/testsuite/cargo_remove/package/in new file mode 120000 index 00000000000..e2165e8cb72 --- /dev/null +++ b/tests/testsuite/cargo_remove/package/in @@ -0,0 +1 @@ +../remove-package.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/package/mod.rs b/tests/testsuite/cargo_remove/package/mod.rs new file mode 100644 index 00000000000..2714f319725 --- /dev/null +++ b/tests/testsuite/cargo_remove/package/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["docopt", "--package", "dep-a"]) + .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_remove/package/out/Cargo.toml b/tests/testsuite/cargo_remove/package/out/Cargo.toml new file mode 100644 index 00000000000..73385711332 --- /dev/null +++ b/tests/testsuite/cargo_remove/package/out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] +members = [ + "dep-a", + "dep-b" +] diff --git a/tests/testsuite/cargo_remove/package/out/dep-a/Cargo.toml b/tests/testsuite/cargo_remove/package/out/dep-a/Cargo.toml new file mode 100644 index 00000000000..5f2bfe6fb1a --- /dev/null +++ b/tests/testsuite/cargo_remove/package/out/dep-a/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "dep-a" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[build-dependencies] +semver = "0.1.0" + +[dependencies] +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/package/out/dep-a/src/lib.rs b/tests/testsuite/cargo_remove/package/out/dep-a/src/lib.rs new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tests/testsuite/cargo_remove/package/out/dep-a/src/lib.rs @@ -0,0 +1 @@ + diff --git a/tests/testsuite/cargo_remove/package/out/dep-b/Cargo.toml b/tests/testsuite/cargo_remove/package/out/dep-b/Cargo.toml new file mode 100644 index 00000000000..37d2d3ddf0b --- /dev/null +++ b/tests/testsuite/cargo_remove/package/out/dep-b/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "dep-b" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[build-dependencies] +semver = "0.1.0" + +[dependencies] +docopt = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/package/out/dep-b/src/lib.rs b/tests/testsuite/cargo_remove/package/out/dep-b/src/lib.rs new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tests/testsuite/cargo_remove/package/out/dep-b/src/lib.rs @@ -0,0 +1 @@ + diff --git a/tests/testsuite/cargo_remove/package/stderr.log b/tests/testsuite/cargo_remove/package/stderr.log new file mode 100644 index 00000000000..231026f2bf6 --- /dev/null +++ b/tests/testsuite/cargo_remove/package/stderr.log @@ -0,0 +1,2 @@ + Removing docopt from dependencies + Updating `dummy-registry` index diff --git a/tests/testsuite/cargo_remove/package/stdout.log b/tests/testsuite/cargo_remove/package/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/remove-basic.in/Cargo.toml b/tests/testsuite/cargo_remove/remove-basic.in/Cargo.toml new file mode 100644 index 00000000000..340f06cda79 --- /dev/null +++ b/tests/testsuite/cargo_remove/remove-basic.in/Cargo.toml @@ -0,0 +1,24 @@ +[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 = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/remove-basic.in/src/lib.rs b/tests/testsuite/cargo_remove/remove-basic.in/src/lib.rs new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tests/testsuite/cargo_remove/remove-basic.in/src/lib.rs @@ -0,0 +1 @@ + diff --git a/tests/testsuite/cargo_remove/remove-package.in/Cargo.toml b/tests/testsuite/cargo_remove/remove-package.in/Cargo.toml new file mode 100644 index 00000000000..73385711332 --- /dev/null +++ b/tests/testsuite/cargo_remove/remove-package.in/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] +members = [ + "dep-a", + "dep-b" +] diff --git a/tests/testsuite/cargo_remove/remove-package.in/dep-a/Cargo.toml b/tests/testsuite/cargo_remove/remove-package.in/dep-a/Cargo.toml new file mode 100644 index 00000000000..7e87ce314da --- /dev/null +++ b/tests/testsuite/cargo_remove/remove-package.in/dep-a/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "dep-a" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[build-dependencies] +semver = "0.1.0" + +[dependencies] +docopt = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/remove-package.in/dep-a/src/lib.rs b/tests/testsuite/cargo_remove/remove-package.in/dep-a/src/lib.rs new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tests/testsuite/cargo_remove/remove-package.in/dep-a/src/lib.rs @@ -0,0 +1 @@ + diff --git a/tests/testsuite/cargo_remove/remove-package.in/dep-b/Cargo.toml b/tests/testsuite/cargo_remove/remove-package.in/dep-b/Cargo.toml new file mode 100644 index 00000000000..37d2d3ddf0b --- /dev/null +++ b/tests/testsuite/cargo_remove/remove-package.in/dep-b/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "dep-b" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[build-dependencies] +semver = "0.1.0" + +[dependencies] +docopt = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/remove-package.in/dep-b/src/lib.rs b/tests/testsuite/cargo_remove/remove-package.in/dep-b/src/lib.rs new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tests/testsuite/cargo_remove/remove-package.in/dep-b/src/lib.rs @@ -0,0 +1 @@ + diff --git a/tests/testsuite/cargo_remove/remove-target.in/Cargo.toml b/tests/testsuite/cargo_remove/remove-target.in/Cargo.toml new file mode 100644 index 00000000000..14747c70b50 --- /dev/null +++ b/tests/testsuite/cargo_remove/remove-target.in/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "cargo-remove-target-test-fixture" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[target.x86_64-unknown-freebsd.build-dependencies] +semver = "0.1.0" + +[target.x86_64-unknown-linux-gnu.build-dependencies] +semver = "0.1.0" + +[dependencies] +docopt = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[target.x86_64-unknown-linux-gnu.dependencies] +dbus = "0.6.2" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[target.x86_64-unknown-linux-gnu.dev-dependencies] +ncurses = "20.0" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/remove_basic/in b/tests/testsuite/cargo_remove/remove_basic/in new file mode 120000 index 00000000000..7fd0ba5ebcc --- /dev/null +++ b/tests/testsuite/cargo_remove/remove_basic/in @@ -0,0 +1 @@ +../remove-basic.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/remove_basic/mod.rs b/tests/testsuite/cargo_remove/remove_basic/mod.rs new file mode 100644 index 00000000000..53381e6bc99 --- /dev/null +++ b/tests/testsuite/cargo_remove/remove_basic/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["docopt"]) + .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_remove/remove_basic/out/Cargo.toml b/tests/testsuite/cargo_remove/remove_basic/out/Cargo.toml new file mode 100644 index 00000000000..b8628eed1c2 --- /dev/null +++ b/tests/testsuite/cargo_remove/remove_basic/out/Cargo.toml @@ -0,0 +1,23 @@ +[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 = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/remove_basic/stderr.log b/tests/testsuite/cargo_remove/remove_basic/stderr.log new file mode 100644 index 00000000000..231026f2bf6 --- /dev/null +++ b/tests/testsuite/cargo_remove/remove_basic/stderr.log @@ -0,0 +1,2 @@ + Removing docopt from dependencies + Updating `dummy-registry` index diff --git a/tests/testsuite/cargo_remove/remove_basic/stdout.log b/tests/testsuite/cargo_remove/remove_basic/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/target/in b/tests/testsuite/cargo_remove/target/in new file mode 120000 index 00000000000..d5742d03887 --- /dev/null +++ b/tests/testsuite/cargo_remove/target/in @@ -0,0 +1 @@ +../remove-target.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/target/mod.rs b/tests/testsuite/cargo_remove/target/mod.rs new file mode 100644 index 00000000000..1447c753d3c --- /dev/null +++ b/tests/testsuite/cargo_remove/target/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["--target", "x86_64-unknown-linux-gnu", "dbus"]) + .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_remove/target/out/Cargo.toml b/tests/testsuite/cargo_remove/target/out/Cargo.toml new file mode 100644 index 00000000000..e29fbbd0030 --- /dev/null +++ b/tests/testsuite/cargo_remove/target/out/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "cargo-remove-target-test-fixture" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[target.x86_64-unknown-freebsd.build-dependencies] +semver = "0.1.0" + +[target.x86_64-unknown-linux-gnu.build-dependencies] +semver = "0.1.0" + +[dependencies] +docopt = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[target.x86_64-unknown-linux-gnu.dev-dependencies] +ncurses = "20.0" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/target/stderr.log b/tests/testsuite/cargo_remove/target/stderr.log new file mode 100644 index 00000000000..810abd994d9 --- /dev/null +++ b/tests/testsuite/cargo_remove/target/stderr.log @@ -0,0 +1,2 @@ + Removing dbus from dependencies for target `x86_64-unknown-linux-gnu` + Updating `dummy-registry` index diff --git a/tests/testsuite/cargo_remove/target/stdout.log b/tests/testsuite/cargo_remove/target/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/target_build/in b/tests/testsuite/cargo_remove/target_build/in new file mode 120000 index 00000000000..d5742d03887 --- /dev/null +++ b/tests/testsuite/cargo_remove/target_build/in @@ -0,0 +1 @@ +../remove-target.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/target_build/mod.rs b/tests/testsuite/cargo_remove/target_build/mod.rs new file mode 100644 index 00000000000..11afbbf8f8d --- /dev/null +++ b/tests/testsuite/cargo_remove/target_build/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["--build", "--target", "x86_64-unknown-linux-gnu", "semver"]) + .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_remove/target_build/out/Cargo.toml b/tests/testsuite/cargo_remove/target_build/out/Cargo.toml new file mode 100644 index 00000000000..7353c7a897b --- /dev/null +++ b/tests/testsuite/cargo_remove/target_build/out/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "cargo-remove-target-test-fixture" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[target.x86_64-unknown-freebsd.build-dependencies] +semver = "0.1.0" + +[dependencies] +docopt = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[target.x86_64-unknown-linux-gnu.dependencies] +dbus = "0.6.2" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[target.x86_64-unknown-linux-gnu.dev-dependencies] +ncurses = "20.0" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/target_build/stderr.log b/tests/testsuite/cargo_remove/target_build/stderr.log new file mode 100644 index 00000000000..b06f8f319c5 --- /dev/null +++ b/tests/testsuite/cargo_remove/target_build/stderr.log @@ -0,0 +1,2 @@ + Removing semver from build-dependencies for target `x86_64-unknown-linux-gnu` + Updating `dummy-registry` index diff --git a/tests/testsuite/cargo_remove/target_build/stdout.log b/tests/testsuite/cargo_remove/target_build/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/target_dev/in b/tests/testsuite/cargo_remove/target_dev/in new file mode 120000 index 00000000000..d5742d03887 --- /dev/null +++ b/tests/testsuite/cargo_remove/target_dev/in @@ -0,0 +1 @@ +../remove-target.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/target_dev/mod.rs b/tests/testsuite/cargo_remove/target_dev/mod.rs new file mode 100644 index 00000000000..d303c2b857f --- /dev/null +++ b/tests/testsuite/cargo_remove/target_dev/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["--dev", "--target", "x86_64-unknown-linux-gnu", "ncurses"]) + .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_remove/target_dev/out/Cargo.toml b/tests/testsuite/cargo_remove/target_dev/out/Cargo.toml new file mode 100644 index 00000000000..a477b3d55cd --- /dev/null +++ b/tests/testsuite/cargo_remove/target_dev/out/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "cargo-remove-target-test-fixture" +version = "0.1.0" + +[[bin]] +name = "main" +path = "src/main.rs" + +[target.x86_64-unknown-freebsd.build-dependencies] +semver = "0.1.0" + +[target.x86_64-unknown-linux-gnu.build-dependencies] +semver = "0.1.0" + +[dependencies] +docopt = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[target.x86_64-unknown-linux-gnu.dependencies] +dbus = "0.6.2" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/target_dev/stderr.log b/tests/testsuite/cargo_remove/target_dev/stderr.log new file mode 100644 index 00000000000..68553a3bdce --- /dev/null +++ b/tests/testsuite/cargo_remove/target_dev/stderr.log @@ -0,0 +1,2 @@ + Removing ncurses from dev-dependencies for target `x86_64-unknown-linux-gnu` + Updating `dummy-registry` index diff --git a/tests/testsuite/cargo_remove/target_dev/stdout.log b/tests/testsuite/cargo_remove/target_dev/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/update_lock_file/in/Cargo.lock b/tests/testsuite/cargo_remove/update_lock_file/in/Cargo.lock new file mode 100644 index 00000000000..06c2052d526 --- /dev/null +++ b/tests/testsuite/cargo_remove/update_lock_file/in/Cargo.lock @@ -0,0 +1,58 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cargo-remove-test-fixture" +version = "0.1.0" +dependencies = [ + "clippy", + "docopt", + "regex", + "rustc-serialize", + "semver", + "serde", + "toml", +] + +[[package]] +name = "clippy" +version = "0.4.1+my-package" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47ced0eda54e9ddc6063f0e1d0164493cd16c84c6b6a0329a536967c44e205f7" + +[[package]] +name = "docopt" +version = "0.6.2+my-package" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b600540c4fafb27bf6e6961f0f1e6f547c9d6126ce581ab3a92f878c8e2c9a2c" + +[[package]] +name = "regex" +version = "0.1.1+my-package" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84949cb53285a6c481d0133065a7b669871acfd9e20f273f4ce1283c309775d5" + +[[package]] +name = "rustc-serialize" +version = "0.4.1+my-package" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31162e7d23a085553c42dee375787b451a481275473f7779c4a63bcc267a24fd" + +[[package]] +name = "semver" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3031434e07edc922bf1b8262f075fac1522694f17b1ee7ad314c4cabd5d2723f" + +[[package]] +name = "serde" +version = "1.0.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75d9264696ebbf5315a6b068e9910c4df9274365afac2d88abf66525df660218" + +[[package]] +name = "toml" +version = "0.1.1+my-package" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0f6c7804525ce0a968ef270e55a516cf4bdcf1fea0b09d130e0aa34a66745b3" diff --git a/tests/testsuite/cargo_remove/update_lock_file/in/Cargo.toml b/tests/testsuite/cargo_remove/update_lock_file/in/Cargo.toml new file mode 100644 index 00000000000..340f06cda79 --- /dev/null +++ b/tests/testsuite/cargo_remove/update_lock_file/in/Cargo.toml @@ -0,0 +1,24 @@ +[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 = "0.6" +rustc-serialize = "0.4" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/update_lock_file/in/src/main.rs b/tests/testsuite/cargo_remove/update_lock_file/in/src/main.rs new file mode 100644 index 00000000000..f328e4d9d04 --- /dev/null +++ b/tests/testsuite/cargo_remove/update_lock_file/in/src/main.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/testsuite/cargo_remove/update_lock_file/mod.rs b/tests/testsuite/cargo_remove/update_lock_file/mod.rs new file mode 100644 index 00000000000..be5bc87f581 --- /dev/null +++ b/tests/testsuite/cargo_remove/update_lock_file/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +use crate::cargo_remove::init_registry; + +#[cargo_test] +fn case() { + 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("remove") + .args(["rustc-serialize"]) + .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_remove/update_lock_file/out/Cargo.lock b/tests/testsuite/cargo_remove/update_lock_file/out/Cargo.lock new file mode 100644 index 00000000000..bd8c90f4687 --- /dev/null +++ b/tests/testsuite/cargo_remove/update_lock_file/out/Cargo.lock @@ -0,0 +1,51 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cargo-remove-test-fixture" +version = "0.1.0" +dependencies = [ + "clippy", + "docopt", + "regex", + "semver", + "serde", + "toml", +] + +[[package]] +name = "clippy" +version = "0.4.1+my-package" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47ced0eda54e9ddc6063f0e1d0164493cd16c84c6b6a0329a536967c44e205f7" + +[[package]] +name = "docopt" +version = "0.6.2+my-package" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b600540c4fafb27bf6e6961f0f1e6f547c9d6126ce581ab3a92f878c8e2c9a2c" + +[[package]] +name = "regex" +version = "0.1.1+my-package" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84949cb53285a6c481d0133065a7b669871acfd9e20f273f4ce1283c309775d5" + +[[package]] +name = "semver" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3031434e07edc922bf1b8262f075fac1522694f17b1ee7ad314c4cabd5d2723f" + +[[package]] +name = "serde" +version = "1.0.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75d9264696ebbf5315a6b068e9910c4df9274365afac2d88abf66525df660218" + +[[package]] +name = "toml" +version = "0.1.1+my-package" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0f6c7804525ce0a968ef270e55a516cf4bdcf1fea0b09d130e0aa34a66745b3" diff --git a/tests/testsuite/cargo_remove/update_lock_file/out/Cargo.toml b/tests/testsuite/cargo_remove/update_lock_file/out/Cargo.toml new file mode 100644 index 00000000000..5e7d7f0a06e --- /dev/null +++ b/tests/testsuite/cargo_remove/update_lock_file/out/Cargo.toml @@ -0,0 +1,23 @@ +[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 = "0.6" +semver = "0.1" +toml = "0.1" +clippy = "0.4" + +[dev-dependencies] +regex = "0.1.1" +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/update_lock_file/out/src/main.rs b/tests/testsuite/cargo_remove/update_lock_file/out/src/main.rs new file mode 100644 index 00000000000..f328e4d9d04 --- /dev/null +++ b/tests/testsuite/cargo_remove/update_lock_file/out/src/main.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/testsuite/cargo_remove/update_lock_file/stderr.log b/tests/testsuite/cargo_remove/update_lock_file/stderr.log new file mode 100644 index 00000000000..164f8f4b979 --- /dev/null +++ b/tests/testsuite/cargo_remove/update_lock_file/stderr.log @@ -0,0 +1,2 @@ + Removing rustc-serialize from dependencies + Updating `dummy-registry` index diff --git a/tests/testsuite/cargo_remove/update_lock_file/stdout.log b/tests/testsuite/cargo_remove/update_lock_file/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index cd817d744d3..465494cb742 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -25,6 +25,7 @@ mod cargo_command; mod cargo_config; mod cargo_env_config; mod cargo_features; +mod cargo_remove; mod cargo_targets; mod cfg; mod check;