diff --git a/Cargo.toml b/Cargo.toml index d1143aa15ae..e5b9144506a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ glob = "0.3.0" hex = "0.4" home = "0.5" humantime = "2.0.0" +indexmap = "1" ignore = "0.4.7" lazy_static = "1.2.0" jobserver = "0.1.24" @@ -45,7 +46,7 @@ libgit2-sys = "0.13.2" memchr = "2.1.3" opener = "0.5" os_info = "3.0.7" -pathdiff = "0.2.1" +pathdiff = "0.2" percent-encoding = "2.0" rustfix = "0.6.0" semver = { version = "1.0.3", features = ["serde"] } @@ -99,6 +100,7 @@ features = [ [dev-dependencies] cargo-test-macro = { path = "crates/cargo-test-macro" } cargo-test-support = { path = "crates/cargo-test-support" } +snapbox = { version = "0.2.8", features = ["diff", "path"] } [build-dependencies] flate2 = { version = "1.0.3", default-features = false, features = ["zlib"] } diff --git a/src/bin/cargo/commands/add.rs b/src/bin/cargo/commands/add.rs new file mode 100644 index 00000000000..8ed6ea1fa29 --- /dev/null +++ b/src/bin/cargo/commands/add.rs @@ -0,0 +1,360 @@ +use indexmap::IndexMap; +use indexmap::IndexSet; + +use cargo::core::dependency::DepKind; +use cargo::core::FeatureValue; +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::util::command_prelude::*; +use cargo::util::interning::InternedString; +use cargo::CargoResult; + +pub fn cli() -> clap::Command<'static> { + clap::Command::new("add") + .setting(clap::AppSettings::DeriveDisplayOrder) + .about("Add dependencies to a Cargo.toml manifest file") + .override_usage( + "\ + cargo add [OPTIONS] [@] ... + cargo add [OPTIONS] --path ... + cargo add [OPTIONS] --git ..." + ) + .after_help("Run `cargo help add` for more detailed information.\n") + .group(clap::ArgGroup::new("selected").multiple(true).required(true)) + .args([ + clap::Arg::new("crates") + .takes_value(true) + .value_name("DEP_ID") + .multiple_occurrences(true) + .help("Reference to a package to add as a dependency") + .long_help( + "Reference to a package to add as a dependency + +You can reference a package by: +- ``, like `cargo add serde` (latest version will be used) +- `@`, like `cargo add serde@1` or `cargo add serde@=1.0.38`" + ) + .group("selected"), + clap::Arg::new("no-default-features") + .long("no-default-features") + .help("Disable the default features"), + clap::Arg::new("default-features") + .long("default-features") + .help("Re-enable the default features") + .overrides_with("no-default-features"), + clap::Arg::new("features") + .short('F') + .long("features") + .takes_value(true) + .value_name("FEATURES") + .multiple_occurrences(true) + .help("Space or comma separated list of features to activate"), + clap::Arg::new("optional") + .long("optional") + .help("Mark the dependency as optional") + .long_help("Mark the dependency as optional + +The package name will be exposed as feature of your crate.") + .conflicts_with("dev"), + clap::Arg::new("no-optional") + .long("no-optional") + .help("Mark the dependency as required") + .long_help("Mark the dependency as required + +The package will be removed from your features.") + .conflicts_with("dev") + .overrides_with("optional"), + clap::Arg::new("rename") + .long("rename") + .takes_value(true) + .value_name("NAME") + .help("Rename the dependency") + .long_help("Rename the dependency + +Example uses: +- Depending on multiple versions of a crate +- Depend on crates with the same name from different registries"), + ]) + .arg_manifest_path() + .args([ + clap::Arg::new("package") + .short('p') + .long("package") + .takes_value(true) + .value_name("SPEC") + .help("Package to modify"), + clap::Arg::new("offline") + .long("offline") + .help("Run without accessing the network") + ]) + .arg_quiet() + .arg_dry_run("Don't actually write the manifest") + .next_help_heading("SOURCE") + .args([ + clap::Arg::new("path") + .long("path") + .takes_value(true) + .value_name("PATH") + .help("Filesystem path to local crate to add") + .group("selected") + .conflicts_with("git"), + clap::Arg::new("git") + .long("git") + .takes_value(true) + .value_name("URI") + .help("Git repository location") + .long_help("Git repository location + +Without any other information, cargo will use latest commit on the main branch.") + .group("selected"), + clap::Arg::new("branch") + .long("branch") + .takes_value(true) + .value_name("BRANCH") + .help("Git branch to download the crate from") + .requires("git") + .group("git-ref"), + clap::Arg::new("tag") + .long("tag") + .takes_value(true) + .value_name("TAG") + .help("Git tag to download the crate from") + .requires("git") + .group("git-ref"), + clap::Arg::new("rev") + .long("rev") + .takes_value(true) + .value_name("REV") + .help("Git reference to download the crate from") + .long_help("Git reference to download the crate from + +This is the catch all, handling hashes to named references in remote repositories.") + .requires("git") + .group("git-ref"), + clap::Arg::new("registry") + .long("registry") + .takes_value(true) + .value_name("NAME") + .help("Package registry for this dependency"), + ]) + .next_help_heading("SECTION") + .args([ + clap::Arg::new("dev") + .long("dev") + .help("Add as development dependency") + .long_help("Add as development dependency + +Dev-dependencies are not used when compiling a package for building, but are used for compiling tests, examples, and benchmarks. + +These dependencies are not propagated to other packages which depend on this package.") + .group("section"), + clap::Arg::new("build") + .long("build") + .help("Add as build dependency") + .long_help("Add as build dependency + +Build-dependencies are the only dependencies available for use by build scripts (`build.rs` files).") + .group("section"), + clap::Arg::new("target") + .long("target") + .takes_value(true) + .value_name("TARGET") + .forbid_empty_values(true) + .help("Add as dependency to the given target platform") + ]) +} + +pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { + let dry_run = args.is_present("dry-run"); + let section = parse_section(args); + + let ws = args.workspace(config)?; + let packages = args.packages_from_flags()?; + let packages = packages.get_packages(&ws)?; + 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 = parse_dependencies(config, args)?; + + let options = AddOptions { + config, + spec, + dependencies, + section, + dry_run, + }; + add(&ws, &options)?; + + Ok(()) +} + +fn parse_dependencies(config: &Config, matches: &ArgMatches) -> CargoResult> { + let path = matches.value_of("path"); + let git = matches.value_of("git"); + let branch = matches.value_of("branch"); + let rev = matches.value_of("rev"); + let tag = matches.value_of("tag"); + let rename = matches.value_of("rename"); + let registry = matches.registry(config)?; + let default_features = default_features(matches); + let optional = optional(matches); + + let mut crates = matches + .values_of("crates") + .into_iter() + .flatten() + .map(|c| (Some(String::from(c)), None)) + .collect::>(); + let mut infer_crate_name = false; + if crates.is_empty() { + if path.is_some() || git.is_some() { + crates.insert(None, None); + infer_crate_name = true; + } else { + unreachable!("clap should ensure we have some source selected"); + } + } + for feature in matches + .values_of("features") + .into_iter() + .flatten() + .flat_map(parse_feature) + { + let parsed_value = FeatureValue::new(InternedString::new(feature)); + match parsed_value { + FeatureValue::Feature(_) => { + if 1 < crates.len() { + let candidates = crates + .keys() + .map(|c| { + format!( + "`{}/{}`", + c.as_deref().expect("only none when there is 1"), + feature + ) + }) + .collect::>(); + anyhow::bail!("feature `{feature}` must be qualified by the dependency its being activated for, like {}", candidates.join(", ")); + } + crates + .first_mut() + .expect("always at least one crate") + .1 + .get_or_insert_with(IndexSet::new) + .insert(feature.to_owned()); + } + FeatureValue::Dep { .. } => { + anyhow::bail!("feature `{feature}` is not allowed to use explicit `dep:` syntax",) + } + FeatureValue::DepFeature { + dep_name, + dep_feature, + .. + } => { + if infer_crate_name { + anyhow::bail!("`{feature}` is unsupported when inferring the crate name, use `{dep_feature}`"); + } + if dep_feature.contains('/') { + anyhow::bail!("multiple slashes in feature `{feature}` is not allowed"); + } + crates.get_mut(&Some(dep_name.as_str().to_owned())).ok_or_else(|| { + anyhow::format_err!("feature `{dep_feature}` activated for crate `{dep_name}` but the crate wasn't specified") + })? + .get_or_insert_with(IndexSet::new) + .insert(dep_feature.as_str().to_owned()); + } + } + } + + let mut deps: Vec = Vec::new(); + for (crate_spec, features) in crates { + let dep = DepOp { + crate_spec, + rename: rename.map(String::from), + features, + default_features, + optional, + registry: registry.clone(), + path: path.map(String::from), + git: git.map(String::from), + branch: branch.map(String::from), + rev: rev.map(String::from), + tag: tag.map(String::from), + }; + deps.push(dep); + } + + if deps.len() > 1 && rename.is_some() { + anyhow::bail!("cannot specify multiple crates with `--rename`"); + } + + Ok(deps) +} + +fn default_features(matches: &ArgMatches) -> Option { + resolve_bool_arg( + matches.is_present("default-features"), + matches.is_present("no-default-features"), + ) +} + +fn optional(matches: &ArgMatches) -> Option { + resolve_bool_arg( + matches.is_present("optional"), + matches.is_present("no-optional"), + ) +} + +fn resolve_bool_arg(yes: bool, no: bool) -> Option { + match (yes, no) { + (true, false) => Some(true), + (false, true) => Some(false), + (false, false) => None, + (_, _) => unreachable!("clap should make this impossible"), + } +} + +fn parse_section(matches: &ArgMatches) -> DepTable { + let kind = if matches.is_present("dev") { + DepKind::Development + } else if matches.is_present("build") { + DepKind::Build + } else { + DepKind::Normal + }; + + let mut table = DepTable::new().set_kind(kind); + + if let Some(target) = matches.value_of("target") { + assert!(!target.is_empty(), "Target specification may not be empty"); + table = table.set_target(target); + } + + table +} + +/// Split feature flag list +fn parse_feature(feature: &str) -> impl Iterator { + // Not re-using `CliFeatures` because it uses a BTreeSet and loses user's ordering + feature + .split_whitespace() + .flat_map(|s| s.split(',')) + .filter(|s| !s.is_empty()) +} diff --git a/src/bin/cargo/commands/mod.rs b/src/bin/cargo/commands/mod.rs index 7d77388f5c2..92ee7d75e45 100644 --- a/src/bin/cargo/commands/mod.rs +++ b/src/bin/cargo/commands/mod.rs @@ -2,6 +2,7 @@ use crate::command_prelude::*; pub fn builtin() -> Vec { vec![ + add::cli(), bench::cli(), build::cli(), check::cli(), @@ -42,6 +43,7 @@ pub fn builtin() -> Vec { pub fn builtin_exec(cmd: &str) -> Option CliResult> { let f = match cmd { + "add" => add::exec, "bench" => bench::exec, "build" => build::exec, "check" => check::exec, @@ -82,6 +84,7 @@ pub fn builtin_exec(cmd: &str) -> Option CliResu Some(f) } +pub mod add; pub mod bench; pub mod build; pub mod check; diff --git a/src/cargo/core/shell.rs b/src/cargo/core/shell.rs index 5da210d9350..d03ef8e8bd0 100644 --- a/src/cargo/core/shell.rs +++ b/src/cargo/core/shell.rs @@ -344,6 +344,17 @@ impl Shell { self.output.write_stdout(fragment, color) } + /// Write a styled fragment + /// + /// Caller is responsible for deciding whether [`Shell::verbosity`] is affects output. + pub fn write_stderr( + &mut self, + fragment: impl fmt::Display, + color: &ColorSpec, + ) -> CargoResult<()> { + self.output.write_stderr(fragment, color) + } + /// Prints a message to stderr and translates ANSI escape code into console colors. pub fn print_ansi_stderr(&mut self, message: &[u8]) -> CargoResult<()> { if self.needs_clear { @@ -450,6 +461,22 @@ impl ShellOut { Ok(()) } + /// Write a styled fragment + fn write_stderr(&mut self, fragment: impl fmt::Display, color: &ColorSpec) -> CargoResult<()> { + match *self { + ShellOut::Stream { ref mut stderr, .. } => { + stderr.reset()?; + stderr.set_color(&color)?; + write!(stderr, "{}", fragment)?; + stderr.reset()?; + } + ShellOut::Write(ref mut w) => { + write!(w, "{}", fragment)?; + } + } + Ok(()) + } + /// Gets stdout as a `io::Write`. fn stdout(&mut self) -> &mut dyn Write { match *self { diff --git a/src/cargo/ops/cargo_add/crate_spec.rs b/src/cargo/ops/cargo_add/crate_spec.rs new file mode 100644 index 00000000000..33b4957f758 --- /dev/null +++ b/src/cargo/ops/cargo_add/crate_spec.rs @@ -0,0 +1,63 @@ +//! Crate name parsing. + +use anyhow::Context as _; + +use super::Dependency; +use super::RegistrySource; +use crate::util::validate_package_name; +use crate::CargoResult; + +/// User-specified crate +/// +/// This can be a +/// - Name (e.g. `docopt`) +/// - Name and a version req (e.g. `docopt@^0.8`) +/// - Path +#[derive(Debug)] +pub struct CrateSpec { + /// Crate name + name: String, + /// Optional version requirement + version_req: Option, +} + +impl CrateSpec { + /// Convert a string to a `Crate` + pub fn resolve(pkg_id: &str) -> CargoResult { + let (name, version) = pkg_id + .split_once('@') + .map(|(n, v)| (n, Some(v))) + .unwrap_or((pkg_id, None)); + + validate_package_name(name, "dependency name", "")?; + + if let Some(version) = version { + semver::VersionReq::parse(version) + .with_context(|| format!("invalid version requirement `{version}`"))?; + } + + let id = Self { + name: name.to_owned(), + version_req: version.map(|s| s.to_owned()), + }; + + Ok(id) + } + + /// Generate a dependency entry for this crate specifier + pub fn to_dependency(&self) -> CargoResult { + let mut dep = Dependency::new(self.name()); + if let Some(version_req) = self.version_req() { + dep = dep.set_source(RegistrySource::new(version_req)); + } + Ok(dep) + } + + pub fn name(&self) -> &str { + &self.name + } + + pub fn version_req(&self) -> Option<&str> { + self.version_req.as_deref() + } +} diff --git a/src/cargo/ops/cargo_add/dependency.rs b/src/cargo/ops/cargo_add/dependency.rs new file mode 100644 index 00000000000..23b3373fc2d --- /dev/null +++ b/src/cargo/ops/cargo_add/dependency.rs @@ -0,0 +1,1038 @@ +use std::collections::BTreeMap; +use std::path::{Path, PathBuf}; + +use indexmap::IndexSet; + +use super::manifest::str_or_1_len_table; +use crate::core::FeatureMap; +use crate::core::FeatureValue; +use crate::core::GitReference; +use crate::core::SourceId; +use crate::core::Summary; +use crate::CargoResult; +use crate::Config; + +/// A dependency handled by Cargo +/// +/// `None` means the field will be blank in TOML +#[derive(Debug, PartialEq, Eq, Clone)] +#[non_exhaustive] +pub struct Dependency { + /// The name of the dependency (as it is set in its `Cargo.toml` and known to crates.io) + pub name: String, + /// Whether the dependency is opted-in with a feature flag + pub optional: Option, + + /// List of features to add (or None to keep features unchanged). + pub features: Option>, + /// Whether default features are enabled + pub default_features: Option, + + /// Where the dependency comes from + pub source: Option, + /// Non-default registry + pub registry: Option, + + /// If the dependency is renamed, this is the new name for the dependency + /// as a string. None if it is not renamed. + pub rename: Option, + + /// Features that are exposed by the dependency + pub available_features: BTreeMap>, +} + +impl Dependency { + /// Create a new dependency with a name + pub fn new(name: &str) -> Self { + Self { + name: name.into(), + optional: None, + features: None, + default_features: None, + source: None, + registry: None, + rename: None, + available_features: Default::default(), + } + } + + /// Set dependency to a given version + pub fn set_source(mut self, source: impl Into) -> Self { + self.source = Some(source.into()); + self + } + + /// Remove the existing version requirement + pub fn clear_version(mut self) -> Self { + match &mut self.source { + Some(Source::Registry(_)) => { + self.source = None; + } + Some(Source::Path(path)) => { + path.version = None; + } + Some(Source::Git(git)) => { + git.version = None; + } + None => {} + } + self + } + + /// Set the available features of the dependency to a given vec + pub fn set_available_features( + mut self, + available_features: BTreeMap>, + ) -> Self { + self.available_features = available_features; + self + } + + /// Populate from cargo + pub fn set_available_features_from_cargo( + mut self, + available_features: &FeatureMap, + ) -> Dependency { + self.available_features = available_features + .iter() + .map(|(k, v)| { + ( + k.as_str().to_owned(), + v.iter() + .filter_map(|v| match v { + FeatureValue::Feature(f) => Some(f.as_str().to_owned()), + FeatureValue::Dep { .. } | FeatureValue::DepFeature { .. } => None, + }) + .collect::>(), + ) + }) + .collect(); + self + } + + /// Set whether the dependency is optional + #[allow(dead_code)] + pub fn set_optional(mut self, opt: bool) -> Self { + self.optional = Some(opt); + self + } + + /// Set features as an array of string (does some basic parsing) + #[allow(dead_code)] + pub fn set_features(mut self, features: IndexSet) -> Self { + self.features = Some(features); + self + } + /// Set features as an array of string (does some basic parsing) + pub fn extend_features(mut self, features: impl IntoIterator) -> Self { + self.features + .get_or_insert_with(Default::default) + .extend(features); + self + } + + /// Set the value of default-features for the dependency + #[allow(dead_code)] + pub fn set_default_features(mut self, default_features: bool) -> Self { + self.default_features = Some(default_features); + self + } + + /// Set the alias for the dependency + pub fn set_rename(mut self, rename: &str) -> Self { + self.rename = Some(rename.into()); + self + } + + /// Set the value of registry for the dependency + pub fn set_registry(mut self, registry: impl Into) -> Self { + self.registry = Some(registry.into()); + self + } + + /// Get the dependency source + pub fn source(&self) -> Option<&Source> { + self.source.as_ref() + } + + /// Get version of dependency + pub fn version(&self) -> Option<&str> { + match self.source()? { + Source::Registry(src) => Some(src.version.as_str()), + Source::Path(src) => src.version.as_deref(), + Source::Git(src) => src.version.as_deref(), + } + } + + /// Get registry of the dependency + pub fn registry(&self) -> Option<&str> { + self.registry.as_deref() + } + + /// Get the alias for the dependency (if any) + pub fn rename(&self) -> Option<&str> { + self.rename.as_deref() + } + + /// Whether default features are activated + pub fn default_features(&self) -> Option { + self.default_features + } + + /// Get whether the dep is optional + pub fn optional(&self) -> Option { + self.optional + } + + /// Get the SourceID for this dependency + pub fn source_id(&self, config: &Config) -> CargoResult { + match &self.source.as_ref() { + Some(Source::Registry(_)) | None => { + if let Some(r) = self.registry() { + let source_id = SourceId::alt_registry(config, r)?; + Ok(source_id) + } else { + let source_id = SourceId::crates_io(config)?; + Ok(source_id) + } + } + Some(Source::Path(source)) => source.source_id(), + Some(Source::Git(source)) => source.source_id(), + } + } + + /// Query to find this dependency + pub fn query(&self, config: &Config) -> CargoResult { + let source_id = self.source_id(config)?; + crate::core::dependency::Dependency::parse(self.name.as_str(), self.version(), source_id) + } +} + +impl Dependency { + /// Create a dependency from a TOML table entry + pub fn from_toml(crate_root: &Path, key: &str, item: &toml_edit::Item) -> CargoResult { + if let Some(version) = item.as_str() { + let dep = Self::new(key).set_source(RegistrySource::new(version)); + Ok(dep) + } else if let Some(table) = item.as_table_like() { + let (name, rename) = if let Some(value) = table.get("package") { + ( + value + .as_str() + .ok_or_else(|| invalid_type(key, "package", value.type_name(), "string"))? + .to_owned(), + Some(key.to_owned()), + ) + } else { + (key.to_owned(), None) + }; + + let source: Source = + if let Some(git) = table.get("git") { + let mut src = GitSource::new( + git.as_str() + .ok_or_else(|| invalid_type(key, "git", git.type_name(), "string"))?, + ); + if let Some(value) = table.get("branch") { + src = src.set_branch(value.as_str().ok_or_else(|| { + invalid_type(key, "branch", value.type_name(), "string") + })?); + } + if let Some(value) = table.get("tag") { + src = src.set_tag(value.as_str().ok_or_else(|| { + invalid_type(key, "tag", value.type_name(), "string") + })?); + } + if let Some(value) = table.get("rev") { + src = src.set_rev(value.as_str().ok_or_else(|| { + invalid_type(key, "rev", value.type_name(), "string") + })?); + } + if let Some(value) = table.get("version") { + src = src.set_version(value.as_str().ok_or_else(|| { + invalid_type(key, "version", value.type_name(), "string") + })?); + } + src.into() + } else if let Some(path) = table.get("path") { + let path = crate_root + .join(path.as_str().ok_or_else(|| { + invalid_type(key, "path", path.type_name(), "string") + })?); + let mut src = PathSource::new(path); + if let Some(value) = table.get("version") { + src = src.set_version(value.as_str().ok_or_else(|| { + invalid_type(key, "version", value.type_name(), "string") + })?); + } + src.into() + } else if let Some(version) = table.get("version") { + let src = RegistrySource::new(version.as_str().ok_or_else(|| { + invalid_type(key, "version", version.type_name(), "string") + })?); + src.into() + } else { + anyhow::bail!("Unrecognized dependency source for `{key}`"); + }; + let registry = if let Some(value) = table.get("registry") { + Some( + value + .as_str() + .ok_or_else(|| invalid_type(key, "registry", value.type_name(), "string"))? + .to_owned(), + ) + } else { + None + }; + + let default_features = table.get("default-features").and_then(|v| v.as_bool()); + if table.contains_key("default_features") { + anyhow::bail!("Use of `default_features` in `{key}` is unsupported, please switch to `default-features`"); + } + + let features = if let Some(value) = table.get("features") { + Some( + value + .as_array() + .ok_or_else(|| invalid_type(key, "features", value.type_name(), "array"))? + .iter() + .map(|v| { + v.as_str().map(|s| s.to_owned()).ok_or_else(|| { + invalid_type(key, "features", v.type_name(), "string") + }) + }) + .collect::>>()?, + ) + } else { + None + }; + + let available_features = BTreeMap::default(); + + let optional = table.get("optional").and_then(|v| v.as_bool()); + + let dep = Self { + name, + rename, + source: Some(source), + registry, + default_features, + features, + available_features, + optional, + }; + Ok(dep) + } else { + anyhow::bail!("Unrecognized` dependency entry format for `{key}"); + } + } + + /// Get the dependency name as defined in the manifest, + /// that is, either the alias (rename field if Some), + /// or the official package name (name field). + pub fn toml_key(&self) -> &str { + self.rename().unwrap_or(&self.name) + } + + /// Convert dependency to TOML + /// + /// Returns a tuple with the dependency's name and either the version as a `String` + /// or the path/git repository as an `InlineTable`. + /// (If the dependency is set as `optional` or `default-features` is set to `false`, + /// an `InlineTable` is returned in any case.) + /// + /// # Panic + /// + /// Panics if the path is relative + pub fn to_toml(&self, crate_root: &Path) -> toml_edit::Item { + assert!( + crate_root.is_absolute(), + "Absolute path needed, got: {}", + crate_root.display() + ); + let table: toml_edit::Item = match ( + self.optional.unwrap_or(false), + self.features.as_ref(), + self.default_features.unwrap_or(true), + self.source.as_ref(), + self.registry.as_ref(), + self.rename.as_ref(), + ) { + // Extra short when version flag only + ( + false, + None, + true, + Some(Source::Registry(RegistrySource { version: v })), + None, + None, + ) => toml_edit::value(v), + // Other cases are represented as an inline table + (_, _, _, _, _, _) => { + let mut table = toml_edit::InlineTable::default(); + + match &self.source { + Some(Source::Registry(src)) => { + table.insert("version", src.version.as_str().into()); + } + Some(Source::Path(src)) => { + let relpath = path_field(crate_root, &src.path); + if let Some(r) = src.version.as_deref() { + table.insert("version", r.into()); + } + table.insert("path", relpath.into()); + } + Some(Source::Git(src)) => { + table.insert("git", src.git.as_str().into()); + if let Some(branch) = src.branch.as_deref() { + table.insert("branch", branch.into()); + } + if let Some(tag) = src.tag.as_deref() { + table.insert("tag", tag.into()); + } + if let Some(rev) = src.rev.as_deref() { + table.insert("rev", rev.into()); + } + if let Some(r) = src.version.as_deref() { + table.insert("version", r.into()); + } + } + None => {} + } + if table.contains_key("version") { + if let Some(r) = self.registry.as_deref() { + table.insert("registry", r.into()); + } + } + + if self.rename.is_some() { + table.insert("package", self.name.as_str().into()); + } + if let Some(v) = self.default_features { + table.insert("default-features", v.into()); + } + if let Some(features) = self.features.as_ref() { + let features: toml_edit::Value = features.iter().cloned().collect(); + table.insert("features", features); + } + if let Some(v) = self.optional { + table.insert("optional", v.into()); + } + + toml_edit::value(toml_edit::Value::InlineTable(table)) + } + }; + + table + } + + /// Modify existing entry to match this dependency + pub fn update_toml(&self, crate_root: &Path, item: &mut toml_edit::Item) { + if str_or_1_len_table(item) { + // Nothing to preserve + *item = self.to_toml(crate_root); + } else if let Some(table) = item.as_table_like_mut() { + match &self.source { + Some(Source::Registry(src)) => { + table.insert("version", toml_edit::value(src.version.as_str())); + + for key in ["path", "git", "branch", "tag", "rev"] { + table.remove(key); + } + } + Some(Source::Path(src)) => { + let relpath = path_field(crate_root, &src.path); + table.insert("path", toml_edit::value(relpath)); + if let Some(r) = src.version.as_deref() { + table.insert("version", toml_edit::value(r)); + } else { + table.remove("version"); + } + + for key in ["git", "branch", "tag", "rev"] { + table.remove(key); + } + } + Some(Source::Git(src)) => { + table.insert("git", toml_edit::value(src.git.as_str())); + if let Some(branch) = src.branch.as_deref() { + table.insert("branch", toml_edit::value(branch)); + } else { + table.remove("branch"); + } + if let Some(tag) = src.tag.as_deref() { + table.insert("tag", toml_edit::value(tag)); + } else { + table.remove("tag"); + } + if let Some(rev) = src.rev.as_deref() { + table.insert("rev", toml_edit::value(rev)); + } else { + table.remove("rev"); + } + if let Some(r) = src.version.as_deref() { + table.insert("version", toml_edit::value(r)); + } else { + table.remove("version"); + } + + for key in ["path"] { + table.remove(key); + } + } + None => {} + } + if table.contains_key("version") { + if let Some(r) = self.registry.as_deref() { + table.insert("registry", toml_edit::value(r)); + } else { + table.remove("registry"); + } + } else { + table.remove("registry"); + } + + if self.rename.is_some() { + table.insert("package", toml_edit::value(self.name.as_str())); + } + match self.default_features { + Some(v) => { + table.insert("default-features", toml_edit::value(v)); + } + None => { + table.remove("default-features"); + } + } + if let Some(new_features) = self.features.as_ref() { + let mut features = table + .get("features") + .and_then(|i| i.as_value()) + .and_then(|v| v.as_array()) + .and_then(|a| { + a.iter() + .map(|v| v.as_str()) + .collect::>>() + }) + .unwrap_or_default(); + features.extend(new_features.iter().map(|s| s.as_str())); + let features = toml_edit::value(features.into_iter().collect::()); + table.insert("features", features); + } else { + table.remove("features"); + } + match self.optional { + Some(v) => { + table.insert("optional", toml_edit::value(v)); + } + None => { + table.remove("optional"); + } + } + + table.fmt(); + } else { + unreachable!("Invalid dependency type: {}", item.type_name()); + } + } +} + +fn invalid_type(dep: &str, key: &str, actual: &str, expected: &str) -> anyhow::Error { + anyhow::format_err!("Found {actual} for {key} when {expected} was expected for {dep}") +} + +impl std::fmt::Display for Dependency { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + if let Some(source) = self.source() { + write!(f, "{}@{}", self.name, source) + } else { + self.toml_key().fmt(f) + } + } +} + +impl<'s> From<&'s Summary> for Dependency { + fn from(other: &'s Summary) -> Self { + let source: Source = if let Some(path) = other.source_id().local_path() { + PathSource::new(path) + .set_version(other.version().to_string()) + .into() + } else if let Some(git_ref) = other.source_id().git_reference() { + let mut src = GitSource::new(other.source_id().url().to_string()) + .set_version(other.version().to_string()); + match git_ref { + GitReference::Branch(branch) => src = src.set_branch(branch), + GitReference::Tag(tag) => src = src.set_tag(tag), + GitReference::Rev(rev) => src = src.set_rev(rev), + GitReference::DefaultBranch => {} + } + src.into() + } else { + RegistrySource::new(other.version().to_string()).into() + }; + Dependency::new(other.name().as_str()) + .set_source(source) + .set_available_features_from_cargo(other.features()) + } +} + +impl From for Dependency { + fn from(other: Summary) -> Self { + (&other).into() + } +} + +fn path_field(crate_root: &Path, abs_path: &Path) -> String { + let relpath = pathdiff::diff_paths(abs_path, crate_root).expect("both paths are absolute"); + let relpath = relpath.to_str().unwrap().replace('\\', "/"); + relpath +} + +/// Primary location of a dependency +#[derive(Debug, Hash, PartialEq, Eq, Clone)] +pub enum Source { + /// Dependency from a registry + Registry(RegistrySource), + /// Dependency from a local path + Path(PathSource), + /// Dependency from a git repo + Git(GitSource), +} + +impl Source { + /// Access the registry source, if present + pub fn as_registry(&self) -> Option<&RegistrySource> { + match self { + Self::Registry(src) => Some(src), + _ => None, + } + } + + /// Access the path source, if present + #[allow(dead_code)] + pub fn as_path(&self) -> Option<&PathSource> { + match self { + Self::Path(src) => Some(src), + _ => None, + } + } + + /// Access the git source, if present + #[allow(dead_code)] + pub fn as_git(&self) -> Option<&GitSource> { + match self { + Self::Git(src) => Some(src), + _ => None, + } + } +} + +impl std::fmt::Display for Source { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Registry(src) => src.fmt(f), + Self::Path(src) => src.fmt(f), + Self::Git(src) => src.fmt(f), + } + } +} + +impl<'s> From<&'s Source> for Source { + fn from(inner: &'s Source) -> Self { + inner.clone() + } +} + +impl From for Source { + fn from(inner: RegistrySource) -> Self { + Self::Registry(inner) + } +} + +impl From for Source { + fn from(inner: PathSource) -> Self { + Self::Path(inner) + } +} + +impl From for Source { + fn from(inner: GitSource) -> Self { + Self::Git(inner) + } +} + +/// Dependency from a registry +#[derive(Debug, Hash, PartialEq, Eq, Clone)] +#[non_exhaustive] +pub struct RegistrySource { + /// Version requirement + pub version: String, +} + +impl RegistrySource { + /// Specify dependency by version requirement + pub fn new(version: impl AsRef) -> Self { + // versions might have semver metadata appended which we do not want to + // store in the cargo toml files. This would cause a warning upon compilation + // ("version requirement […] includes semver metadata which will be ignored") + let version = version.as_ref().split('+').next().unwrap(); + Self { + version: version.to_owned(), + } + } +} + +impl std::fmt::Display for RegistrySource { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.version.fmt(f) + } +} + +/// Dependency from a local path +#[derive(Debug, Hash, PartialEq, Eq, Clone)] +#[non_exhaustive] +pub struct PathSource { + /// Local, absolute path + pub path: PathBuf, + /// Version requirement for when published + pub version: Option, +} + +impl PathSource { + /// Specify dependency from a path + pub fn new(path: impl Into) -> Self { + Self { + path: path.into(), + version: None, + } + } + + /// Set an optional version requirement + pub fn set_version(mut self, version: impl AsRef) -> Self { + // versions might have semver metadata appended which we do not want to + // store in the cargo toml files. This would cause a warning upon compilation + // ("version requirement […] includes semver metadata which will be ignored") + let version = version.as_ref().split('+').next().unwrap(); + self.version = Some(version.to_owned()); + self + } + + /// Get the SourceID for this dependency + pub fn source_id(&self) -> CargoResult { + SourceId::for_path(&self.path) + } +} + +impl std::fmt::Display for PathSource { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.path.display().fmt(f) + } +} + +/// Dependency from a git repo +#[derive(Debug, Hash, PartialEq, Eq, Clone)] +#[non_exhaustive] +pub struct GitSource { + /// Repo URL + pub git: String, + /// Select specific branch + pub branch: Option, + /// Select specific tag + pub tag: Option, + /// Select specific rev + pub rev: Option, + /// Version requirement for when published + pub version: Option, +} + +impl GitSource { + /// Specify dependency from a git repo + pub fn new(git: impl Into) -> Self { + Self { + git: git.into(), + branch: None, + tag: None, + rev: None, + version: None, + } + } + + /// Specify an optional branch + pub fn set_branch(mut self, branch: impl Into) -> Self { + self.branch = Some(branch.into()); + self.tag = None; + self.rev = None; + self + } + + /// Specify an optional tag + pub fn set_tag(mut self, tag: impl Into) -> Self { + self.branch = None; + self.tag = Some(tag.into()); + self.rev = None; + self + } + + /// Specify an optional rev + pub fn set_rev(mut self, rev: impl Into) -> Self { + self.branch = None; + self.tag = None; + self.rev = Some(rev.into()); + self + } + + /// Get the SourceID for this dependency + pub fn source_id(&self) -> CargoResult { + let git_url = self.git.parse::()?; + let git_ref = self.git_ref(); + SourceId::for_git(&git_url, git_ref) + } + + fn git_ref(&self) -> GitReference { + match ( + self.branch.as_deref(), + self.tag.as_deref(), + self.rev.as_deref(), + ) { + (Some(branch), _, _) => GitReference::Branch(branch.to_owned()), + (_, Some(tag), _) => GitReference::Tag(tag.to_owned()), + (_, _, Some(rev)) => GitReference::Rev(rev.to_owned()), + _ => GitReference::DefaultBranch, + } + } + + /// Set an optional version requirement + pub fn set_version(mut self, version: impl AsRef) -> Self { + // versions might have semver metadata appended which we do not want to + // store in the cargo toml files. This would cause a warning upon compilation + // ("version requirement […] includes semver metadata which will be ignored") + let version = version.as_ref().split('+').next().unwrap(); + self.version = Some(version.to_owned()); + self + } +} + +impl std::fmt::Display for GitSource { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let git_ref = self.git_ref(); + if let Some(pretty_ref) = git_ref.pretty_ref() { + write!(f, "{}?{}", self.git, pretty_ref) + } else { + write!(f, "{}", self.git) + } + } +} + +#[cfg(test)] +mod tests { + use std::path::Path; + + use cargo_util::paths; + + use super::*; + + #[test] + fn to_toml_simple_dep() { + let crate_root = + paths::normalize_path(&std::env::current_dir().unwrap().join(Path::new("/"))); + let dep = Dependency::new("dep").set_source(RegistrySource::new("1.0")); + let key = dep.toml_key(); + let item = dep.to_toml(&crate_root); + + assert_eq!(key, "dep".to_owned()); + + verify_roundtrip(&crate_root, key, &item); + } + + #[test] + fn to_toml_simple_dep_with_version() { + let crate_root = + paths::normalize_path(&std::env::current_dir().unwrap().join(Path::new("/"))); + let dep = Dependency::new("dep").set_source(RegistrySource::new("1.0")); + let key = dep.toml_key(); + let item = dep.to_toml(&crate_root); + + assert_eq!(key, "dep".to_owned()); + assert_eq!(item.as_str(), Some("1.0")); + + verify_roundtrip(&crate_root, key, &item); + } + + #[test] + fn to_toml_optional_dep() { + let crate_root = + paths::normalize_path(&std::env::current_dir().unwrap().join(Path::new("/"))); + let dep = Dependency::new("dep") + .set_source(RegistrySource::new("1.0")) + .set_optional(true); + let key = dep.toml_key(); + let item = dep.to_toml(&crate_root); + + assert_eq!(key, "dep".to_owned()); + assert!(item.is_inline_table()); + + let dep = item.as_inline_table().unwrap(); + assert_eq!(dep.get("optional").unwrap().as_bool(), Some(true)); + + verify_roundtrip(&crate_root, key, &item); + } + + #[test] + fn to_toml_dep_without_default_features() { + let crate_root = + paths::normalize_path(&std::env::current_dir().unwrap().join(Path::new("/"))); + let dep = Dependency::new("dep") + .set_source(RegistrySource::new("1.0")) + .set_default_features(false); + let key = dep.toml_key(); + let item = dep.to_toml(&crate_root); + + assert_eq!(key, "dep".to_owned()); + assert!(item.is_inline_table()); + + let dep = item.as_inline_table().unwrap(); + assert_eq!(dep.get("default-features").unwrap().as_bool(), Some(false)); + + verify_roundtrip(&crate_root, key, &item); + } + + #[test] + fn to_toml_dep_with_path_source() { + let root = paths::normalize_path(&std::env::current_dir().unwrap().join(Path::new("/"))); + let crate_root = root.join("foo"); + let dep = Dependency::new("dep").set_source(PathSource::new(root.join("bar"))); + let key = dep.toml_key(); + let item = dep.to_toml(&crate_root); + + assert_eq!(key, "dep".to_owned()); + assert!(item.is_inline_table()); + + let dep = item.as_inline_table().unwrap(); + assert_eq!(dep.get("path").unwrap().as_str(), Some("../bar")); + + verify_roundtrip(&crate_root, key, &item); + } + + #[test] + fn to_toml_dep_with_git_source() { + let crate_root = + paths::normalize_path(&std::env::current_dir().unwrap().join(Path::new("/"))); + let dep = Dependency::new("dep").set_source(GitSource::new("https://foor/bar.git")); + let key = dep.toml_key(); + let item = dep.to_toml(&crate_root); + + assert_eq!(key, "dep".to_owned()); + assert!(item.is_inline_table()); + + let dep = item.as_inline_table().unwrap(); + assert_eq!( + dep.get("git").unwrap().as_str(), + Some("https://foor/bar.git") + ); + + verify_roundtrip(&crate_root, key, &item); + } + + #[test] + fn to_toml_renamed_dep() { + let crate_root = + paths::normalize_path(&std::env::current_dir().unwrap().join(Path::new("/"))); + let dep = Dependency::new("dep") + .set_source(RegistrySource::new("1.0")) + .set_rename("d"); + let key = dep.toml_key(); + let item = dep.to_toml(&crate_root); + + assert_eq!(key, "d".to_owned()); + assert!(item.is_inline_table()); + + let dep = item.as_inline_table().unwrap(); + assert_eq!(dep.get("package").unwrap().as_str(), Some("dep")); + + verify_roundtrip(&crate_root, key, &item); + } + + #[test] + fn to_toml_dep_from_alt_registry() { + let crate_root = + paths::normalize_path(&std::env::current_dir().unwrap().join(Path::new("/"))); + let dep = Dependency::new("dep") + .set_source(RegistrySource::new("1.0")) + .set_registry("alternative"); + let key = dep.toml_key(); + let item = dep.to_toml(&crate_root); + + assert_eq!(key, "dep".to_owned()); + assert!(item.is_inline_table()); + + let dep = item.as_inline_table().unwrap(); + assert_eq!(dep.get("registry").unwrap().as_str(), Some("alternative")); + + verify_roundtrip(&crate_root, key, &item); + } + + #[test] + fn to_toml_complex_dep() { + let crate_root = + paths::normalize_path(&std::env::current_dir().unwrap().join(Path::new("/"))); + let dep = Dependency::new("dep") + .set_source(RegistrySource::new("1.0")) + .set_default_features(false) + .set_rename("d"); + let key = dep.toml_key(); + let item = dep.to_toml(&crate_root); + + assert_eq!(key, "d".to_owned()); + assert!(item.is_inline_table()); + + let dep = item.as_inline_table().unwrap(); + assert_eq!(dep.get("package").unwrap().as_str(), Some("dep")); + assert_eq!(dep.get("version").unwrap().as_str(), Some("1.0")); + assert_eq!(dep.get("default-features").unwrap().as_bool(), Some(false)); + + verify_roundtrip(&crate_root, key, &item); + } + + #[test] + fn paths_with_forward_slashes_are_left_as_is() { + let crate_root = + paths::normalize_path(&std::env::current_dir().unwrap().join(Path::new("/"))); + let path = crate_root.join("sibling/crate"); + let relpath = "sibling/crate"; + let dep = Dependency::new("dep").set_source(PathSource::new(path)); + let key = dep.toml_key(); + let item = dep.to_toml(&crate_root); + + let table = item.as_inline_table().unwrap(); + let got = table.get("path").unwrap().as_str().unwrap(); + assert_eq!(got, relpath); + + verify_roundtrip(&crate_root, key, &item); + } + + #[test] + #[cfg(windows)] + fn normalise_windows_style_paths() { + let crate_root = + paths::normalize_path(&std::env::current_dir().unwrap().join(Path::new("/"))); + let original = crate_root.join(r"sibling\crate"); + let should_be = "sibling/crate"; + let dep = Dependency::new("dep").set_source(PathSource::new(original)); + let key = dep.toml_key(); + let item = dep.to_toml(&crate_root); + + let table = item.as_inline_table().unwrap(); + let got = table.get("path").unwrap().as_str().unwrap(); + assert_eq!(got, should_be); + + verify_roundtrip(&crate_root, key, &item); + } + + #[track_caller] + fn verify_roundtrip(crate_root: &Path, key: &str, item: &toml_edit::Item) { + let roundtrip = Dependency::from_toml(crate_root, key, item).unwrap(); + let round_key = roundtrip.toml_key(); + let round_item = roundtrip.to_toml(crate_root); + assert_eq!(key, round_key); + assert_eq!(item.to_string(), round_item.to_string()); + } +} diff --git a/src/cargo/ops/cargo_add/manifest.rs b/src/cargo/ops/cargo_add/manifest.rs new file mode 100644 index 00000000000..63cab6a701d --- /dev/null +++ b/src/cargo/ops/cargo_add/manifest.rs @@ -0,0 +1,507 @@ +use std::ops::{Deref, DerefMut}; +use std::path::{Path, PathBuf}; +use std::str; + +use anyhow::Context as _; + +use super::dependency::Dependency; +use crate::core::dependency::DepKind; +use crate::core::FeatureValue; +use crate::util::interning::InternedString; +use crate::CargoResult; + +/// Dependency table to add dep to +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct DepTable { + kind: DepKind, + target: Option, +} + +impl DepTable { + const KINDS: &'static [Self] = &[ + Self::new().set_kind(DepKind::Normal), + Self::new().set_kind(DepKind::Development), + Self::new().set_kind(DepKind::Build), + ]; + + /// Reference to a Dependency Table + pub const fn new() -> Self { + Self { + kind: DepKind::Normal, + target: None, + } + } + + /// Choose the type of dependency + pub const fn set_kind(mut self, kind: DepKind) -> Self { + self.kind = kind; + self + } + + /// Choose the platform for the dependency + pub fn set_target(mut self, target: impl Into) -> Self { + self.target = Some(target.into()); + self + } + + /// Type of dependency + pub fn kind(&self) -> DepKind { + self.kind + } + + /// Platform for the dependency + pub fn target(&self) -> Option<&str> { + self.target.as_deref() + } + + /// Keys to the table + pub fn to_table(&self) -> Vec<&str> { + if let Some(target) = &self.target { + vec!["target", target, self.kind_table()] + } else { + vec![self.kind_table()] + } + } + + fn kind_table(&self) -> &str { + match self.kind { + DepKind::Normal => "dependencies", + DepKind::Development => "dev-dependencies", + DepKind::Build => "build-dependencies", + } + } +} + +impl Default for DepTable { + fn default() -> Self { + Self::new() + } +} + +impl From for DepTable { + fn from(other: DepKind) -> Self { + Self::new().set_kind(other) + } +} + +/// A Cargo manifest +#[derive(Debug, Clone)] +pub struct Manifest { + /// Manifest contents as TOML data + pub data: toml_edit::Document, +} + +impl Manifest { + /// Get the manifest's package name + pub fn package_name(&self) -> CargoResult<&str> { + self.data + .as_table() + .get("package") + .and_then(|m| m.get("name")) + .and_then(|m| m.as_str()) + .ok_or_else(parse_manifest_err) + } + + /// Get the specified table from the manifest. + pub fn get_table<'a>(&'a self, table_path: &[String]) -> CargoResult<&'a toml_edit::Item> { + /// Descend into a manifest until the required table is found. + fn descend<'a>( + input: &'a toml_edit::Item, + path: &[String], + ) -> CargoResult<&'a toml_edit::Item> { + if let Some(segment) = path.get(0) { + let value = input + .get(&segment) + .ok_or_else(|| non_existent_table_err(segment))?; + + if value.is_table_like() { + descend(value, &path[1..]) + } else { + Err(non_existent_table_err(segment)) + } + } else { + Ok(input) + } + } + + descend(self.data.as_item(), table_path) + } + + /// Get the specified table from the manifest. + pub fn get_table_mut<'a>( + &'a mut self, + table_path: &[String], + ) -> CargoResult<&'a mut toml_edit::Item> { + /// Descend into a manifest until the required table is found. + fn descend<'a>( + input: &'a mut toml_edit::Item, + path: &[String], + ) -> CargoResult<&'a mut toml_edit::Item> { + if let Some(segment) = path.get(0) { + let mut default_table = toml_edit::Table::new(); + default_table.set_implicit(true); + let value = input[&segment].or_insert(toml_edit::Item::Table(default_table)); + + if value.is_table_like() { + descend(value, &path[1..]) + } else { + Err(non_existent_table_err(segment)) + } + } else { + Ok(input) + } + } + + descend(self.data.as_item_mut(), table_path) + } + + /// Get all sections in the manifest that exist and might contain dependencies. + /// The returned items are always `Table` or `InlineTable`. + pub fn get_sections(&self) -> Vec<(DepTable, toml_edit::Item)> { + let mut sections = Vec::new(); + + for table in DepTable::KINDS { + let dependency_type = table.kind_table(); + // Dependencies can be in the three standard sections... + if self + .data + .get(dependency_type) + .map(|t| t.is_table_like()) + .unwrap_or(false) + { + sections.push((table.clone(), self.data[dependency_type].clone())) + } + + // ... and in `target..(build-/dev-)dependencies`. + let target_sections = self + .data + .as_table() + .get("target") + .and_then(toml_edit::Item::as_table_like) + .into_iter() + .flat_map(toml_edit::TableLike::iter) + .filter_map(|(target_name, target_table)| { + let dependency_table = target_table.get(dependency_type)?; + dependency_table.as_table_like().map(|_| { + ( + table.clone().set_target(target_name), + dependency_table.clone(), + ) + }) + }); + + sections.extend(target_sections); + } + + sections + } + + pub fn get_legacy_sections(&self) -> Vec { + let mut result = Vec::new(); + + for dependency_type in ["dev_dependencies", "build_dependencies"] { + if self.data.contains_key(dependency_type) { + result.push(dependency_type.to_owned()); + } + + // ... and in `target..(build-/dev-)dependencies`. + result.extend( + self.data + .as_table() + .get("target") + .and_then(toml_edit::Item::as_table_like) + .into_iter() + .flat_map(toml_edit::TableLike::iter) + .filter_map(|(target_name, target_table)| { + if target_table.as_table_like()?.contains_key(dependency_type) { + Some(format!("target.{target_name}.{dependency_type}")) + } else { + None + } + }), + ); + } + result + } +} + +impl str::FromStr for Manifest { + type Err = anyhow::Error; + + /// Read manifest data from string + fn from_str(input: &str) -> ::std::result::Result { + let d: toml_edit::Document = input.parse().context("Manifest not valid TOML")?; + + Ok(Manifest { data: d }) + } +} + +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) + } +} + +/// A Cargo manifest that is available locally. +#[derive(Debug)] +pub struct LocalManifest { + /// Path to the manifest + pub path: PathBuf, + /// Manifest contents + pub manifest: Manifest, +} + +impl Deref for LocalManifest { + type Target = Manifest; + + fn deref(&self) -> &Manifest { + &self.manifest + } +} + +impl DerefMut for LocalManifest { + fn deref_mut(&mut self) -> &mut Manifest { + &mut self.manifest + } +} + +impl LocalManifest { + /// Construct the `LocalManifest` corresponding to the `Path` provided. + pub fn try_new(path: &Path) -> CargoResult { + if !path.is_absolute() { + anyhow::bail!("can only edit absolute paths, got {}", path.display()); + } + let data = cargo_util::paths::read(&path)?; + let manifest = data.parse().context("Unable to parse Cargo.toml")?; + Ok(LocalManifest { + manifest, + path: path.to_owned(), + }) + } + + /// Write changes back to the file + pub fn write(&self) -> CargoResult<()> { + if !self.manifest.data.contains_key("package") + && !self.manifest.data.contains_key("project") + { + if self.manifest.data.contains_key("workspace") { + anyhow::bail!( + "found virtual manifest at {}, but this command requires running against an \ + actual package in this workspace.", + self.path.display() + ); + } else { + anyhow::bail!( + "missing expected `package` or `project` fields in {}", + self.path.display() + ); + } + } + + let s = self.manifest.data.to_string(); + let new_contents_bytes = s.as_bytes(); + + cargo_util::paths::write(&self.path, new_contents_bytes) + } + + /// Lookup a dependency + pub fn get_dependency_versions<'s>( + &'s self, + dep_key: &'s str, + ) -> impl Iterator)> + 's { + let crate_root = self.path.parent().expect("manifest path is absolute"); + self.get_sections() + .into_iter() + .filter_map(move |(table_path, table)| { + let table = table.into_table().ok()?; + Some( + table + .into_iter() + .filter_map(|(key, item)| { + if key.as_str() == dep_key { + Some((table_path.clone(), key, item)) + } else { + None + } + }) + .collect::>(), + ) + }) + .flatten() + .map(move |(table_path, dep_key, dep_item)| { + let dep = Dependency::from_toml(crate_root, &dep_key, &dep_item); + (table_path, dep) + }) + } + + /// Add entry to a Cargo.toml. + pub fn insert_into_table( + &mut self, + table_path: &[String], + dep: &Dependency, + ) -> CargoResult<()> { + let crate_root = self + .path + .parent() + .expect("manifest path is absolute") + .to_owned(); + let dep_key = dep.toml_key(); + + let table = self.get_table_mut(table_path)?; + if let Some(dep_item) = table.as_table_like_mut().unwrap().get_mut(dep_key) { + dep.update_toml(&crate_root, dep_item); + } else { + let new_dependency = dep.to_toml(&crate_root); + table[dep_key] = new_dependency; + } + if let Some(t) = table.as_inline_table_mut() { + t.fmt() + } + + 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); + let status = self.dep_status(dep_key); + + if let Some(toml_edit::Item::Table(feature_table)) = + self.data.as_table_mut().get_mut("features") + { + for (_feature, mut feature_values) in feature_table.iter_mut() { + if let toml_edit::Item::Value(toml_edit::Value::Array(feature_values)) = + &mut feature_values + { + fix_feature_activations( + feature_values, + dep_key, + status, + explicit_dep_activation, + ); + } + } + } + } + + fn is_explicit_dep_activation(&self, dep_key: &str) -> bool { + if let Some(toml_edit::Item::Table(feature_table)) = self.data.as_table().get("features") { + for values in feature_table + .iter() + .map(|(_, a)| a) + .filter_map(|i| i.as_value()) + .filter_map(|v| v.as_array()) + { + for value in values.iter().filter_map(|v| v.as_str()) { + let value = FeatureValue::new(InternedString::new(value)); + if let FeatureValue::Dep { dep_name } = &value { + if dep_name.as_str() == dep_key { + return true; + } + } + } + } + } + + false + } + + fn dep_status(&self, dep_key: &str) -> DependencyStatus { + let mut status = DependencyStatus::None; + for (_, tbl) in self.get_sections() { + if let toml_edit::Item::Table(tbl) = tbl { + if let Some(dep_item) = tbl.get(dep_key) { + let optional = dep_item + .get("optional") + .and_then(|i| i.as_value()) + .and_then(|i| i.as_bool()) + .unwrap_or(false); + if optional { + return DependencyStatus::Optional; + } else { + status = DependencyStatus::Required; + } + } + } + } + status + } +} + +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +enum DependencyStatus { + None, + Optional, + Required, +} + +fn fix_feature_activations( + feature_values: &mut toml_edit::Array, + dep_key: &str, + status: DependencyStatus, + explicit_dep_activation: bool, +) { + let remove_list: Vec = feature_values + .iter() + .enumerate() + .filter_map(|(idx, value)| value.as_str().map(|s| (idx, s))) + .filter_map(|(idx, value)| { + let parsed_value = FeatureValue::new(InternedString::new(value)); + match status { + DependencyStatus::None => match (parsed_value, explicit_dep_activation) { + (FeatureValue::Feature(dep_name), false) + | (FeatureValue::Dep { dep_name }, _) + | (FeatureValue::DepFeature { dep_name, .. }, _) => dep_name == dep_key, + _ => false, + }, + DependencyStatus::Optional => false, + DependencyStatus::Required => match (parsed_value, explicit_dep_activation) { + (FeatureValue::Feature(dep_name), false) + | (FeatureValue::Dep { dep_name }, _) => dep_name == dep_key, + (FeatureValue::Feature(_), true) | (FeatureValue::DepFeature { .. }, _) => { + false + } + }, + } + .then(|| idx) + }) + .collect(); + + // Remove found idx in revers order so we don't invalidate the idx. + for idx in remove_list.iter().rev() { + feature_values.remove(*idx); + } + + if status == DependencyStatus::Required { + for value in feature_values.iter_mut() { + let parsed_value = if let Some(value) = value.as_str() { + FeatureValue::new(InternedString::new(value)) + } else { + continue; + }; + if let FeatureValue::DepFeature { + dep_name, + dep_feature, + weak, + } = parsed_value + { + if dep_name == dep_key && weak { + *value = format!("{dep_name}/{dep_feature}").into(); + } + } + } + } +} + +pub fn str_or_1_len_table(item: &toml_edit::Item) -> bool { + item.is_str() || item.as_table_like().map(|t| t.len() == 1).unwrap_or(false) +} + +fn parse_manifest_err() -> anyhow::Error { + anyhow::format_err!("unable to parse external Cargo.toml") +} + +fn non_existent_table_err(table: impl std::fmt::Display) -> anyhow::Error { + anyhow::format_err!("the table `{table}` could not be found.") +} diff --git a/src/cargo/ops/cargo_add/mod.rs b/src/cargo/ops/cargo_add/mod.rs new file mode 100644 index 00000000000..20cc26ece22 --- /dev/null +++ b/src/cargo/ops/cargo_add/mod.rs @@ -0,0 +1,647 @@ +//! Core of cargo-add command + +mod crate_spec; +mod dependency; +mod manifest; + +use std::collections::BTreeSet; +use std::collections::VecDeque; +use std::path::Path; + +use cargo_util::paths; +use indexmap::IndexSet; +use termcolor::Color::Green; +use termcolor::Color::Red; +use termcolor::ColorSpec; +use toml_edit::Item as TomlItem; + +use crate::core::dependency::DepKind; +use crate::core::registry::PackageRegistry; +use crate::core::Package; +use crate::core::Registry; +use crate::core::Shell; +use crate::core::Workspace; +use crate::CargoResult; +use crate::Config; +use crate_spec::CrateSpec; +use dependency::Dependency; +use dependency::GitSource; +use dependency::PathSource; +use dependency::RegistrySource; +use dependency::Source; +use manifest::LocalManifest; + +pub use manifest::DepTable; + +/// Information on what dependencies should be added +#[derive(Clone, Debug)] +pub struct AddOptions<'a> { + /// Configuration information for cargo operations + pub config: &'a Config, + /// Package to add dependencies to + pub spec: &'a Package, + /// Dependencies to add or modify + pub dependencies: Vec, + /// Which dependency section to add these to + pub section: DepTable, + /// Act as if dependencies will be added + pub dry_run: bool, +} + +/// Add dependencies to a manifest +pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> 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)?; + let legacy = manifest.get_legacy_sections(); + if !legacy.is_empty() { + anyhow::bail!( + "Deprecated dependency sections are unsupported: {}", + legacy.join(", ") + ); + } + + let mut registry = PackageRegistry::new(options.config)?; + + let deps = { + let _lock = options.config.acquire_package_cache_lock()?; + registry.lock_patches(); + options + .dependencies + .iter() + .map(|raw| { + resolve_dependency( + &manifest, + raw, + workspace, + &options.section, + options.config, + &mut registry, + ) + }) + .collect::>>()? + }; + + let was_sorted = manifest + .get_table(&dep_table) + .map(TomlItem::as_table) + .map_or(true, |table_option| { + table_option.map_or(true, |table| is_sorted(table.iter().map(|(name, _)| name))) + }); + for dep in deps { + print_msg(&mut options.config.shell(), &dep, &dep_table)?; + if let Some(Source::Path(src)) = dep.source() { + if src.path == manifest.path.parent().unwrap_or_else(|| Path::new("")) { + anyhow::bail!( + "cannot add `{}` as a dependency to itself", + manifest.package_name()? + ) + } + } + if let Some(req_feats) = dep.features.as_ref() { + let req_feats: BTreeSet<_> = req_feats.iter().map(|s| s.as_str()).collect(); + + let available_features = dep + .available_features + .keys() + .map(|s| s.as_ref()) + .collect::>(); + + let mut unknown_features: Vec<&&str> = + req_feats.difference(&available_features).collect(); + unknown_features.sort(); + + if !unknown_features.is_empty() { + anyhow::bail!("unrecognized features: {unknown_features:?}"); + } + } + manifest.insert_into_table(&dep_table, &dep)?; + manifest.gc_dep(dep.toml_key()); + } + + if was_sorted { + if let Some(table) = manifest + .get_table_mut(&dep_table) + .ok() + .and_then(TomlItem::as_table_like_mut) + { + table.sort_values(); + } + } + + if options.dry_run { + options.config.shell().warn("aborting add due to dry run")?; + } else { + manifest.write()?; + } + + Ok(()) +} + +/// Dependency entry operation +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct DepOp { + /// Describes the crate + pub crate_spec: Option, + /// Dependency key, overriding the package name in crate_spec + pub rename: Option, + + /// Feature flags to activate + pub features: Option>, + /// Whether the default feature should be activated + pub default_features: Option, + + /// Whether dependency is optional + pub optional: Option, + + /// Registry for looking up dependency version + pub registry: Option, + + /// Git repo for dependency + pub path: Option, + /// Git repo for dependency + pub git: Option, + /// Specify an alternative git branch + pub branch: Option, + /// Specify a specific git rev + pub rev: Option, + /// Specify a specific git tag + pub tag: Option, +} + +fn resolve_dependency( + manifest: &LocalManifest, + arg: &DepOp, + ws: &Workspace<'_>, + section: &DepTable, + config: &Config, + registry: &mut PackageRegistry<'_>, +) -> CargoResult { + let crate_spec = arg + .crate_spec + .as_deref() + .map(CrateSpec::resolve) + .transpose()?; + let mut selected_dep = if let Some(url) = &arg.git { + let mut src = GitSource::new(url); + if let Some(branch) = &arg.branch { + src = src.set_branch(branch); + } + if let Some(tag) = &arg.tag { + src = src.set_tag(tag); + } + if let Some(rev) = &arg.rev { + src = src.set_rev(rev); + } + + let selected = if let Some(crate_spec) = &crate_spec { + if let Some(v) = crate_spec.version_req() { + // crate specifier includes a version (e.g. `docopt@0.8`) + anyhow::bail!("cannot specify a git URL (`{url}`) with a version (`{v}`)."); + } + let dependency = crate_spec.to_dependency()?.set_source(src); + let selected = select_package(&dependency, config, registry)?; + if dependency.name != selected.name { + config.shell().warn(format!( + "translating `{}` to `{}`", + dependency.name, selected.name, + ))?; + } + selected + } else { + let mut source = crate::sources::GitSource::new(src.source_id()?, config)?; + let packages = source.read_packages()?; + let package = infer_package(packages, &src)?; + Dependency::from(package.summary()) + }; + selected + } else if let Some(raw_path) = &arg.path { + let path = paths::normalize_path(&std::env::current_dir()?.join(raw_path)); + let src = PathSource::new(&path); + + let selected = if let Some(crate_spec) = &crate_spec { + if let Some(v) = crate_spec.version_req() { + // crate specifier includes a version (e.g. `docopt@0.8`) + anyhow::bail!("cannot specify a path (`{raw_path}`) with a version (`{v}`)."); + } + let dependency = crate_spec.to_dependency()?.set_source(src); + let selected = select_package(&dependency, config, registry)?; + if dependency.name != selected.name { + config.shell().warn(format!( + "translating `{}` to `{}`", + dependency.name, selected.name, + ))?; + } + selected + } else { + let source = crate::sources::PathSource::new(&path, src.source_id()?, config); + let packages = source.read_packages()?; + let package = infer_package(packages, &src)?; + Dependency::from(package.summary()) + }; + selected + } else if let Some(crate_spec) = &crate_spec { + crate_spec.to_dependency()? + } else { + anyhow::bail!("dependency name is required"); + }; + selected_dep = populate_dependency(selected_dep, arg); + + let old_dep = get_existing_dependency(manifest, selected_dep.toml_key(), section)?; + let mut dependency = if let Some(mut old_dep) = old_dep.clone() { + if old_dep.name != selected_dep.name { + // Assuming most existing keys are not relevant when the package changes + if selected_dep.optional.is_none() { + selected_dep.optional = old_dep.optional; + } + selected_dep + } else { + if selected_dep.source().is_some() { + // Overwrite with `crate_spec` + old_dep.source = selected_dep.source; + } + old_dep = populate_dependency(old_dep, arg); + old_dep.available_features = selected_dep.available_features; + old_dep + } + } else { + selected_dep + }; + + if dependency.source().is_none() { + if let Some(package) = ws.members().find(|p| p.name().as_str() == dependency.name) { + // Only special-case workspaces when the user doesn't provide any extra + // information, otherwise, trust the user. + let mut src = PathSource::new(package.root()); + // dev-dependencies do not need the version populated + if section.kind() != DepKind::Development { + let op = ""; + let v = format!("{op}{version}", version = package.version()); + src = src.set_version(v); + } + dependency = dependency.set_source(src); + } else { + let latest = get_latest_dependency(&dependency, false, config, registry)?; + + if dependency.name != latest.name { + config.shell().warn(format!( + "translating `{}` to `{}`", + dependency.name, latest.name, + ))?; + dependency.name = latest.name; // Normalize the name + } + dependency = dependency + .set_source(latest.source.expect("latest always has a source")) + .set_available_features(latest.available_features); + } + } + + let version_required = dependency.source().and_then(|s| s.as_registry()).is_some(); + let version_optional_in_section = section.kind() == DepKind::Development; + let preserve_existing_version = old_dep + .as_ref() + .map(|d| d.version().is_some()) + .unwrap_or(false); + if !version_required && !preserve_existing_version && version_optional_in_section { + // dev-dependencies do not need the version populated + dependency = dependency.clear_version(); + } + + dependency = populate_available_features(dependency, config, registry)?; + + Ok(dependency) +} + +/// Provide the existing dependency for the target table +/// +/// If it doesn't exist but exists in another table, let's use that as most likely users +/// want to use the same version across all tables unless they are renaming. +fn get_existing_dependency( + manifest: &LocalManifest, + dep_key: &str, + section: &DepTable, +) -> CargoResult> { + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)] + enum Key { + Error, + Dev, + Build, + Normal, + Existing, + } + + let mut possible: Vec<_> = manifest + .get_dependency_versions(dep_key) + .map(|(path, dep)| { + let key = if path == *section { + (Key::Existing, true) + } else if dep.is_err() { + (Key::Error, path.target().is_some()) + } else { + let key = match path.kind() { + DepKind::Normal => Key::Normal, + DepKind::Build => Key::Build, + DepKind::Development => Key::Dev, + }; + (key, path.target().is_some()) + }; + (key, dep) + }) + .collect(); + possible.sort_by_key(|(key, _)| *key); + let (key, dep) = if let Some(item) = possible.pop() { + item + } else { + return Ok(None); + }; + let mut dep = dep?; + + if key.0 != Key::Existing { + // When the dep comes from a different section, we only care about the source and not any + // of the other fields, like `features` + let unrelated = dep; + dep = Dependency::new(&unrelated.name); + dep.source = unrelated.source.clone(); + dep.registry = unrelated.registry.clone(); + + // dev-dependencies do not need the version populated when path is set though we + // should preserve it if the user chose to populate it. + let version_required = unrelated.source().and_then(|s| s.as_registry()).is_some(); + let version_optional_in_section = section.kind() == DepKind::Development; + if !version_required && version_optional_in_section { + dep = dep.clear_version(); + } + } + + Ok(Some(dep)) +} + +fn get_latest_dependency( + dependency: &Dependency, + _flag_allow_prerelease: bool, + config: &Config, + registry: &mut PackageRegistry<'_>, +) -> CargoResult { + let query = dependency.query(config)?; + let possibilities = loop { + let fuzzy = true; + match registry.query_vec(&query, fuzzy) { + std::task::Poll::Ready(res) => { + break res?; + } + std::task::Poll::Pending => registry.block_until_ready()?, + } + }; + let latest = possibilities + .iter() + .max_by_key(|s| { + // Fallback to a pre-release if no official release is available by sorting them as + // less. + let stable = s.version().pre.is_empty(); + (stable, s.version()) + }) + .ok_or_else(|| { + anyhow::format_err!("the crate `{dependency}` could not be found in registry index.") + })?; + let mut dep = Dependency::from(latest); + if let Some(reg_name) = dependency.registry.as_deref() { + dep = dep.set_registry(reg_name); + } + Ok(dep) +} + +fn select_package( + dependency: &Dependency, + config: &Config, + registry: &mut PackageRegistry<'_>, +) -> CargoResult { + let query = dependency.query(config)?; + let possibilities = loop { + let fuzzy = false; // Returns all for path/git + match registry.query_vec(&query, fuzzy) { + std::task::Poll::Ready(res) => { + break res?; + } + std::task::Poll::Pending => registry.block_until_ready()?, + } + }; + match possibilities.len() { + 0 => { + let source = dependency + .source() + .expect("source should be resolved before here"); + anyhow::bail!("the crate `{dependency}` could not be found at `{source}`") + } + 1 => { + let mut dep = Dependency::from(&possibilities[0]); + if let Some(reg_name) = dependency.registry.as_deref() { + dep = dep.set_registry(reg_name); + } + Ok(dep) + } + _ => { + let source = dependency + .source() + .expect("source should be resolved before here"); + anyhow::bail!( + "unexpectedly found multiple copies of crate `{dependency}` at `{source}`" + ) + } + } +} + +fn infer_package(mut packages: Vec, src: &dyn std::fmt::Display) -> CargoResult { + let package = match packages.len() { + 0 => { + anyhow::bail!("no packages found at `{src}`"); + } + 1 => packages.pop().expect("match ensured element is present"), + _ => { + let mut names: Vec<_> = packages + .iter() + .map(|p| p.name().as_str().to_owned()) + .collect(); + names.sort_unstable(); + anyhow::bail!("multiple packages found at `{src}`: {}", names.join(", ")); + } + }; + Ok(package) +} + +fn populate_dependency(mut dependency: Dependency, arg: &DepOp) -> Dependency { + if let Some(registry) = &arg.registry { + if registry.is_empty() { + dependency.registry = None; + } else { + dependency.registry = Some(registry.to_owned()); + } + } + if let Some(value) = arg.optional { + if value { + dependency.optional = Some(true); + } else { + dependency.optional = None; + } + } + if let Some(value) = arg.default_features { + if value { + dependency.default_features = None; + } else { + dependency.default_features = Some(false); + } + } + if let Some(value) = arg.features.as_ref() { + dependency = dependency.extend_features(value.iter().cloned()); + } + + if let Some(rename) = &arg.rename { + dependency = dependency.set_rename(rename); + } + + dependency +} + +/// Lookup available features +fn populate_available_features( + mut dependency: Dependency, + config: &Config, + registry: &mut PackageRegistry<'_>, +) -> CargoResult { + if !dependency.available_features.is_empty() { + return Ok(dependency); + } + + let query = dependency.query(config)?; + let possibilities = loop { + match registry.query_vec(&query, true) { + std::task::Poll::Ready(res) => { + break res?; + } + std::task::Poll::Pending => registry.block_until_ready()?, + } + }; + // Ensure widest feature flag compatibility by picking the earliest version that could show up + // in the lock file for a given version requirement. + let lowest_common_denominator = possibilities + .iter() + .min_by_key(|s| { + // Fallback to a pre-release if no official release is available by sorting them as + // more. + let is_pre = !s.version().pre.is_empty(); + (is_pre, s.version()) + }) + .ok_or_else(|| { + anyhow::format_err!("the crate `{dependency}` could not be found in registry index.") + })?; + dependency = dependency.set_available_features_from_cargo(lowest_common_denominator.features()); + + Ok(dependency) +} + +fn print_msg(shell: &mut Shell, dep: &Dependency, section: &[String]) -> CargoResult<()> { + use std::fmt::Write; + + if matches!(shell.verbosity(), crate::core::shell::Verbosity::Quiet) { + return Ok(()); + } + + let mut message = String::new(); + write!(message, "{}", dep.name)?; + match dep.source() { + Some(Source::Registry(src)) => { + if src.version.chars().next().unwrap_or('0').is_ascii_digit() { + write!(message, " v{}", src.version)?; + } else { + write!(message, " {}", src.version)?; + } + } + Some(Source::Path(_)) => { + write!(message, " (local)")?; + } + Some(Source::Git(_)) => { + write!(message, " (git)")?; + } + None => {} + } + write!(message, " to")?; + if dep.optional().unwrap_or(false) { + write!(message, " optional")?; + } + let section = if section.len() == 1 { + section[0].clone() + } else { + format!("{} for target `{}`", §ion[2], §ion[1]) + }; + write!(message, " {section}")?; + write!(message, ".")?; + shell.status("Adding", message)?; + + let mut activated: IndexSet<_> = dep.features.iter().flatten().map(|s| s.as_str()).collect(); + if dep.default_features().unwrap_or(true) { + activated.insert("default"); + } + let mut walk: VecDeque<_> = activated.iter().cloned().collect(); + while let Some(next) = walk.pop_front() { + walk.extend( + dep.available_features + .get(next) + .into_iter() + .flatten() + .map(|s| s.as_str()), + ); + activated.extend( + dep.available_features + .get(next) + .into_iter() + .flatten() + .map(|s| s.as_str()), + ); + } + activated.remove("default"); + activated.sort(); + let mut deactivated = dep + .available_features + .keys() + .filter(|f| !activated.contains(f.as_str()) && *f != "default") + .collect::>(); + deactivated.sort(); + if !activated.is_empty() || !deactivated.is_empty() { + let prefix = format!("{:>13}", " "); + shell.write_stderr(format_args!("{}Features:\n", prefix), &ColorSpec::new())?; + for feat in activated { + shell.write_stderr(&prefix, &ColorSpec::new())?; + shell.write_stderr('+', &ColorSpec::new().set_bold(true).set_fg(Some(Green)))?; + shell.write_stderr(format_args!(" {}\n", feat), &ColorSpec::new())?; + } + for feat in deactivated { + shell.write_stderr(&prefix, &ColorSpec::new())?; + shell.write_stderr('-', &ColorSpec::new().set_bold(true).set_fg(Some(Red)))?; + shell.write_stderr(format_args!(" {}\n", feat), &ColorSpec::new())?; + } + } + + Ok(()) +} + +// Based on Iterator::is_sorted from nightly std; remove in favor of that when stabilized. +fn is_sorted(mut it: impl Iterator) -> bool { + let mut last = match it.next() { + Some(e) => e, + None => return true, + }; + + for curr in it { + if curr < last { + return false; + } + last = curr; + } + + true +} diff --git a/src/cargo/ops/mod.rs b/src/cargo/ops/mod.rs index e81486f3dd5..4e694ca6ffb 100644 --- a/src/cargo/ops/mod.rs +++ b/src/cargo/ops/mod.rs @@ -32,6 +32,7 @@ pub use self::resolve::{ }; pub use self::vendor::{vendor, VendorOptions}; +pub mod cargo_add; mod cargo_clean; mod cargo_compile; pub mod cargo_config; diff --git a/tests/snapshots/add/add-basic.in/Cargo.toml b/tests/snapshots/add/add-basic.in/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/add-basic.in/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/add-basic.in/src/lib.rs b/tests/snapshots/add/add-basic.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/add_basic.in b/tests/snapshots/add/add_basic.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/add_basic.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/add_basic.out/Cargo.toml b/tests/snapshots/add/add_basic.out/Cargo.toml new file mode 100644 index 00000000000..5964c87be74 --- /dev/null +++ b/tests/snapshots/add/add_basic.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/snapshots/add/add_basic.stderr b/tests/snapshots/add/add_basic.stderr new file mode 100644 index 00000000000..fd6b711e386 --- /dev/null +++ b/tests/snapshots/add/add_basic.stderr @@ -0,0 +1,2 @@ + Updating `dummy-registry` index + Adding my-package v99999.0.0 to dependencies. diff --git a/tests/snapshots/add/add_basic.stdout b/tests/snapshots/add/add_basic.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/add_multiple.in b/tests/snapshots/add/add_multiple.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/add_multiple.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/add_multiple.out/Cargo.toml b/tests/snapshots/add/add_multiple.out/Cargo.toml new file mode 100644 index 00000000000..ba8d7eabe5b --- /dev/null +++ b/tests/snapshots/add/add_multiple.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = "99999.0.0" +my-package2 = "99999.0.0" diff --git a/tests/snapshots/add/add_multiple.stderr b/tests/snapshots/add/add_multiple.stderr new file mode 100644 index 00000000000..d0b4e73c1ce --- /dev/null +++ b/tests/snapshots/add/add_multiple.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package1 v99999.0.0 to dependencies. + Adding my-package2 v99999.0.0 to dependencies. diff --git a/tests/snapshots/add/add_multiple.stdout b/tests/snapshots/add/add_multiple.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/add_normalized_name_external.in b/tests/snapshots/add/add_normalized_name_external.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/add_normalized_name_external.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/add_normalized_name_external.out/Cargo.toml b/tests/snapshots/add/add_normalized_name_external.out/Cargo.toml new file mode 100644 index 00000000000..3d0dec34345 --- /dev/null +++ b/tests/snapshots/add/add_normalized_name_external.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +inflector = "0.11.4" +linked-hash-map = "0.5.4" diff --git a/tests/snapshots/add/add_normalized_name_external.stderr b/tests/snapshots/add/add_normalized_name_external.stderr new file mode 100644 index 00000000000..c7d45114329 --- /dev/null +++ b/tests/snapshots/add/add_normalized_name_external.stderr @@ -0,0 +1,18 @@ + Updating `dummy-registry` index +warning: translating `linked_hash_map` to `linked-hash-map` +warning: translating `Inflector` to `inflector` + Adding linked-hash-map v0.5.4 to dependencies. + Features: + - clippy + - heapsize + - heapsize_impl + - nightly + - serde + - serde_impl + - serde_test + Adding inflector v0.11.4 to dependencies. + Features: + + heavyweight + + lazy_static + + regex + - unstable diff --git a/tests/snapshots/add/add_normalized_name_external.stdout b/tests/snapshots/add/add_normalized_name_external.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/build.in b/tests/snapshots/add/build.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/build.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/build.out/Cargo.toml b/tests/snapshots/add/build.out/Cargo.toml new file mode 100644 index 00000000000..cceb448ed56 --- /dev/null +++ b/tests/snapshots/add/build.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[build-dependencies] +my-build-package1 = "99999.0.0" +my-build-package2 = "99999.0.0" diff --git a/tests/snapshots/add/build.stderr b/tests/snapshots/add/build.stderr new file mode 100644 index 00000000000..b873c5a8069 --- /dev/null +++ b/tests/snapshots/add/build.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-build-package1 v99999.0.0 to build-dependencies. + Adding my-build-package2 v99999.0.0 to build-dependencies. diff --git a/tests/snapshots/add/build.stdout b/tests/snapshots/add/build.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/build_prefer_existing_version.in/Cargo.toml b/tests/snapshots/add/build_prefer_existing_version.in/Cargo.toml new file mode 100644 index 00000000000..6a6ac823fd6 --- /dev/null +++ b/tests/snapshots/add/build_prefer_existing_version.in/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] +exclude = ["dependency"] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +cargo-list-test-fixture-dependency = { version = "0.0.0", path = "dependency", optional = true, default-features = false, features = ["one", "two"], registry = "alternative" } diff --git a/tests/snapshots/add/build_prefer_existing_version.in/dependency/Cargo.toml b/tests/snapshots/add/build_prefer_existing_version.in/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/build_prefer_existing_version.in/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/build_prefer_existing_version.in/dependency/src/lib.rs b/tests/snapshots/add/build_prefer_existing_version.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/build_prefer_existing_version.in/src/lib.rs b/tests/snapshots/add/build_prefer_existing_version.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/build_prefer_existing_version.out/Cargo.toml b/tests/snapshots/add/build_prefer_existing_version.out/Cargo.toml new file mode 100644 index 00000000000..123af6d22a8 --- /dev/null +++ b/tests/snapshots/add/build_prefer_existing_version.out/Cargo.toml @@ -0,0 +1,12 @@ +[workspace] +exclude = ["dependency"] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +cargo-list-test-fixture-dependency = { version = "0.0.0", path = "dependency", optional = true, default-features = false, features = ["one", "two"], registry = "alternative" } + +[build-dependencies] +cargo-list-test-fixture-dependency = { version = "0.0.0", path = "dependency", registry = "alternative" } diff --git a/tests/snapshots/add/build_prefer_existing_version.out/dependency/Cargo.toml b/tests/snapshots/add/build_prefer_existing_version.out/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/build_prefer_existing_version.out/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/build_prefer_existing_version.stderr b/tests/snapshots/add/build_prefer_existing_version.stderr new file mode 100644 index 00000000000..00f39cd5b98 --- /dev/null +++ b/tests/snapshots/add/build_prefer_existing_version.stderr @@ -0,0 +1 @@ + Adding cargo-list-test-fixture-dependency (local) to build-dependencies. diff --git a/tests/snapshots/add/build_prefer_existing_version.stdout b/tests/snapshots/add/build_prefer_existing_version.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/change_rename_target.in/Cargo.toml b/tests/snapshots/add/change_rename_target.in/Cargo.toml new file mode 100644 index 00000000000..e81a76b4be4 --- /dev/null +++ b/tests/snapshots/add/change_rename_target.in/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +some-package = { package = "my-package1", version = "0.1.1", optional = true } diff --git a/tests/snapshots/add/change_rename_target.in/src/lib.rs b/tests/snapshots/add/change_rename_target.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/change_rename_target.out/Cargo.toml b/tests/snapshots/add/change_rename_target.out/Cargo.toml new file mode 100644 index 00000000000..70cd318268c --- /dev/null +++ b/tests/snapshots/add/change_rename_target.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +some-package = { package = "my-package2", version = "99999.0.0", optional = true } diff --git a/tests/snapshots/add/change_rename_target.stderr b/tests/snapshots/add/change_rename_target.stderr new file mode 100644 index 00000000000..674f626023c --- /dev/null +++ b/tests/snapshots/add/change_rename_target.stderr @@ -0,0 +1,2 @@ + Updating `dummy-registry` index + Adding my-package2 v99999.0.0 to optional dependencies. diff --git a/tests/snapshots/add/change_rename_target.stdout b/tests/snapshots/add/change_rename_target.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/default_features.in b/tests/snapshots/add/default_features.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/default_features.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/default_features.out/Cargo.toml b/tests/snapshots/add/default_features.out/Cargo.toml new file mode 100644 index 00000000000..c5e01789281 --- /dev/null +++ b/tests/snapshots/add/default_features.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = "99999.0.0" +my-package2 = "0.4.1" diff --git a/tests/snapshots/add/default_features.stderr b/tests/snapshots/add/default_features.stderr new file mode 100644 index 00000000000..fb8d4903d7b --- /dev/null +++ b/tests/snapshots/add/default_features.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package1 v99999.0.0 to dependencies. + Adding my-package2 v0.4.1 to dependencies. diff --git a/tests/snapshots/add/default_features.stdout b/tests/snapshots/add/default_features.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/deprecated_default_features.in/Cargo.toml b/tests/snapshots/add/deprecated_default_features.in/Cargo.toml new file mode 100644 index 00000000000..c0fc374eae3 --- /dev/null +++ b/tests/snapshots/add/deprecated_default_features.in/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package = { version = "99999.0.0", default_features = false } diff --git a/tests/snapshots/add/deprecated_default_features.in/src/lib.rs b/tests/snapshots/add/deprecated_default_features.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/deprecated_default_features.out/Cargo.toml b/tests/snapshots/add/deprecated_default_features.out/Cargo.toml new file mode 100644 index 00000000000..c0fc374eae3 --- /dev/null +++ b/tests/snapshots/add/deprecated_default_features.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package = { version = "99999.0.0", default_features = false } diff --git a/tests/snapshots/add/deprecated_default_features.stderr b/tests/snapshots/add/deprecated_default_features.stderr new file mode 100644 index 00000000000..46d99d15def --- /dev/null +++ b/tests/snapshots/add/deprecated_default_features.stderr @@ -0,0 +1 @@ +error: Use of `default_features` in `my-package` is unsupported, please switch to `default-features` diff --git a/tests/snapshots/add/deprecated_default_features.stdout b/tests/snapshots/add/deprecated_default_features.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/deprecated_section.in/Cargo.toml b/tests/snapshots/add/deprecated_section.in/Cargo.toml new file mode 100644 index 00000000000..a83d2c621f6 --- /dev/null +++ b/tests/snapshots/add/deprecated_section.in/Cargo.toml @@ -0,0 +1,11 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dev_dependencies] +my-package = "99999.0.0" + +[build_dependencies] +my-package = "99999.0.0" diff --git a/tests/snapshots/add/deprecated_section.in/src/lib.rs b/tests/snapshots/add/deprecated_section.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/deprecated_section.out/Cargo.toml b/tests/snapshots/add/deprecated_section.out/Cargo.toml new file mode 100644 index 00000000000..a83d2c621f6 --- /dev/null +++ b/tests/snapshots/add/deprecated_section.out/Cargo.toml @@ -0,0 +1,11 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dev_dependencies] +my-package = "99999.0.0" + +[build_dependencies] +my-package = "99999.0.0" diff --git a/tests/snapshots/add/deprecated_section.stderr b/tests/snapshots/add/deprecated_section.stderr new file mode 100644 index 00000000000..b3b9c10f9b9 --- /dev/null +++ b/tests/snapshots/add/deprecated_section.stderr @@ -0,0 +1 @@ +error: Deprecated dependency sections are unsupported: dev_dependencies, build_dependencies diff --git a/tests/snapshots/add/deprecated_section.stdout b/tests/snapshots/add/deprecated_section.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/dev.in b/tests/snapshots/add/dev.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/dev.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/dev.out/Cargo.toml b/tests/snapshots/add/dev.out/Cargo.toml new file mode 100644 index 00000000000..28d9e81ced5 --- /dev/null +++ b/tests/snapshots/add/dev.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dev-dependencies] +my-dev-package1 = "99999.0.0" +my-dev-package2 = "99999.0.0" diff --git a/tests/snapshots/add/dev.stderr b/tests/snapshots/add/dev.stderr new file mode 100644 index 00000000000..f8e187ce9c6 --- /dev/null +++ b/tests/snapshots/add/dev.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-dev-package1 v99999.0.0 to dev-dependencies. + Adding my-dev-package2 v99999.0.0 to dev-dependencies. diff --git a/tests/snapshots/add/dev.stdout b/tests/snapshots/add/dev.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/dev_build_conflict.in b/tests/snapshots/add/dev_build_conflict.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/dev_build_conflict.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/dev_build_conflict.out/Cargo.toml b/tests/snapshots/add/dev_build_conflict.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/dev_build_conflict.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/dev_build_conflict.stderr b/tests/snapshots/add/dev_build_conflict.stderr new file mode 100644 index 00000000000..7aee514e4f3 --- /dev/null +++ b/tests/snapshots/add/dev_build_conflict.stderr @@ -0,0 +1,8 @@ +error: The argument '--dev' cannot be used with '--build' + +USAGE: + cargo add [OPTIONS] [@] ... + cargo add [OPTIONS] --path ... + cargo add [OPTIONS] --git ... + +For more information try --help diff --git a/tests/snapshots/add/dev_build_conflict.stdout b/tests/snapshots/add/dev_build_conflict.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/dev_prefer_existing_version.in/Cargo.toml b/tests/snapshots/add/dev_prefer_existing_version.in/Cargo.toml new file mode 100644 index 00000000000..6a6ac823fd6 --- /dev/null +++ b/tests/snapshots/add/dev_prefer_existing_version.in/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] +exclude = ["dependency"] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +cargo-list-test-fixture-dependency = { version = "0.0.0", path = "dependency", optional = true, default-features = false, features = ["one", "two"], registry = "alternative" } diff --git a/tests/snapshots/add/dev_prefer_existing_version.in/dependency/Cargo.toml b/tests/snapshots/add/dev_prefer_existing_version.in/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/dev_prefer_existing_version.in/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/dev_prefer_existing_version.in/dependency/src/lib.rs b/tests/snapshots/add/dev_prefer_existing_version.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/dev_prefer_existing_version.in/src/lib.rs b/tests/snapshots/add/dev_prefer_existing_version.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/dev_prefer_existing_version.out/Cargo.toml b/tests/snapshots/add/dev_prefer_existing_version.out/Cargo.toml new file mode 100644 index 00000000000..247f345cf64 --- /dev/null +++ b/tests/snapshots/add/dev_prefer_existing_version.out/Cargo.toml @@ -0,0 +1,12 @@ +[workspace] +exclude = ["dependency"] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +cargo-list-test-fixture-dependency = { version = "0.0.0", path = "dependency", optional = true, default-features = false, features = ["one", "two"], registry = "alternative" } + +[dev-dependencies] +cargo-list-test-fixture-dependency = { path = "dependency" } diff --git a/tests/snapshots/add/dev_prefer_existing_version.out/dependency/Cargo.toml b/tests/snapshots/add/dev_prefer_existing_version.out/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/dev_prefer_existing_version.out/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/dev_prefer_existing_version.stderr b/tests/snapshots/add/dev_prefer_existing_version.stderr new file mode 100644 index 00000000000..d8093d6aece --- /dev/null +++ b/tests/snapshots/add/dev_prefer_existing_version.stderr @@ -0,0 +1 @@ + Adding cargo-list-test-fixture-dependency (local) to dev-dependencies. diff --git a/tests/snapshots/add/dev_prefer_existing_version.stdout b/tests/snapshots/add/dev_prefer_existing_version.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/dry_run.in b/tests/snapshots/add/dry_run.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/dry_run.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/dry_run.out/Cargo.toml b/tests/snapshots/add/dry_run.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/dry_run.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/dry_run.stderr b/tests/snapshots/add/dry_run.stderr new file mode 100644 index 00000000000..c80dba94226 --- /dev/null +++ b/tests/snapshots/add/dry_run.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package v99999.0.0 to dependencies. +warning: aborting add due to dry run diff --git a/tests/snapshots/add/dry_run.stdout b/tests/snapshots/add/dry_run.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/features.in b/tests/snapshots/add/features.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/features.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/features.out/Cargo.toml b/tests/snapshots/add/features.out/Cargo.toml new file mode 100644 index 00000000000..11419b20363 --- /dev/null +++ b/tests/snapshots/add/features.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = { version = "99999.0.0", features = ["eyes"] } diff --git a/tests/snapshots/add/features.stderr b/tests/snapshots/add/features.stderr new file mode 100644 index 00000000000..386f3db5acc --- /dev/null +++ b/tests/snapshots/add/features.stderr @@ -0,0 +1,7 @@ + Updating `dummy-registry` index + Adding your-face v99999.0.0 to dependencies. + Features: + + eyes + - ears + - mouth + - nose diff --git a/tests/snapshots/add/features.stdout b/tests/snapshots/add/features.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/features_empty.in b/tests/snapshots/add/features_empty.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/features_empty.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/features_empty.out/Cargo.toml b/tests/snapshots/add/features_empty.out/Cargo.toml new file mode 100644 index 00000000000..79d735a12d4 --- /dev/null +++ b/tests/snapshots/add/features_empty.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = "99999.0.0" diff --git a/tests/snapshots/add/features_empty.stderr b/tests/snapshots/add/features_empty.stderr new file mode 100644 index 00000000000..796b9601b4d --- /dev/null +++ b/tests/snapshots/add/features_empty.stderr @@ -0,0 +1,7 @@ + Updating `dummy-registry` index + Adding your-face v99999.0.0 to dependencies. + Features: + - ears + - eyes + - mouth + - nose diff --git a/tests/snapshots/add/features_empty.stdout b/tests/snapshots/add/features_empty.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/features_multiple_occurrences.in b/tests/snapshots/add/features_multiple_occurrences.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/features_multiple_occurrences.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/features_multiple_occurrences.out/Cargo.toml b/tests/snapshots/add/features_multiple_occurrences.out/Cargo.toml new file mode 100644 index 00000000000..0060d24bcbc --- /dev/null +++ b/tests/snapshots/add/features_multiple_occurrences.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = { version = "99999.0.0", features = ["eyes", "nose"] } diff --git a/tests/snapshots/add/features_multiple_occurrences.stderr b/tests/snapshots/add/features_multiple_occurrences.stderr new file mode 100644 index 00000000000..615459052e4 --- /dev/null +++ b/tests/snapshots/add/features_multiple_occurrences.stderr @@ -0,0 +1,7 @@ + Updating `dummy-registry` index + Adding your-face v99999.0.0 to dependencies. + Features: + + eyes + + nose + - ears + - mouth diff --git a/tests/snapshots/add/features_multiple_occurrences.stdout b/tests/snapshots/add/features_multiple_occurrences.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/features_preserve.in/Cargo.toml b/tests/snapshots/add/features_preserve.in/Cargo.toml new file mode 100644 index 00000000000..11419b20363 --- /dev/null +++ b/tests/snapshots/add/features_preserve.in/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = { version = "99999.0.0", features = ["eyes"] } diff --git a/tests/snapshots/add/features_preserve.in/src/lib.rs b/tests/snapshots/add/features_preserve.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/features_preserve.out/Cargo.toml b/tests/snapshots/add/features_preserve.out/Cargo.toml new file mode 100644 index 00000000000..11419b20363 --- /dev/null +++ b/tests/snapshots/add/features_preserve.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = { version = "99999.0.0", features = ["eyes"] } diff --git a/tests/snapshots/add/features_preserve.stderr b/tests/snapshots/add/features_preserve.stderr new file mode 100644 index 00000000000..386f3db5acc --- /dev/null +++ b/tests/snapshots/add/features_preserve.stderr @@ -0,0 +1,7 @@ + Updating `dummy-registry` index + Adding your-face v99999.0.0 to dependencies. + Features: + + eyes + - ears + - mouth + - nose diff --git a/tests/snapshots/add/features_preserve.stdout b/tests/snapshots/add/features_preserve.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/features_spaced_values.in b/tests/snapshots/add/features_spaced_values.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/features_spaced_values.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/features_spaced_values.out/Cargo.toml b/tests/snapshots/add/features_spaced_values.out/Cargo.toml new file mode 100644 index 00000000000..0060d24bcbc --- /dev/null +++ b/tests/snapshots/add/features_spaced_values.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = { version = "99999.0.0", features = ["eyes", "nose"] } diff --git a/tests/snapshots/add/features_spaced_values.stderr b/tests/snapshots/add/features_spaced_values.stderr new file mode 100644 index 00000000000..615459052e4 --- /dev/null +++ b/tests/snapshots/add/features_spaced_values.stderr @@ -0,0 +1,7 @@ + Updating `dummy-registry` index + Adding your-face v99999.0.0 to dependencies. + Features: + + eyes + + nose + - ears + - mouth diff --git a/tests/snapshots/add/features_spaced_values.stdout b/tests/snapshots/add/features_spaced_values.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/features_unknown.in b/tests/snapshots/add/features_unknown.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/features_unknown.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/features_unknown.out/Cargo.toml b/tests/snapshots/add/features_unknown.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/features_unknown.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/features_unknown.stderr b/tests/snapshots/add/features_unknown.stderr new file mode 100644 index 00000000000..7f59af09a6e --- /dev/null +++ b/tests/snapshots/add/features_unknown.stderr @@ -0,0 +1,9 @@ + Updating `dummy-registry` index + Adding your-face v99999.0.0 to dependencies. + Features: + + noze + - ears + - eyes + - mouth + - nose +error: unrecognized features: ["noze"] diff --git a/tests/snapshots/add/features_unknown.stdout b/tests/snapshots/add/features_unknown.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/git.in b/tests/snapshots/add/git.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/git.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/git.out/Cargo.toml b/tests/snapshots/add/git.out/Cargo.toml new file mode 100644 index 00000000000..7f2d2f18840 --- /dev/null +++ b/tests/snapshots/add/git.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +git-package = { git = "[ROOTURL]/git-package", version = "0.3.0" } diff --git a/tests/snapshots/add/git.stderr b/tests/snapshots/add/git.stderr new file mode 100644 index 00000000000..fdfb1a952a1 --- /dev/null +++ b/tests/snapshots/add/git.stderr @@ -0,0 +1,2 @@ + Updating git repository `[ROOTURL]/git-package` + Adding git-package (git) to dependencies. diff --git a/tests/snapshots/add/git.stdout b/tests/snapshots/add/git.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/git_branch.in b/tests/snapshots/add/git_branch.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/git_branch.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/git_branch.out/Cargo.toml b/tests/snapshots/add/git_branch.out/Cargo.toml new file mode 100644 index 00000000000..2eb2955810a --- /dev/null +++ b/tests/snapshots/add/git_branch.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +git-package = { git = "[ROOTURL]/git-package", branch = "dev", version = "0.3.0" } diff --git a/tests/snapshots/add/git_branch.stderr b/tests/snapshots/add/git_branch.stderr new file mode 100644 index 00000000000..fdfb1a952a1 --- /dev/null +++ b/tests/snapshots/add/git_branch.stderr @@ -0,0 +1,2 @@ + Updating git repository `[ROOTURL]/git-package` + Adding git-package (git) to dependencies. diff --git a/tests/snapshots/add/git_branch.stdout b/tests/snapshots/add/git_branch.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/git_conflicts_namever.in b/tests/snapshots/add/git_conflicts_namever.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/git_conflicts_namever.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/git_conflicts_namever.out/Cargo.toml b/tests/snapshots/add/git_conflicts_namever.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/git_conflicts_namever.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/git_conflicts_namever.stderr b/tests/snapshots/add/git_conflicts_namever.stderr new file mode 100644 index 00000000000..207e0ded3a7 --- /dev/null +++ b/tests/snapshots/add/git_conflicts_namever.stderr @@ -0,0 +1 @@ +error: cannot specify a git URL (`https://github.com/dcjanus/invalid`) with a version (`0.4.3`). diff --git a/tests/snapshots/add/git_conflicts_namever.stdout b/tests/snapshots/add/git_conflicts_namever.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/git_dev.in b/tests/snapshots/add/git_dev.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/git_dev.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/git_dev.out/Cargo.toml b/tests/snapshots/add/git_dev.out/Cargo.toml new file mode 100644 index 00000000000..ceb1317576d --- /dev/null +++ b/tests/snapshots/add/git_dev.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dev-dependencies] +git-package = { git = "[ROOTURL]/git-package" } diff --git a/tests/snapshots/add/git_dev.stderr b/tests/snapshots/add/git_dev.stderr new file mode 100644 index 00000000000..4ba31625b58 --- /dev/null +++ b/tests/snapshots/add/git_dev.stderr @@ -0,0 +1,2 @@ + Updating git repository `[ROOTURL]/git-package` + Adding git-package (git) to dev-dependencies. diff --git a/tests/snapshots/add/git_dev.stdout b/tests/snapshots/add/git_dev.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/git_inferred_name.in b/tests/snapshots/add/git_inferred_name.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/git_inferred_name.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/git_inferred_name.out/Cargo.toml b/tests/snapshots/add/git_inferred_name.out/Cargo.toml new file mode 100644 index 00000000000..7f2d2f18840 --- /dev/null +++ b/tests/snapshots/add/git_inferred_name.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +git-package = { git = "[ROOTURL]/git-package", version = "0.3.0" } diff --git a/tests/snapshots/add/git_inferred_name.stderr b/tests/snapshots/add/git_inferred_name.stderr new file mode 100644 index 00000000000..48f251ea11d --- /dev/null +++ b/tests/snapshots/add/git_inferred_name.stderr @@ -0,0 +1,3 @@ + Updating git repository `[ROOTURL]/git-package` + Updating git repository `[ROOTURL]/git-package` + Adding git-package (git) to dependencies. diff --git a/tests/snapshots/add/git_inferred_name.stdout b/tests/snapshots/add/git_inferred_name.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/git_inferred_name_multiple.in b/tests/snapshots/add/git_inferred_name_multiple.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/git_inferred_name_multiple.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/git_inferred_name_multiple.out/Cargo.toml b/tests/snapshots/add/git_inferred_name_multiple.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/git_inferred_name_multiple.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/git_inferred_name_multiple.stderr b/tests/snapshots/add/git_inferred_name_multiple.stderr new file mode 100644 index 00000000000..829cc67b27a --- /dev/null +++ b/tests/snapshots/add/git_inferred_name_multiple.stderr @@ -0,0 +1,2 @@ + Updating git repository `[ROOTURL]/git-package` +error: multiple packages found at `[ROOTURL]/git-package`: my-package1, my-package2 diff --git a/tests/snapshots/add/git_inferred_name_multiple.stdout b/tests/snapshots/add/git_inferred_name_multiple.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/git_multiple_names.in b/tests/snapshots/add/git_multiple_names.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/git_multiple_names.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/git_multiple_names.out/Cargo.toml b/tests/snapshots/add/git_multiple_names.out/Cargo.toml new file mode 100644 index 00000000000..ba9d3c5ea05 --- /dev/null +++ b/tests/snapshots/add/git_multiple_names.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = { git = "[ROOTURL]/git-package", version = "0.3.0" } +my-package2 = { git = "[ROOTURL]/git-package", version = "0.3.0" } diff --git a/tests/snapshots/add/git_multiple_names.stderr b/tests/snapshots/add/git_multiple_names.stderr new file mode 100644 index 00000000000..e67710147da --- /dev/null +++ b/tests/snapshots/add/git_multiple_names.stderr @@ -0,0 +1,3 @@ + Updating git repository `[ROOTURL]/git-package` + Adding my-package1 (git) to dependencies. + Adding my-package2 (git) to dependencies. diff --git a/tests/snapshots/add/git_multiple_names.stdout b/tests/snapshots/add/git_multiple_names.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/git_normalized_name.in b/tests/snapshots/add/git_normalized_name.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/git_normalized_name.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/git_normalized_name.out/Cargo.toml b/tests/snapshots/add/git_normalized_name.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/git_normalized_name.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/git_normalized_name.stderr b/tests/snapshots/add/git_normalized_name.stderr new file mode 100644 index 00000000000..fedf82861c2 --- /dev/null +++ b/tests/snapshots/add/git_normalized_name.stderr @@ -0,0 +1,2 @@ + Updating git repository `[ROOTURL]/git-package` +error: the crate `git_package@[ROOTURL]/git-package` could not be found at `[ROOTURL]/git-package` diff --git a/tests/snapshots/add/git_normalized_name.stdout b/tests/snapshots/add/git_normalized_name.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/git_registry.in/Cargo.toml b/tests/snapshots/add/git_registry.in/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/git_registry.in/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/git_registry.in/src/lib.rs b/tests/snapshots/add/git_registry.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/git_registry.out/Cargo.toml b/tests/snapshots/add/git_registry.out/Cargo.toml new file mode 100644 index 00000000000..3773d1c8000 --- /dev/null +++ b/tests/snapshots/add/git_registry.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +versioned-package = { git = "[ROOTURL]/versioned-package", version = "0.3.0", registry = "alternative" } diff --git a/tests/snapshots/add/git_registry.stderr b/tests/snapshots/add/git_registry.stderr new file mode 100644 index 00000000000..548debfadf6 --- /dev/null +++ b/tests/snapshots/add/git_registry.stderr @@ -0,0 +1,2 @@ + Updating git repository `[ROOTURL]/versioned-package` + Adding versioned-package (git) to dependencies. diff --git a/tests/snapshots/add/git_registry.stdout b/tests/snapshots/add/git_registry.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/git_rev.in b/tests/snapshots/add/git_rev.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/git_rev.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/git_rev.out/Cargo.toml b/tests/snapshots/add/git_rev.out/Cargo.toml new file mode 100644 index 00000000000..efc00a01a2e --- /dev/null +++ b/tests/snapshots/add/git_rev.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +git-package = { git = "[ROOTURL]/git-package", rev = "[..]", version = "0.3.0" } diff --git a/tests/snapshots/add/git_rev.stderr b/tests/snapshots/add/git_rev.stderr new file mode 100644 index 00000000000..fdfb1a952a1 --- /dev/null +++ b/tests/snapshots/add/git_rev.stderr @@ -0,0 +1,2 @@ + Updating git repository `[ROOTURL]/git-package` + Adding git-package (git) to dependencies. diff --git a/tests/snapshots/add/git_rev.stdout b/tests/snapshots/add/git_rev.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/git_tag.in b/tests/snapshots/add/git_tag.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/git_tag.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/git_tag.out/Cargo.toml b/tests/snapshots/add/git_tag.out/Cargo.toml new file mode 100644 index 00000000000..233f26e655d --- /dev/null +++ b/tests/snapshots/add/git_tag.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +git-package = { git = "[ROOTURL]/git-package", tag = "v1.0.0", version = "0.3.0" } diff --git a/tests/snapshots/add/git_tag.stderr b/tests/snapshots/add/git_tag.stderr new file mode 100644 index 00000000000..fdfb1a952a1 --- /dev/null +++ b/tests/snapshots/add/git_tag.stderr @@ -0,0 +1,2 @@ + Updating git repository `[ROOTURL]/git-package` + Adding git-package (git) to dependencies. diff --git a/tests/snapshots/add/git_tag.stdout b/tests/snapshots/add/git_tag.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/infer_prerelease.in b/tests/snapshots/add/infer_prerelease.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/infer_prerelease.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/infer_prerelease.out/Cargo.toml b/tests/snapshots/add/infer_prerelease.out/Cargo.toml new file mode 100644 index 00000000000..4a86322add9 --- /dev/null +++ b/tests/snapshots/add/infer_prerelease.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +prerelease_only = "0.2.0-alpha.1" diff --git a/tests/snapshots/add/infer_prerelease.stderr b/tests/snapshots/add/infer_prerelease.stderr new file mode 100644 index 00000000000..0696d8f7b22 --- /dev/null +++ b/tests/snapshots/add/infer_prerelease.stderr @@ -0,0 +1,2 @@ + Updating `dummy-registry` index + Adding prerelease_only v0.2.0-alpha.1 to dependencies. diff --git a/tests/snapshots/add/infer_prerelease.stdout b/tests/snapshots/add/infer_prerelease.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/invalid_arg.in b/tests/snapshots/add/invalid_arg.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/invalid_arg.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/invalid_arg.out/Cargo.toml b/tests/snapshots/add/invalid_arg.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/invalid_arg.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/invalid_arg.stderr b/tests/snapshots/add/invalid_arg.stderr new file mode 100644 index 00000000000..d994681a416 --- /dev/null +++ b/tests/snapshots/add/invalid_arg.stderr @@ -0,0 +1,10 @@ +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 add [OPTIONS] [@] ... + cargo add [OPTIONS] --path ... + cargo add [OPTIONS] --git ... + +For more information try --help diff --git a/tests/snapshots/add/invalid_arg.stdout b/tests/snapshots/add/invalid_arg.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/invalid_git_external.in b/tests/snapshots/add/invalid_git_external.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/invalid_git_external.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/invalid_git_external.out/Cargo.toml b/tests/snapshots/add/invalid_git_external.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/invalid_git_external.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/invalid_git_external.stderr b/tests/snapshots/add/invalid_git_external.stderr new file mode 100644 index 00000000000..18656300b63 --- /dev/null +++ b/tests/snapshots/add/invalid_git_external.stderr @@ -0,0 +1,12 @@ + Updating git repository `[ROOTURL]/case/does-not-exist/` +... +error: failed to load source for dependency `fake-git` + +Caused by: + Unable to update [ROOTURL]/case/does-not-exist/ + +Caused by: + failed to clone into: [ROOT]/home/.cargo/git/db/does-not-exist-[..] + +Caused by: +... diff --git a/tests/snapshots/add/invalid_git_external.stdout b/tests/snapshots/add/invalid_git_external.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/invalid_git_name.in b/tests/snapshots/add/invalid_git_name.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/invalid_git_name.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/invalid_git_name.out/Cargo.toml b/tests/snapshots/add/invalid_git_name.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/invalid_git_name.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/invalid_git_name.stderr b/tests/snapshots/add/invalid_git_name.stderr new file mode 100644 index 00000000000..68fc4e49d77 --- /dev/null +++ b/tests/snapshots/add/invalid_git_name.stderr @@ -0,0 +1,2 @@ + Updating git repository `[ROOTURL]/git-package` +error: the crate `not-in-git@[ROOTURL]/git-package` could not be found at `[ROOTURL]/git-package` diff --git a/tests/snapshots/add/invalid_git_name.stdout b/tests/snapshots/add/invalid_git_name.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/invalid_manifest.in/Cargo.toml b/tests/snapshots/add/invalid_manifest.in/Cargo.toml new file mode 100644 index 00000000000..94ee95994f4 --- /dev/null +++ b/tests/snapshots/add/invalid_manifest.in/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "manifest-invalid-test-fixture" +version = "0.1.0" + +[invalid-section] +key = invalid-value diff --git a/tests/snapshots/add/invalid_manifest.in/src/lib.rs b/tests/snapshots/add/invalid_manifest.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/invalid_manifest.out/Cargo.toml b/tests/snapshots/add/invalid_manifest.out/Cargo.toml new file mode 100644 index 00000000000..94ee95994f4 --- /dev/null +++ b/tests/snapshots/add/invalid_manifest.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "manifest-invalid-test-fixture" +version = "0.1.0" + +[invalid-section] +key = invalid-value diff --git a/tests/snapshots/add/invalid_manifest.stderr b/tests/snapshots/add/invalid_manifest.stderr new file mode 100644 index 00000000000..83bfc5e4eaa --- /dev/null +++ b/tests/snapshots/add/invalid_manifest.stderr @@ -0,0 +1,11 @@ +error: failed to parse manifest at `[ROOT]/case/Cargo.toml` + +Caused by: + could not parse input as TOML + +Caused by: + TOML parse error at line 8, column 7 + | + 8 | key = invalid-value + | ^ + Unexpected `v` diff --git a/tests/snapshots/add/invalid_manifest.stdout b/tests/snapshots/add/invalid_manifest.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/invalid_name_external.in b/tests/snapshots/add/invalid_name_external.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/invalid_name_external.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/invalid_name_external.out/Cargo.toml b/tests/snapshots/add/invalid_name_external.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/invalid_name_external.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/invalid_name_external.stderr b/tests/snapshots/add/invalid_name_external.stderr new file mode 100644 index 00000000000..5e574cedad0 --- /dev/null +++ b/tests/snapshots/add/invalid_name_external.stderr @@ -0,0 +1,2 @@ + Updating `dummy-registry` index +error: the crate `lets_hope_nobody_ever_publishes_this_crate` could not be found in registry index. diff --git a/tests/snapshots/add/invalid_name_external.stdout b/tests/snapshots/add/invalid_name_external.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/invalid_path.in b/tests/snapshots/add/invalid_path.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/invalid_path.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/invalid_path.out/Cargo.toml b/tests/snapshots/add/invalid_path.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/invalid_path.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/invalid_path.stderr b/tests/snapshots/add/invalid_path.stderr new file mode 100644 index 00000000000..f6c40433062 --- /dev/null +++ b/tests/snapshots/add/invalid_path.stderr @@ -0,0 +1,10 @@ +error: failed to load source for dependency `cargo-list-test-fixture` + +Caused by: + Unable to update [ROOT]/case/tests/fixtures/local + +Caused by: + failed to read `[ROOT]/case/tests/fixtures/local/Cargo.toml` + +Caused by: + [..] diff --git a/tests/snapshots/add/invalid_path.stdout b/tests/snapshots/add/invalid_path.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/invalid_path_name.in/dependency/Cargo.toml b/tests/snapshots/add/invalid_path_name.in/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/invalid_path_name.in/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/invalid_path_name.in/dependency/src/lib.rs b/tests/snapshots/add/invalid_path_name.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/invalid_path_name.in/primary/Cargo.toml b/tests/snapshots/add/invalid_path_name.in/primary/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/invalid_path_name.in/primary/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/invalid_path_name.in/primary/src/lib.rs b/tests/snapshots/add/invalid_path_name.in/primary/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/invalid_path_name.out/dependency/Cargo.toml b/tests/snapshots/add/invalid_path_name.out/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/invalid_path_name.out/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/invalid_path_name.out/primary/Cargo.toml b/tests/snapshots/add/invalid_path_name.out/primary/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/invalid_path_name.out/primary/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/invalid_path_name.stderr b/tests/snapshots/add/invalid_path_name.stderr new file mode 100644 index 00000000000..b35ea823377 --- /dev/null +++ b/tests/snapshots/add/invalid_path_name.stderr @@ -0,0 +1 @@ +error: the crate `not-at-path@[ROOT]/case/dependency` could not be found at `[ROOT]/case/dependency` diff --git a/tests/snapshots/add/invalid_path_name.stdout b/tests/snapshots/add/invalid_path_name.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/invalid_path_self.in b/tests/snapshots/add/invalid_path_self.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/invalid_path_self.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/invalid_path_self.out/Cargo.toml b/tests/snapshots/add/invalid_path_self.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/invalid_path_self.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/invalid_path_self.stderr b/tests/snapshots/add/invalid_path_self.stderr new file mode 100644 index 00000000000..62a25dbb42a --- /dev/null +++ b/tests/snapshots/add/invalid_path_self.stderr @@ -0,0 +1,2 @@ + Adding cargo-list-test-fixture (local) to dependencies. +error: cannot add `cargo-list-test-fixture` as a dependency to itself diff --git a/tests/snapshots/add/invalid_path_self.stdout b/tests/snapshots/add/invalid_path_self.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/invalid_target_empty.in b/tests/snapshots/add/invalid_target_empty.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/invalid_target_empty.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/invalid_target_empty.out/Cargo.toml b/tests/snapshots/add/invalid_target_empty.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/invalid_target_empty.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/invalid_target_empty.stderr b/tests/snapshots/add/invalid_target_empty.stderr new file mode 100644 index 00000000000..44aad058cbc --- /dev/null +++ b/tests/snapshots/add/invalid_target_empty.stderr @@ -0,0 +1,8 @@ +error: The argument '--target ' requires a value but none was supplied + +USAGE: + cargo add [OPTIONS] [@] ... + cargo add [OPTIONS] --path ... + cargo add [OPTIONS] --git ... + +For more information try --help diff --git a/tests/snapshots/add/invalid_target_empty.stdout b/tests/snapshots/add/invalid_target_empty.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/invalid_vers.in b/tests/snapshots/add/invalid_vers.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/invalid_vers.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/invalid_vers.out/Cargo.toml b/tests/snapshots/add/invalid_vers.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/invalid_vers.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/invalid_vers.stderr b/tests/snapshots/add/invalid_vers.stderr new file mode 100644 index 00000000000..13a110305ea --- /dev/null +++ b/tests/snapshots/add/invalid_vers.stderr @@ -0,0 +1,4 @@ +error: invalid version requirement `invalid version string` + +Caused by: + unexpected character 'i' while parsing major version number diff --git a/tests/snapshots/add/invalid_vers.stdout b/tests/snapshots/add/invalid_vers.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/list_features.in b/tests/snapshots/add/list_features.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/list_features.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/list_features.out/Cargo.toml b/tests/snapshots/add/list_features.out/Cargo.toml new file mode 100644 index 00000000000..79d735a12d4 --- /dev/null +++ b/tests/snapshots/add/list_features.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = "99999.0.0" diff --git a/tests/snapshots/add/list_features.stderr b/tests/snapshots/add/list_features.stderr new file mode 100644 index 00000000000..796b9601b4d --- /dev/null +++ b/tests/snapshots/add/list_features.stderr @@ -0,0 +1,7 @@ + Updating `dummy-registry` index + Adding your-face v99999.0.0 to dependencies. + Features: + - ears + - eyes + - mouth + - nose diff --git a/tests/snapshots/add/list_features.stdout b/tests/snapshots/add/list_features.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/list_features_path.in/Cargo.toml b/tests/snapshots/add/list_features_path.in/Cargo.toml new file mode 100644 index 00000000000..299859e79df --- /dev/null +++ b/tests/snapshots/add/list_features_path.in/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["primary", "dependency", "optional"] diff --git a/tests/snapshots/add/list_features_path.in/dependency/Cargo.toml b/tests/snapshots/add/list_features_path.in/dependency/Cargo.toml new file mode 100644 index 00000000000..34157f41182 --- /dev/null +++ b/tests/snapshots/add/list_features_path.in/dependency/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "your-face" +version = "0.1.3" + +[dependencies] +toml_edit = "0.1.5" +atty = "0.2.13" +optional-dependency = { path = "../optional", optional = true } + +[features] +default = ["mouth"] +nose = [] +mouth = ["nose"] +eyes = [] diff --git a/tests/snapshots/add/list_features_path.in/dependency/src/lib.rs b/tests/snapshots/add/list_features_path.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/list_features_path.in/optional/Cargo.toml b/tests/snapshots/add/list_features_path.in/optional/Cargo.toml new file mode 100644 index 00000000000..0216dba8987 --- /dev/null +++ b/tests/snapshots/add/list_features_path.in/optional/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "optional-dep" +version = "0.1.3" + +[dependencies] +toml_edit = "0.1.5" +atty = "0.2.13" diff --git a/tests/snapshots/add/list_features_path.in/optional/src/lib.rs b/tests/snapshots/add/list_features_path.in/optional/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/list_features_path.in/primary/Cargo.toml b/tests/snapshots/add/list_features_path.in/primary/Cargo.toml new file mode 100644 index 00000000000..5e20016d710 --- /dev/null +++ b/tests/snapshots/add/list_features_path.in/primary/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/list_features_path.in/primary/src/lib.rs b/tests/snapshots/add/list_features_path.in/primary/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/list_features_path.out/Cargo.toml b/tests/snapshots/add/list_features_path.out/Cargo.toml new file mode 100644 index 00000000000..299859e79df --- /dev/null +++ b/tests/snapshots/add/list_features_path.out/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["primary", "dependency", "optional"] diff --git a/tests/snapshots/add/list_features_path.out/dependency/Cargo.toml b/tests/snapshots/add/list_features_path.out/dependency/Cargo.toml new file mode 100644 index 00000000000..34157f41182 --- /dev/null +++ b/tests/snapshots/add/list_features_path.out/dependency/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "your-face" +version = "0.1.3" + +[dependencies] +toml_edit = "0.1.5" +atty = "0.2.13" +optional-dependency = { path = "../optional", optional = true } + +[features] +default = ["mouth"] +nose = [] +mouth = ["nose"] +eyes = [] diff --git a/tests/snapshots/add/list_features_path.out/primary/Cargo.toml b/tests/snapshots/add/list_features_path.out/primary/Cargo.toml new file mode 100644 index 00000000000..2461d0932d4 --- /dev/null +++ b/tests/snapshots/add/list_features_path.out/primary/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = { version = "0.1.3", path = "../dependency" } diff --git a/tests/snapshots/add/list_features_path.stderr b/tests/snapshots/add/list_features_path.stderr new file mode 100644 index 00000000000..27378049be0 --- /dev/null +++ b/tests/snapshots/add/list_features_path.stderr @@ -0,0 +1,6 @@ + Adding your-face (local) to dependencies. + Features: + + mouth + + nose + - eyes + - optional-dependency diff --git a/tests/snapshots/add/list_features_path.stdout b/tests/snapshots/add/list_features_path.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/list_features_path_no_default.in/Cargo.toml b/tests/snapshots/add/list_features_path_no_default.in/Cargo.toml new file mode 100644 index 00000000000..299859e79df --- /dev/null +++ b/tests/snapshots/add/list_features_path_no_default.in/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["primary", "dependency", "optional"] diff --git a/tests/snapshots/add/list_features_path_no_default.in/dependency/Cargo.toml b/tests/snapshots/add/list_features_path_no_default.in/dependency/Cargo.toml new file mode 100644 index 00000000000..34157f41182 --- /dev/null +++ b/tests/snapshots/add/list_features_path_no_default.in/dependency/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "your-face" +version = "0.1.3" + +[dependencies] +toml_edit = "0.1.5" +atty = "0.2.13" +optional-dependency = { path = "../optional", optional = true } + +[features] +default = ["mouth"] +nose = [] +mouth = ["nose"] +eyes = [] diff --git a/tests/snapshots/add/list_features_path_no_default.in/dependency/src/lib.rs b/tests/snapshots/add/list_features_path_no_default.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/list_features_path_no_default.in/optional/Cargo.toml b/tests/snapshots/add/list_features_path_no_default.in/optional/Cargo.toml new file mode 100644 index 00000000000..0216dba8987 --- /dev/null +++ b/tests/snapshots/add/list_features_path_no_default.in/optional/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "optional-dep" +version = "0.1.3" + +[dependencies] +toml_edit = "0.1.5" +atty = "0.2.13" diff --git a/tests/snapshots/add/list_features_path_no_default.in/optional/src/lib.rs b/tests/snapshots/add/list_features_path_no_default.in/optional/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/list_features_path_no_default.in/primary/Cargo.toml b/tests/snapshots/add/list_features_path_no_default.in/primary/Cargo.toml new file mode 100644 index 00000000000..5e20016d710 --- /dev/null +++ b/tests/snapshots/add/list_features_path_no_default.in/primary/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/list_features_path_no_default.in/primary/src/lib.rs b/tests/snapshots/add/list_features_path_no_default.in/primary/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/list_features_path_no_default.out/Cargo.toml b/tests/snapshots/add/list_features_path_no_default.out/Cargo.toml new file mode 100644 index 00000000000..299859e79df --- /dev/null +++ b/tests/snapshots/add/list_features_path_no_default.out/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["primary", "dependency", "optional"] diff --git a/tests/snapshots/add/list_features_path_no_default.out/dependency/Cargo.toml b/tests/snapshots/add/list_features_path_no_default.out/dependency/Cargo.toml new file mode 100644 index 00000000000..34157f41182 --- /dev/null +++ b/tests/snapshots/add/list_features_path_no_default.out/dependency/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "your-face" +version = "0.1.3" + +[dependencies] +toml_edit = "0.1.5" +atty = "0.2.13" +optional-dependency = { path = "../optional", optional = true } + +[features] +default = ["mouth"] +nose = [] +mouth = ["nose"] +eyes = [] diff --git a/tests/snapshots/add/list_features_path_no_default.out/primary/Cargo.toml b/tests/snapshots/add/list_features_path_no_default.out/primary/Cargo.toml new file mode 100644 index 00000000000..0b0400d51fa --- /dev/null +++ b/tests/snapshots/add/list_features_path_no_default.out/primary/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = { version = "0.1.3", path = "../dependency", default-features = false } diff --git a/tests/snapshots/add/list_features_path_no_default.stderr b/tests/snapshots/add/list_features_path_no_default.stderr new file mode 100644 index 00000000000..cc6c8346279 --- /dev/null +++ b/tests/snapshots/add/list_features_path_no_default.stderr @@ -0,0 +1,6 @@ + Adding your-face (local) to dependencies. + Features: + - eyes + - mouth + - nose + - optional-dependency diff --git a/tests/snapshots/add/list_features_path_no_default.stdout b/tests/snapshots/add/list_features_path_no_default.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/manifest_path_package.in/Cargo.toml b/tests/snapshots/add/manifest_path_package.in/Cargo.toml new file mode 100644 index 00000000000..57e1f30855f --- /dev/null +++ b/tests/snapshots/add/manifest_path_package.in/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["primary", "dependency"] diff --git a/tests/snapshots/add/manifest_path_package.in/dependency/Cargo.toml b/tests/snapshots/add/manifest_path_package.in/dependency/Cargo.toml new file mode 100644 index 00000000000..ca4f36d72f7 --- /dev/null +++ b/tests/snapshots/add/manifest_path_package.in/dependency/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/manifest_path_package.in/dependency/src/lib.rs b/tests/snapshots/add/manifest_path_package.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/manifest_path_package.in/primary/Cargo.toml b/tests/snapshots/add/manifest_path_package.in/primary/Cargo.toml new file mode 100644 index 00000000000..5e20016d710 --- /dev/null +++ b/tests/snapshots/add/manifest_path_package.in/primary/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/manifest_path_package.in/primary/src/lib.rs b/tests/snapshots/add/manifest_path_package.in/primary/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/manifest_path_package.out/Cargo.toml b/tests/snapshots/add/manifest_path_package.out/Cargo.toml new file mode 100644 index 00000000000..57e1f30855f --- /dev/null +++ b/tests/snapshots/add/manifest_path_package.out/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["primary", "dependency"] diff --git a/tests/snapshots/add/manifest_path_package.out/dependency/Cargo.toml b/tests/snapshots/add/manifest_path_package.out/dependency/Cargo.toml new file mode 100644 index 00000000000..ca4f36d72f7 --- /dev/null +++ b/tests/snapshots/add/manifest_path_package.out/dependency/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/manifest_path_package.out/primary/Cargo.toml b/tests/snapshots/add/manifest_path_package.out/primary/Cargo.toml new file mode 100644 index 00000000000..a693df54f88 --- /dev/null +++ b/tests/snapshots/add/manifest_path_package.out/primary/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +cargo-list-test-fixture-dependency = { version = "0.0.0", path = "../dependency" } diff --git a/tests/snapshots/add/manifest_path_package.stderr b/tests/snapshots/add/manifest_path_package.stderr new file mode 100644 index 00000000000..8109d3cc54b --- /dev/null +++ b/tests/snapshots/add/manifest_path_package.stderr @@ -0,0 +1 @@ + Adding cargo-list-test-fixture-dependency (local) to dependencies. diff --git a/tests/snapshots/add/manifest_path_package.stdout b/tests/snapshots/add/manifest_path_package.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/multiple_conflicts_with_features.in b/tests/snapshots/add/multiple_conflicts_with_features.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/multiple_conflicts_with_features.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/multiple_conflicts_with_features.out/Cargo.toml b/tests/snapshots/add/multiple_conflicts_with_features.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/multiple_conflicts_with_features.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/multiple_conflicts_with_features.stderr b/tests/snapshots/add/multiple_conflicts_with_features.stderr new file mode 100644 index 00000000000..60a6961e60c --- /dev/null +++ b/tests/snapshots/add/multiple_conflicts_with_features.stderr @@ -0,0 +1 @@ +error: feature `nose` must be qualified by the dependency its being activated for, like `my-package1/nose`, `your-face/nose` diff --git a/tests/snapshots/add/multiple_conflicts_with_features.stdout b/tests/snapshots/add/multiple_conflicts_with_features.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/multiple_conflicts_with_rename.in b/tests/snapshots/add/multiple_conflicts_with_rename.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/multiple_conflicts_with_rename.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/multiple_conflicts_with_rename.out/Cargo.toml b/tests/snapshots/add/multiple_conflicts_with_rename.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/multiple_conflicts_with_rename.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/multiple_conflicts_with_rename.stderr b/tests/snapshots/add/multiple_conflicts_with_rename.stderr new file mode 100644 index 00000000000..e83250e7389 --- /dev/null +++ b/tests/snapshots/add/multiple_conflicts_with_rename.stderr @@ -0,0 +1 @@ +error: cannot specify multiple crates with `--rename` diff --git a/tests/snapshots/add/multiple_conflicts_with_rename.stdout b/tests/snapshots/add/multiple_conflicts_with_rename.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/namever.in b/tests/snapshots/add/namever.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/namever.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/namever.out/Cargo.toml b/tests/snapshots/add/namever.out/Cargo.toml new file mode 100644 index 00000000000..1704d3435d1 --- /dev/null +++ b/tests/snapshots/add/namever.out/Cargo.toml @@ -0,0 +1,10 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package = "99999.0.0" +my-package1 = ">=0.1.1" +my-package2 = "0.2.3" diff --git a/tests/snapshots/add/namever.stderr b/tests/snapshots/add/namever.stderr new file mode 100644 index 00000000000..17be8f9d8d9 --- /dev/null +++ b/tests/snapshots/add/namever.stderr @@ -0,0 +1,4 @@ + Updating `dummy-registry` index + Adding my-package1 >=0.1.1 to dependencies. + Adding my-package2 v0.2.3 to dependencies. + Adding my-package v99999.0.0 to dependencies. diff --git a/tests/snapshots/add/namever.stdout b/tests/snapshots/add/namever.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/no_args.in b/tests/snapshots/add/no_args.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/no_args.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/no_args.out/Cargo.toml b/tests/snapshots/add/no_args.out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/no_args.out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/no_args.stderr b/tests/snapshots/add/no_args.stderr new file mode 100644 index 00000000000..a046b3f3f4a --- /dev/null +++ b/tests/snapshots/add/no_args.stderr @@ -0,0 +1,9 @@ +error: The following required arguments were not provided: + |--git > + +USAGE: + cargo add [OPTIONS] [@] ... + cargo add [OPTIONS] --path ... + cargo add [OPTIONS] --git ... + +For more information try --help diff --git a/tests/snapshots/add/no_args.stdout b/tests/snapshots/add/no_args.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/no_default_features.in b/tests/snapshots/add/no_default_features.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/no_default_features.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/no_default_features.out/Cargo.toml b/tests/snapshots/add/no_default_features.out/Cargo.toml new file mode 100644 index 00000000000..ddd02b1f050 --- /dev/null +++ b/tests/snapshots/add/no_default_features.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = { version = "99999.0.0", default-features = false } +my-package2 = { version = "0.4.1", default-features = false } diff --git a/tests/snapshots/add/no_default_features.stderr b/tests/snapshots/add/no_default_features.stderr new file mode 100644 index 00000000000..fb8d4903d7b --- /dev/null +++ b/tests/snapshots/add/no_default_features.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package1 v99999.0.0 to dependencies. + Adding my-package2 v0.4.1 to dependencies. diff --git a/tests/snapshots/add/no_default_features.stdout b/tests/snapshots/add/no_default_features.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/no_optional.in b/tests/snapshots/add/no_optional.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/no_optional.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/no_optional.out/Cargo.toml b/tests/snapshots/add/no_optional.out/Cargo.toml new file mode 100644 index 00000000000..c5e01789281 --- /dev/null +++ b/tests/snapshots/add/no_optional.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = "99999.0.0" +my-package2 = "0.4.1" diff --git a/tests/snapshots/add/no_optional.stderr b/tests/snapshots/add/no_optional.stderr new file mode 100644 index 00000000000..fb8d4903d7b --- /dev/null +++ b/tests/snapshots/add/no_optional.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package1 v99999.0.0 to dependencies. + Adding my-package2 v0.4.1 to dependencies. diff --git a/tests/snapshots/add/no_optional.stdout b/tests/snapshots/add/no_optional.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/optional.in b/tests/snapshots/add/optional.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/optional.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/optional.out/Cargo.toml b/tests/snapshots/add/optional.out/Cargo.toml new file mode 100644 index 00000000000..eda5445c50f --- /dev/null +++ b/tests/snapshots/add/optional.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = { version = "99999.0.0", optional = true } +my-package2 = { version = "0.4.1", optional = true } diff --git a/tests/snapshots/add/optional.stderr b/tests/snapshots/add/optional.stderr new file mode 100644 index 00000000000..8cf4812cf17 --- /dev/null +++ b/tests/snapshots/add/optional.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package1 v99999.0.0 to optional dependencies. + Adding my-package2 v0.4.1 to optional dependencies. diff --git a/tests/snapshots/add/optional.stdout b/tests/snapshots/add/optional.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_default_features.in/Cargo.toml b/tests/snapshots/add/overwrite_default_features.in/Cargo.toml new file mode 100644 index 00000000000..c5e01789281 --- /dev/null +++ b/tests/snapshots/add/overwrite_default_features.in/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = "99999.0.0" +my-package2 = "0.4.1" diff --git a/tests/snapshots/add/overwrite_default_features.in/src/lib.rs b/tests/snapshots/add/overwrite_default_features.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_default_features.out/Cargo.toml b/tests/snapshots/add/overwrite_default_features.out/Cargo.toml new file mode 100644 index 00000000000..c5e01789281 --- /dev/null +++ b/tests/snapshots/add/overwrite_default_features.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = "99999.0.0" +my-package2 = "0.4.1" diff --git a/tests/snapshots/add/overwrite_default_features.stderr b/tests/snapshots/add/overwrite_default_features.stderr new file mode 100644 index 00000000000..fb8d4903d7b --- /dev/null +++ b/tests/snapshots/add/overwrite_default_features.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package1 v99999.0.0 to dependencies. + Adding my-package2 v0.4.1 to dependencies. diff --git a/tests/snapshots/add/overwrite_default_features.stdout b/tests/snapshots/add/overwrite_default_features.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_default_features_with_no_default_features.in/Cargo.toml b/tests/snapshots/add/overwrite_default_features_with_no_default_features.in/Cargo.toml new file mode 100644 index 00000000000..73f56a7a321 --- /dev/null +++ b/tests/snapshots/add/overwrite_default_features_with_no_default_features.in/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = { version = "99999.0.0", default-features = true } +my-package2 = { version = "0.4.1", default-features = true } diff --git a/tests/snapshots/add/overwrite_default_features_with_no_default_features.in/src/lib.rs b/tests/snapshots/add/overwrite_default_features_with_no_default_features.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_default_features_with_no_default_features.out/Cargo.toml b/tests/snapshots/add/overwrite_default_features_with_no_default_features.out/Cargo.toml new file mode 100644 index 00000000000..ddd02b1f050 --- /dev/null +++ b/tests/snapshots/add/overwrite_default_features_with_no_default_features.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = { version = "99999.0.0", default-features = false } +my-package2 = { version = "0.4.1", default-features = false } diff --git a/tests/snapshots/add/overwrite_default_features_with_no_default_features.stderr b/tests/snapshots/add/overwrite_default_features_with_no_default_features.stderr new file mode 100644 index 00000000000..fb8d4903d7b --- /dev/null +++ b/tests/snapshots/add/overwrite_default_features_with_no_default_features.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package1 v99999.0.0 to dependencies. + Adding my-package2 v0.4.1 to dependencies. diff --git a/tests/snapshots/add/overwrite_default_features_with_no_default_features.stdout b/tests/snapshots/add/overwrite_default_features_with_no_default_features.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_features.in/Cargo.toml b/tests/snapshots/add/overwrite_features.in/Cargo.toml new file mode 100644 index 00000000000..11419b20363 --- /dev/null +++ b/tests/snapshots/add/overwrite_features.in/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = { version = "99999.0.0", features = ["eyes"] } diff --git a/tests/snapshots/add/overwrite_features.in/src/lib.rs b/tests/snapshots/add/overwrite_features.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_features.out/Cargo.toml b/tests/snapshots/add/overwrite_features.out/Cargo.toml new file mode 100644 index 00000000000..0060d24bcbc --- /dev/null +++ b/tests/snapshots/add/overwrite_features.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = { version = "99999.0.0", features = ["eyes", "nose"] } diff --git a/tests/snapshots/add/overwrite_features.stderr b/tests/snapshots/add/overwrite_features.stderr new file mode 100644 index 00000000000..615459052e4 --- /dev/null +++ b/tests/snapshots/add/overwrite_features.stderr @@ -0,0 +1,7 @@ + Updating `dummy-registry` index + Adding your-face v99999.0.0 to dependencies. + Features: + + eyes + + nose + - ears + - mouth diff --git a/tests/snapshots/add/overwrite_features.stdout b/tests/snapshots/add/overwrite_features.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_git_with_path.in/dependency/Cargo.toml b/tests/snapshots/add/overwrite_git_with_path.in/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/overwrite_git_with_path.in/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/overwrite_git_with_path.in/dependency/src/lib.rs b/tests/snapshots/add/overwrite_git_with_path.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_git_with_path.in/primary/Cargo.toml b/tests/snapshots/add/overwrite_git_with_path.in/primary/Cargo.toml new file mode 100644 index 00000000000..6cb4d6a7d6d --- /dev/null +++ b/tests/snapshots/add/overwrite_git_with_path.in/primary/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +cargo-list-test-fixture-dependency = { git = "git://git.git", branch = "main", optional = true } diff --git a/tests/snapshots/add/overwrite_git_with_path.in/primary/src/lib.rs b/tests/snapshots/add/overwrite_git_with_path.in/primary/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_git_with_path.out/dependency/Cargo.toml b/tests/snapshots/add/overwrite_git_with_path.out/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/overwrite_git_with_path.out/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/overwrite_git_with_path.out/primary/Cargo.toml b/tests/snapshots/add/overwrite_git_with_path.out/primary/Cargo.toml new file mode 100644 index 00000000000..ad120548123 --- /dev/null +++ b/tests/snapshots/add/overwrite_git_with_path.out/primary/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +cargo-list-test-fixture-dependency = { optional = true, path = "../dependency", version = "0.0.0" } diff --git a/tests/snapshots/add/overwrite_git_with_path.stderr b/tests/snapshots/add/overwrite_git_with_path.stderr new file mode 100644 index 00000000000..98abcfc99e4 --- /dev/null +++ b/tests/snapshots/add/overwrite_git_with_path.stderr @@ -0,0 +1 @@ + Adding cargo-list-test-fixture-dependency (local) to optional dependencies. diff --git a/tests/snapshots/add/overwrite_git_with_path.stdout b/tests/snapshots/add/overwrite_git_with_path.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_inline_features.in/Cargo.toml b/tests/snapshots/add/overwrite_inline_features.in/Cargo.toml new file mode 100644 index 00000000000..11419b20363 --- /dev/null +++ b/tests/snapshots/add/overwrite_inline_features.in/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = { version = "99999.0.0", features = ["eyes"] } diff --git a/tests/snapshots/add/overwrite_inline_features.in/src/lib.rs b/tests/snapshots/add/overwrite_inline_features.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_inline_features.out/Cargo.toml b/tests/snapshots/add/overwrite_inline_features.out/Cargo.toml new file mode 100644 index 00000000000..8e9579dc65e --- /dev/null +++ b/tests/snapshots/add/overwrite_inline_features.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +unrelateed-crate = "99999.0.0" +your-face = { version = "99999.0.0", features = ["eyes", "nose", "mouth", "ears"] } diff --git a/tests/snapshots/add/overwrite_inline_features.stderr b/tests/snapshots/add/overwrite_inline_features.stderr new file mode 100644 index 00000000000..a686cba55d5 --- /dev/null +++ b/tests/snapshots/add/overwrite_inline_features.stderr @@ -0,0 +1,8 @@ + Updating `dummy-registry` index + Adding unrelateed-crate v99999.0.0 to dependencies. + Adding your-face v99999.0.0 to dependencies. + Features: + + ears + + eyes + + mouth + + nose diff --git a/tests/snapshots/add/overwrite_inline_features.stdout b/tests/snapshots/add/overwrite_inline_features.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_name_dev_noop.in/Cargo.toml b/tests/snapshots/add/overwrite_name_dev_noop.in/Cargo.toml new file mode 100644 index 00000000000..b69b5d38e76 --- /dev/null +++ b/tests/snapshots/add/overwrite_name_dev_noop.in/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] +exclude = ["dependency"] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dev-dependencies] +your-face = { version = "0.0.0", path = "dependency", default-features = false, features = ["nose", "mouth"], registry = "alternative" } diff --git a/tests/snapshots/add/overwrite_name_dev_noop.in/dependency/Cargo.toml b/tests/snapshots/add/overwrite_name_dev_noop.in/dependency/Cargo.toml new file mode 100644 index 00000000000..8243797eb0a --- /dev/null +++ b/tests/snapshots/add/overwrite_name_dev_noop.in/dependency/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "your-face" +version = "0.0.0" + +[features] +mouth = [] +nose = [] diff --git a/tests/snapshots/add/overwrite_name_dev_noop.in/dependency/src/lib.rs b/tests/snapshots/add/overwrite_name_dev_noop.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_name_dev_noop.in/src/lib.rs b/tests/snapshots/add/overwrite_name_dev_noop.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_name_dev_noop.out/Cargo.toml b/tests/snapshots/add/overwrite_name_dev_noop.out/Cargo.toml new file mode 100644 index 00000000000..b69b5d38e76 --- /dev/null +++ b/tests/snapshots/add/overwrite_name_dev_noop.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] +exclude = ["dependency"] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dev-dependencies] +your-face = { version = "0.0.0", path = "dependency", default-features = false, features = ["nose", "mouth"], registry = "alternative" } diff --git a/tests/snapshots/add/overwrite_name_dev_noop.out/dependency/Cargo.toml b/tests/snapshots/add/overwrite_name_dev_noop.out/dependency/Cargo.toml new file mode 100644 index 00000000000..8243797eb0a --- /dev/null +++ b/tests/snapshots/add/overwrite_name_dev_noop.out/dependency/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "your-face" +version = "0.0.0" + +[features] +mouth = [] +nose = [] diff --git a/tests/snapshots/add/overwrite_name_dev_noop.stderr b/tests/snapshots/add/overwrite_name_dev_noop.stderr new file mode 100644 index 00000000000..2fe3f6a2906 --- /dev/null +++ b/tests/snapshots/add/overwrite_name_dev_noop.stderr @@ -0,0 +1,4 @@ + Adding your-face (local) to dev-dependencies. + Features: + + mouth + + nose diff --git a/tests/snapshots/add/overwrite_name_dev_noop.stdout b/tests/snapshots/add/overwrite_name_dev_noop.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_name_noop.in/Cargo.toml b/tests/snapshots/add/overwrite_name_noop.in/Cargo.toml new file mode 100644 index 00000000000..bbaf4f5521c --- /dev/null +++ b/tests/snapshots/add/overwrite_name_noop.in/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] +exclude = ["dependency"] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = { version = "0.0.0", path = "dependency", optional = true, default-features = false, features = ["nose", "mouth"], registry = "alternative" } diff --git a/tests/snapshots/add/overwrite_name_noop.in/dependency/Cargo.toml b/tests/snapshots/add/overwrite_name_noop.in/dependency/Cargo.toml new file mode 100644 index 00000000000..8243797eb0a --- /dev/null +++ b/tests/snapshots/add/overwrite_name_noop.in/dependency/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "your-face" +version = "0.0.0" + +[features] +mouth = [] +nose = [] diff --git a/tests/snapshots/add/overwrite_name_noop.in/dependency/src/lib.rs b/tests/snapshots/add/overwrite_name_noop.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_name_noop.in/src/lib.rs b/tests/snapshots/add/overwrite_name_noop.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_name_noop.out/Cargo.toml b/tests/snapshots/add/overwrite_name_noop.out/Cargo.toml new file mode 100644 index 00000000000..bbaf4f5521c --- /dev/null +++ b/tests/snapshots/add/overwrite_name_noop.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] +exclude = ["dependency"] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = { version = "0.0.0", path = "dependency", optional = true, default-features = false, features = ["nose", "mouth"], registry = "alternative" } diff --git a/tests/snapshots/add/overwrite_name_noop.out/dependency/Cargo.toml b/tests/snapshots/add/overwrite_name_noop.out/dependency/Cargo.toml new file mode 100644 index 00000000000..8243797eb0a --- /dev/null +++ b/tests/snapshots/add/overwrite_name_noop.out/dependency/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "your-face" +version = "0.0.0" + +[features] +mouth = [] +nose = [] diff --git a/tests/snapshots/add/overwrite_name_noop.stderr b/tests/snapshots/add/overwrite_name_noop.stderr new file mode 100644 index 00000000000..2f0b90de0d2 --- /dev/null +++ b/tests/snapshots/add/overwrite_name_noop.stderr @@ -0,0 +1,4 @@ + Adding your-face (local) to optional dependencies. + Features: + + mouth + + nose diff --git a/tests/snapshots/add/overwrite_name_noop.stdout b/tests/snapshots/add/overwrite_name_noop.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_no_default_features.in/Cargo.toml b/tests/snapshots/add/overwrite_no_default_features.in/Cargo.toml new file mode 100644 index 00000000000..c5e01789281 --- /dev/null +++ b/tests/snapshots/add/overwrite_no_default_features.in/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = "99999.0.0" +my-package2 = "0.4.1" diff --git a/tests/snapshots/add/overwrite_no_default_features.in/src/lib.rs b/tests/snapshots/add/overwrite_no_default_features.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_no_default_features.out/Cargo.toml b/tests/snapshots/add/overwrite_no_default_features.out/Cargo.toml new file mode 100644 index 00000000000..ddd02b1f050 --- /dev/null +++ b/tests/snapshots/add/overwrite_no_default_features.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = { version = "99999.0.0", default-features = false } +my-package2 = { version = "0.4.1", default-features = false } diff --git a/tests/snapshots/add/overwrite_no_default_features.stderr b/tests/snapshots/add/overwrite_no_default_features.stderr new file mode 100644 index 00000000000..fb8d4903d7b --- /dev/null +++ b/tests/snapshots/add/overwrite_no_default_features.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package1 v99999.0.0 to dependencies. + Adding my-package2 v0.4.1 to dependencies. diff --git a/tests/snapshots/add/overwrite_no_default_features.stdout b/tests/snapshots/add/overwrite_no_default_features.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_no_default_features_with_default_features.in/Cargo.toml b/tests/snapshots/add/overwrite_no_default_features_with_default_features.in/Cargo.toml new file mode 100644 index 00000000000..ddd02b1f050 --- /dev/null +++ b/tests/snapshots/add/overwrite_no_default_features_with_default_features.in/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = { version = "99999.0.0", default-features = false } +my-package2 = { version = "0.4.1", default-features = false } diff --git a/tests/snapshots/add/overwrite_no_default_features_with_default_features.in/src/lib.rs b/tests/snapshots/add/overwrite_no_default_features_with_default_features.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_no_default_features_with_default_features.out/Cargo.toml b/tests/snapshots/add/overwrite_no_default_features_with_default_features.out/Cargo.toml new file mode 100644 index 00000000000..b9e8985c6d4 --- /dev/null +++ b/tests/snapshots/add/overwrite_no_default_features_with_default_features.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = { version = "99999.0.0" } +my-package2 = { version = "0.4.1" } diff --git a/tests/snapshots/add/overwrite_no_default_features_with_default_features.stderr b/tests/snapshots/add/overwrite_no_default_features_with_default_features.stderr new file mode 100644 index 00000000000..fb8d4903d7b --- /dev/null +++ b/tests/snapshots/add/overwrite_no_default_features_with_default_features.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package1 v99999.0.0 to dependencies. + Adding my-package2 v0.4.1 to dependencies. diff --git a/tests/snapshots/add/overwrite_no_default_features_with_default_features.stdout b/tests/snapshots/add/overwrite_no_default_features_with_default_features.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_no_optional.in/Cargo.toml b/tests/snapshots/add/overwrite_no_optional.in/Cargo.toml new file mode 100644 index 00000000000..c5e01789281 --- /dev/null +++ b/tests/snapshots/add/overwrite_no_optional.in/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = "99999.0.0" +my-package2 = "0.4.1" diff --git a/tests/snapshots/add/overwrite_no_optional.in/src/lib.rs b/tests/snapshots/add/overwrite_no_optional.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_no_optional.out/Cargo.toml b/tests/snapshots/add/overwrite_no_optional.out/Cargo.toml new file mode 100644 index 00000000000..c5e01789281 --- /dev/null +++ b/tests/snapshots/add/overwrite_no_optional.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = "99999.0.0" +my-package2 = "0.4.1" diff --git a/tests/snapshots/add/overwrite_no_optional.stderr b/tests/snapshots/add/overwrite_no_optional.stderr new file mode 100644 index 00000000000..fb8d4903d7b --- /dev/null +++ b/tests/snapshots/add/overwrite_no_optional.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package1 v99999.0.0 to dependencies. + Adding my-package2 v0.4.1 to dependencies. diff --git a/tests/snapshots/add/overwrite_no_optional.stdout b/tests/snapshots/add/overwrite_no_optional.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_no_optional_with_optional.in/Cargo.toml b/tests/snapshots/add/overwrite_no_optional_with_optional.in/Cargo.toml new file mode 100644 index 00000000000..8cd2616d4ef --- /dev/null +++ b/tests/snapshots/add/overwrite_no_optional_with_optional.in/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = { version = "99999.0.0", optional = false } +my-package2 = { version = "0.4.1", optional = false } diff --git a/tests/snapshots/add/overwrite_no_optional_with_optional.in/src/lib.rs b/tests/snapshots/add/overwrite_no_optional_with_optional.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_no_optional_with_optional.out/Cargo.toml b/tests/snapshots/add/overwrite_no_optional_with_optional.out/Cargo.toml new file mode 100644 index 00000000000..eda5445c50f --- /dev/null +++ b/tests/snapshots/add/overwrite_no_optional_with_optional.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = { version = "99999.0.0", optional = true } +my-package2 = { version = "0.4.1", optional = true } diff --git a/tests/snapshots/add/overwrite_no_optional_with_optional.stderr b/tests/snapshots/add/overwrite_no_optional_with_optional.stderr new file mode 100644 index 00000000000..8cf4812cf17 --- /dev/null +++ b/tests/snapshots/add/overwrite_no_optional_with_optional.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package1 v99999.0.0 to optional dependencies. + Adding my-package2 v0.4.1 to optional dependencies. diff --git a/tests/snapshots/add/overwrite_no_optional_with_optional.stdout b/tests/snapshots/add/overwrite_no_optional_with_optional.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_optional.in/Cargo.toml b/tests/snapshots/add/overwrite_optional.in/Cargo.toml new file mode 100644 index 00000000000..c5e01789281 --- /dev/null +++ b/tests/snapshots/add/overwrite_optional.in/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = "99999.0.0" +my-package2 = "0.4.1" diff --git a/tests/snapshots/add/overwrite_optional.in/src/lib.rs b/tests/snapshots/add/overwrite_optional.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_optional.out/Cargo.toml b/tests/snapshots/add/overwrite_optional.out/Cargo.toml new file mode 100644 index 00000000000..eda5445c50f --- /dev/null +++ b/tests/snapshots/add/overwrite_optional.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = { version = "99999.0.0", optional = true } +my-package2 = { version = "0.4.1", optional = true } diff --git a/tests/snapshots/add/overwrite_optional.stderr b/tests/snapshots/add/overwrite_optional.stderr new file mode 100644 index 00000000000..8cf4812cf17 --- /dev/null +++ b/tests/snapshots/add/overwrite_optional.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package1 v99999.0.0 to optional dependencies. + Adding my-package2 v0.4.1 to optional dependencies. diff --git a/tests/snapshots/add/overwrite_optional.stdout b/tests/snapshots/add/overwrite_optional.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_optional_with_no_optional.in/Cargo.toml b/tests/snapshots/add/overwrite_optional_with_no_optional.in/Cargo.toml new file mode 100644 index 00000000000..195d5c7e061 --- /dev/null +++ b/tests/snapshots/add/overwrite_optional_with_no_optional.in/Cargo.toml @@ -0,0 +1,13 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[features] +default = ["my-package1"] +other = ["my-package1/nose"] + +[dependencies] +my-package1 = { version = "99999.0.0", optional = true } +my-package2 = { version = "0.4.1", optional = true } diff --git a/tests/snapshots/add/overwrite_optional_with_no_optional.in/src/lib.rs b/tests/snapshots/add/overwrite_optional_with_no_optional.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_optional_with_no_optional.out/Cargo.toml b/tests/snapshots/add/overwrite_optional_with_no_optional.out/Cargo.toml new file mode 100644 index 00000000000..6301685d17e --- /dev/null +++ b/tests/snapshots/add/overwrite_optional_with_no_optional.out/Cargo.toml @@ -0,0 +1,13 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[features] +default = [] +other = ["my-package1/nose"] + +[dependencies] +my-package1 = { version = "99999.0.0" } +my-package2 = { version = "0.4.1" } diff --git a/tests/snapshots/add/overwrite_optional_with_no_optional.stderr b/tests/snapshots/add/overwrite_optional_with_no_optional.stderr new file mode 100644 index 00000000000..fb8d4903d7b --- /dev/null +++ b/tests/snapshots/add/overwrite_optional_with_no_optional.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package1 v99999.0.0 to dependencies. + Adding my-package2 v0.4.1 to dependencies. diff --git a/tests/snapshots/add/overwrite_optional_with_no_optional.stdout b/tests/snapshots/add/overwrite_optional_with_no_optional.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_path_noop.in/Cargo.toml b/tests/snapshots/add/overwrite_path_noop.in/Cargo.toml new file mode 100644 index 00000000000..bbaf4f5521c --- /dev/null +++ b/tests/snapshots/add/overwrite_path_noop.in/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] +exclude = ["dependency"] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = { version = "0.0.0", path = "dependency", optional = true, default-features = false, features = ["nose", "mouth"], registry = "alternative" } diff --git a/tests/snapshots/add/overwrite_path_noop.in/dependency/Cargo.toml b/tests/snapshots/add/overwrite_path_noop.in/dependency/Cargo.toml new file mode 100644 index 00000000000..8243797eb0a --- /dev/null +++ b/tests/snapshots/add/overwrite_path_noop.in/dependency/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "your-face" +version = "0.0.0" + +[features] +mouth = [] +nose = [] diff --git a/tests/snapshots/add/overwrite_path_noop.in/dependency/src/lib.rs b/tests/snapshots/add/overwrite_path_noop.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_path_noop.in/src/lib.rs b/tests/snapshots/add/overwrite_path_noop.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_path_noop.out/Cargo.toml b/tests/snapshots/add/overwrite_path_noop.out/Cargo.toml new file mode 100644 index 00000000000..bbaf4f5521c --- /dev/null +++ b/tests/snapshots/add/overwrite_path_noop.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] +exclude = ["dependency"] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = { version = "0.0.0", path = "dependency", optional = true, default-features = false, features = ["nose", "mouth"], registry = "alternative" } diff --git a/tests/snapshots/add/overwrite_path_noop.out/dependency/Cargo.toml b/tests/snapshots/add/overwrite_path_noop.out/dependency/Cargo.toml new file mode 100644 index 00000000000..8243797eb0a --- /dev/null +++ b/tests/snapshots/add/overwrite_path_noop.out/dependency/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "your-face" +version = "0.0.0" + +[features] +mouth = [] +nose = [] diff --git a/tests/snapshots/add/overwrite_path_noop.stderr b/tests/snapshots/add/overwrite_path_noop.stderr new file mode 100644 index 00000000000..2f0b90de0d2 --- /dev/null +++ b/tests/snapshots/add/overwrite_path_noop.stderr @@ -0,0 +1,4 @@ + Adding your-face (local) to optional dependencies. + Features: + + mouth + + nose diff --git a/tests/snapshots/add/overwrite_path_noop.stdout b/tests/snapshots/add/overwrite_path_noop.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_path_with_version.in/dependency/Cargo.toml b/tests/snapshots/add/overwrite_path_with_version.in/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/overwrite_path_with_version.in/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/overwrite_path_with_version.in/dependency/src/lib.rs b/tests/snapshots/add/overwrite_path_with_version.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_path_with_version.in/primary/Cargo.toml b/tests/snapshots/add/overwrite_path_with_version.in/primary/Cargo.toml new file mode 100644 index 00000000000..9d20b2240c6 --- /dev/null +++ b/tests/snapshots/add/overwrite_path_with_version.in/primary/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +cargo-list-test-fixture-dependency = { optional = true, path = "../dependency" } diff --git a/tests/snapshots/add/overwrite_path_with_version.in/primary/src/lib.rs b/tests/snapshots/add/overwrite_path_with_version.in/primary/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_path_with_version.out/dependency/Cargo.toml b/tests/snapshots/add/overwrite_path_with_version.out/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/overwrite_path_with_version.out/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/overwrite_path_with_version.out/primary/Cargo.toml b/tests/snapshots/add/overwrite_path_with_version.out/primary/Cargo.toml new file mode 100644 index 00000000000..a20f2095db9 --- /dev/null +++ b/tests/snapshots/add/overwrite_path_with_version.out/primary/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +cargo-list-test-fixture-dependency = { optional = true, version = "20.0" } diff --git a/tests/snapshots/add/overwrite_path_with_version.stderr b/tests/snapshots/add/overwrite_path_with_version.stderr new file mode 100644 index 00000000000..d0b3a4cf228 --- /dev/null +++ b/tests/snapshots/add/overwrite_path_with_version.stderr @@ -0,0 +1,2 @@ + Updating `dummy-registry` index + Adding cargo-list-test-fixture-dependency v20.0 to optional dependencies. diff --git a/tests/snapshots/add/overwrite_path_with_version.stdout b/tests/snapshots/add/overwrite_path_with_version.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_rename_with_no_rename.in/Cargo.toml b/tests/snapshots/add/overwrite_rename_with_no_rename.in/Cargo.toml new file mode 100644 index 00000000000..4502292454a --- /dev/null +++ b/tests/snapshots/add/overwrite_rename_with_no_rename.in/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +a1 = { package = "versioned-package", version = "0.1.1", optional = true } diff --git a/tests/snapshots/add/overwrite_rename_with_no_rename.in/src/lib.rs b/tests/snapshots/add/overwrite_rename_with_no_rename.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_rename_with_no_rename.out/Cargo.toml b/tests/snapshots/add/overwrite_rename_with_no_rename.out/Cargo.toml new file mode 100644 index 00000000000..9951492da90 --- /dev/null +++ b/tests/snapshots/add/overwrite_rename_with_no_rename.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +a1 = { package = "versioned-package", version = "0.1.1", optional = true } +versioned-package = "99999.0.0" diff --git a/tests/snapshots/add/overwrite_rename_with_no_rename.stderr b/tests/snapshots/add/overwrite_rename_with_no_rename.stderr new file mode 100644 index 00000000000..305b89f26bc --- /dev/null +++ b/tests/snapshots/add/overwrite_rename_with_no_rename.stderr @@ -0,0 +1,2 @@ + Updating `dummy-registry` index + Adding versioned-package v99999.0.0 to dependencies. diff --git a/tests/snapshots/add/overwrite_rename_with_no_rename.stdout b/tests/snapshots/add/overwrite_rename_with_no_rename.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_rename_with_rename.in/Cargo.toml b/tests/snapshots/add/overwrite_rename_with_rename.in/Cargo.toml new file mode 100644 index 00000000000..4502292454a --- /dev/null +++ b/tests/snapshots/add/overwrite_rename_with_rename.in/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +a1 = { package = "versioned-package", version = "0.1.1", optional = true } diff --git a/tests/snapshots/add/overwrite_rename_with_rename.in/src/lib.rs b/tests/snapshots/add/overwrite_rename_with_rename.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_rename_with_rename.out/Cargo.toml b/tests/snapshots/add/overwrite_rename_with_rename.out/Cargo.toml new file mode 100644 index 00000000000..790f6546cc9 --- /dev/null +++ b/tests/snapshots/add/overwrite_rename_with_rename.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +a1 = { package = "versioned-package", version = "0.1.1", optional = true } +a2 = { version = "99999.0.0", package = "versioned-package" } diff --git a/tests/snapshots/add/overwrite_rename_with_rename.stderr b/tests/snapshots/add/overwrite_rename_with_rename.stderr new file mode 100644 index 00000000000..305b89f26bc --- /dev/null +++ b/tests/snapshots/add/overwrite_rename_with_rename.stderr @@ -0,0 +1,2 @@ + Updating `dummy-registry` index + Adding versioned-package v99999.0.0 to dependencies. diff --git a/tests/snapshots/add/overwrite_rename_with_rename.stdout b/tests/snapshots/add/overwrite_rename_with_rename.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_rename_with_rename_noop.in/Cargo.toml b/tests/snapshots/add/overwrite_rename_with_rename_noop.in/Cargo.toml new file mode 100644 index 00000000000..4502292454a --- /dev/null +++ b/tests/snapshots/add/overwrite_rename_with_rename_noop.in/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +a1 = { package = "versioned-package", version = "0.1.1", optional = true } diff --git a/tests/snapshots/add/overwrite_rename_with_rename_noop.in/src/lib.rs b/tests/snapshots/add/overwrite_rename_with_rename_noop.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_rename_with_rename_noop.out/Cargo.toml b/tests/snapshots/add/overwrite_rename_with_rename_noop.out/Cargo.toml new file mode 100644 index 00000000000..4502292454a --- /dev/null +++ b/tests/snapshots/add/overwrite_rename_with_rename_noop.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +a1 = { package = "versioned-package", version = "0.1.1", optional = true } diff --git a/tests/snapshots/add/overwrite_rename_with_rename_noop.stderr b/tests/snapshots/add/overwrite_rename_with_rename_noop.stderr new file mode 100644 index 00000000000..d69dc92cd28 --- /dev/null +++ b/tests/snapshots/add/overwrite_rename_with_rename_noop.stderr @@ -0,0 +1,2 @@ + Updating `dummy-registry` index + Adding versioned-package v0.1.1 to optional dependencies. diff --git a/tests/snapshots/add/overwrite_rename_with_rename_noop.stdout b/tests/snapshots/add/overwrite_rename_with_rename_noop.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_version_with_git.in/Cargo.toml b/tests/snapshots/add/overwrite_version_with_git.in/Cargo.toml new file mode 100644 index 00000000000..fe41f2a90b4 --- /dev/null +++ b/tests/snapshots/add/overwrite_version_with_git.in/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +versioned-package = { version = "0.1.1", optional = true } diff --git a/tests/snapshots/add/overwrite_version_with_git.in/src/lib.rs b/tests/snapshots/add/overwrite_version_with_git.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_version_with_git.out/Cargo.toml b/tests/snapshots/add/overwrite_version_with_git.out/Cargo.toml new file mode 100644 index 00000000000..26001402414 --- /dev/null +++ b/tests/snapshots/add/overwrite_version_with_git.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +versioned-package = { version = "0.3.0", optional = true, git = "[ROOTURL]/versioned-package" } diff --git a/tests/snapshots/add/overwrite_version_with_git.stderr b/tests/snapshots/add/overwrite_version_with_git.stderr new file mode 100644 index 00000000000..c5013969264 --- /dev/null +++ b/tests/snapshots/add/overwrite_version_with_git.stderr @@ -0,0 +1,2 @@ + Updating git repository `[ROOTURL]/versioned-package` + Adding versioned-package (git) to optional dependencies. diff --git a/tests/snapshots/add/overwrite_version_with_git.stdout b/tests/snapshots/add/overwrite_version_with_git.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_version_with_path.in/dependency/Cargo.toml b/tests/snapshots/add/overwrite_version_with_path.in/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/overwrite_version_with_path.in/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/overwrite_version_with_path.in/dependency/src/lib.rs b/tests/snapshots/add/overwrite_version_with_path.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_version_with_path.in/primary/Cargo.toml b/tests/snapshots/add/overwrite_version_with_path.in/primary/Cargo.toml new file mode 100644 index 00000000000..063b891926b --- /dev/null +++ b/tests/snapshots/add/overwrite_version_with_path.in/primary/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +cargo-list-test-fixture-dependency = { version = "0.1.1", optional = true } diff --git a/tests/snapshots/add/overwrite_version_with_path.in/primary/src/lib.rs b/tests/snapshots/add/overwrite_version_with_path.in/primary/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_version_with_path.out/dependency/Cargo.toml b/tests/snapshots/add/overwrite_version_with_path.out/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/overwrite_version_with_path.out/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/overwrite_version_with_path.out/primary/Cargo.toml b/tests/snapshots/add/overwrite_version_with_path.out/primary/Cargo.toml new file mode 100644 index 00000000000..07253670afe --- /dev/null +++ b/tests/snapshots/add/overwrite_version_with_path.out/primary/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +cargo-list-test-fixture-dependency = { version = "0.0.0", optional = true, path = "../dependency" } diff --git a/tests/snapshots/add/overwrite_version_with_path.stderr b/tests/snapshots/add/overwrite_version_with_path.stderr new file mode 100644 index 00000000000..98abcfc99e4 --- /dev/null +++ b/tests/snapshots/add/overwrite_version_with_path.stderr @@ -0,0 +1 @@ + Adding cargo-list-test-fixture-dependency (local) to optional dependencies. diff --git a/tests/snapshots/add/overwrite_version_with_path.stdout b/tests/snapshots/add/overwrite_version_with_path.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_with_rename.in/Cargo.toml b/tests/snapshots/add/overwrite_with_rename.in/Cargo.toml new file mode 100644 index 00000000000..fe41f2a90b4 --- /dev/null +++ b/tests/snapshots/add/overwrite_with_rename.in/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +versioned-package = { version = "0.1.1", optional = true } diff --git a/tests/snapshots/add/overwrite_with_rename.in/src/lib.rs b/tests/snapshots/add/overwrite_with_rename.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/overwrite_with_rename.out/Cargo.toml b/tests/snapshots/add/overwrite_with_rename.out/Cargo.toml new file mode 100644 index 00000000000..4b748518116 --- /dev/null +++ b/tests/snapshots/add/overwrite_with_rename.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +renamed = { version = "99999.0.0", package = "versioned-package" } +versioned-package = { version = "0.1.1", optional = true } diff --git a/tests/snapshots/add/overwrite_with_rename.stderr b/tests/snapshots/add/overwrite_with_rename.stderr new file mode 100644 index 00000000000..305b89f26bc --- /dev/null +++ b/tests/snapshots/add/overwrite_with_rename.stderr @@ -0,0 +1,2 @@ + Updating `dummy-registry` index + Adding versioned-package v99999.0.0 to dependencies. diff --git a/tests/snapshots/add/overwrite_with_rename.stdout b/tests/snapshots/add/overwrite_with_rename.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/path.in/dependency/Cargo.toml b/tests/snapshots/add/path.in/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/path.in/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/path.in/dependency/src/lib.rs b/tests/snapshots/add/path.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/path.in/primary/Cargo.toml b/tests/snapshots/add/path.in/primary/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/path.in/primary/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/path.in/primary/src/lib.rs b/tests/snapshots/add/path.in/primary/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/path.out/dependency/Cargo.toml b/tests/snapshots/add/path.out/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/path.out/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/path.out/primary/Cargo.toml b/tests/snapshots/add/path.out/primary/Cargo.toml new file mode 100644 index 00000000000..93476d743f6 --- /dev/null +++ b/tests/snapshots/add/path.out/primary/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +cargo-list-test-fixture-dependency = { version = "0.0.0", path = "../dependency" } diff --git a/tests/snapshots/add/path.stderr b/tests/snapshots/add/path.stderr new file mode 100644 index 00000000000..8109d3cc54b --- /dev/null +++ b/tests/snapshots/add/path.stderr @@ -0,0 +1 @@ + Adding cargo-list-test-fixture-dependency (local) to dependencies. diff --git a/tests/snapshots/add/path.stdout b/tests/snapshots/add/path.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/path_dev.in/dependency/Cargo.toml b/tests/snapshots/add/path_dev.in/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/path_dev.in/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/path_dev.in/dependency/src/lib.rs b/tests/snapshots/add/path_dev.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/path_dev.in/primary/Cargo.toml b/tests/snapshots/add/path_dev.in/primary/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/path_dev.in/primary/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/path_dev.in/primary/src/lib.rs b/tests/snapshots/add/path_dev.in/primary/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/path_dev.out/dependency/Cargo.toml b/tests/snapshots/add/path_dev.out/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/path_dev.out/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/path_dev.out/primary/Cargo.toml b/tests/snapshots/add/path_dev.out/primary/Cargo.toml new file mode 100644 index 00000000000..92be59dc6d0 --- /dev/null +++ b/tests/snapshots/add/path_dev.out/primary/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dev-dependencies] +cargo-list-test-fixture-dependency = { path = "../dependency" } diff --git a/tests/snapshots/add/path_dev.stderr b/tests/snapshots/add/path_dev.stderr new file mode 100644 index 00000000000..d8093d6aece --- /dev/null +++ b/tests/snapshots/add/path_dev.stderr @@ -0,0 +1 @@ + Adding cargo-list-test-fixture-dependency (local) to dev-dependencies. diff --git a/tests/snapshots/add/path_dev.stdout b/tests/snapshots/add/path_dev.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/path_inferred_name.in/dependency/Cargo.toml b/tests/snapshots/add/path_inferred_name.in/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/path_inferred_name.in/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/path_inferred_name.in/dependency/src/lib.rs b/tests/snapshots/add/path_inferred_name.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/path_inferred_name.in/primary/Cargo.toml b/tests/snapshots/add/path_inferred_name.in/primary/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/path_inferred_name.in/primary/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/path_inferred_name.in/primary/src/lib.rs b/tests/snapshots/add/path_inferred_name.in/primary/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/path_inferred_name.out/dependency/Cargo.toml b/tests/snapshots/add/path_inferred_name.out/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/path_inferred_name.out/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/path_inferred_name.out/primary/Cargo.toml b/tests/snapshots/add/path_inferred_name.out/primary/Cargo.toml new file mode 100644 index 00000000000..93476d743f6 --- /dev/null +++ b/tests/snapshots/add/path_inferred_name.out/primary/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +cargo-list-test-fixture-dependency = { version = "0.0.0", path = "../dependency" } diff --git a/tests/snapshots/add/path_inferred_name.stderr b/tests/snapshots/add/path_inferred_name.stderr new file mode 100644 index 00000000000..8109d3cc54b --- /dev/null +++ b/tests/snapshots/add/path_inferred_name.stderr @@ -0,0 +1 @@ + Adding cargo-list-test-fixture-dependency (local) to dependencies. diff --git a/tests/snapshots/add/path_inferred_name.stdout b/tests/snapshots/add/path_inferred_name.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/Cargo.toml b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/Cargo.toml new file mode 100644 index 00000000000..299859e79df --- /dev/null +++ b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["primary", "dependency", "optional"] diff --git a/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/dependency/Cargo.toml b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/dependency/Cargo.toml new file mode 100644 index 00000000000..34157f41182 --- /dev/null +++ b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/dependency/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "your-face" +version = "0.1.3" + +[dependencies] +toml_edit = "0.1.5" +atty = "0.2.13" +optional-dependency = { path = "../optional", optional = true } + +[features] +default = ["mouth"] +nose = [] +mouth = ["nose"] +eyes = [] diff --git a/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/dependency/src/lib.rs b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/optional/Cargo.toml b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/optional/Cargo.toml new file mode 100644 index 00000000000..0216dba8987 --- /dev/null +++ b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/optional/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "optional-dep" +version = "0.1.3" + +[dependencies] +toml_edit = "0.1.5" +atty = "0.2.13" diff --git a/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/optional/src/lib.rs b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/optional/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/primary/Cargo.toml b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/primary/Cargo.toml new file mode 100644 index 00000000000..5e20016d710 --- /dev/null +++ b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/primary/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/primary/src/lib.rs b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.in/primary/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/path_inferred_name_conflicts_full_feature.out/Cargo.toml b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.out/Cargo.toml new file mode 100644 index 00000000000..299859e79df --- /dev/null +++ b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.out/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["primary", "dependency", "optional"] diff --git a/tests/snapshots/add/path_inferred_name_conflicts_full_feature.out/dependency/Cargo.toml b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.out/dependency/Cargo.toml new file mode 100644 index 00000000000..34157f41182 --- /dev/null +++ b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.out/dependency/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "your-face" +version = "0.1.3" + +[dependencies] +toml_edit = "0.1.5" +atty = "0.2.13" +optional-dependency = { path = "../optional", optional = true } + +[features] +default = ["mouth"] +nose = [] +mouth = ["nose"] +eyes = [] diff --git a/tests/snapshots/add/path_inferred_name_conflicts_full_feature.out/primary/Cargo.toml b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.out/primary/Cargo.toml new file mode 100644 index 00000000000..5e20016d710 --- /dev/null +++ b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.out/primary/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/path_inferred_name_conflicts_full_feature.stderr b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.stderr new file mode 100644 index 00000000000..791ca6008e1 --- /dev/null +++ b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.stderr @@ -0,0 +1 @@ +error: `your-face/nose` is unsupported when inferring the crate name, use `nose` diff --git a/tests/snapshots/add/path_inferred_name_conflicts_full_feature.stdout b/tests/snapshots/add/path_inferred_name_conflicts_full_feature.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/path_normalized_name.in/dependency/Cargo.toml b/tests/snapshots/add/path_normalized_name.in/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/path_normalized_name.in/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/path_normalized_name.in/dependency/src/lib.rs b/tests/snapshots/add/path_normalized_name.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/path_normalized_name.in/primary/Cargo.toml b/tests/snapshots/add/path_normalized_name.in/primary/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/path_normalized_name.in/primary/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/path_normalized_name.in/primary/src/lib.rs b/tests/snapshots/add/path_normalized_name.in/primary/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/path_normalized_name.out/dependency/Cargo.toml b/tests/snapshots/add/path_normalized_name.out/dependency/Cargo.toml new file mode 100644 index 00000000000..cbe244113c1 --- /dev/null +++ b/tests/snapshots/add/path_normalized_name.out/dependency/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/path_normalized_name.out/primary/Cargo.toml b/tests/snapshots/add/path_normalized_name.out/primary/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/path_normalized_name.out/primary/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/path_normalized_name.stderr b/tests/snapshots/add/path_normalized_name.stderr new file mode 100644 index 00000000000..59b35e3c4b1 --- /dev/null +++ b/tests/snapshots/add/path_normalized_name.stderr @@ -0,0 +1 @@ +error: the crate `cargo_list_test_fixture_dependency@[ROOT]/case/dependency` could not be found at `[ROOT]/case/dependency` diff --git a/tests/snapshots/add/path_normalized_name.stdout b/tests/snapshots/add/path_normalized_name.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/preserve_sorted.in/Cargo.toml b/tests/snapshots/add/preserve_sorted.in/Cargo.toml new file mode 100644 index 00000000000..2716d647883 --- /dev/null +++ b/tests/snapshots/add/preserve_sorted.in/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +atty = "0.2.13" +toml_edit = "0.1.5" diff --git a/tests/snapshots/add/preserve_sorted.in/src/lib.rs b/tests/snapshots/add/preserve_sorted.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/preserve_sorted.out/Cargo.toml b/tests/snapshots/add/preserve_sorted.out/Cargo.toml new file mode 100644 index 00000000000..88222bd2a22 --- /dev/null +++ b/tests/snapshots/add/preserve_sorted.out/Cargo.toml @@ -0,0 +1,10 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +atty = "0.2.13" +toml = "99999.0.0" +toml_edit = "0.1.5" diff --git a/tests/snapshots/add/preserve_sorted.stderr b/tests/snapshots/add/preserve_sorted.stderr new file mode 100644 index 00000000000..7c83976f800 --- /dev/null +++ b/tests/snapshots/add/preserve_sorted.stderr @@ -0,0 +1,2 @@ + Updating `dummy-registry` index + Adding toml v99999.0.0 to dependencies. diff --git a/tests/snapshots/add/preserve_sorted.stdout b/tests/snapshots/add/preserve_sorted.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/preserve_unsorted.in/Cargo.toml b/tests/snapshots/add/preserve_unsorted.in/Cargo.toml new file mode 100644 index 00000000000..5957df98b62 --- /dev/null +++ b/tests/snapshots/add/preserve_unsorted.in/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +toml_edit = "0.1.5" +atty = "0.2.13" diff --git a/tests/snapshots/add/preserve_unsorted.in/src/lib.rs b/tests/snapshots/add/preserve_unsorted.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/preserve_unsorted.out/Cargo.toml b/tests/snapshots/add/preserve_unsorted.out/Cargo.toml new file mode 100644 index 00000000000..e01b9255ecc --- /dev/null +++ b/tests/snapshots/add/preserve_unsorted.out/Cargo.toml @@ -0,0 +1,10 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +toml_edit = "0.1.5" +atty = "0.2.13" +toml = "99999.0.0" diff --git a/tests/snapshots/add/preserve_unsorted.stderr b/tests/snapshots/add/preserve_unsorted.stderr new file mode 100644 index 00000000000..7c83976f800 --- /dev/null +++ b/tests/snapshots/add/preserve_unsorted.stderr @@ -0,0 +1,2 @@ + Updating `dummy-registry` index + Adding toml v99999.0.0 to dependencies. diff --git a/tests/snapshots/add/preserve_unsorted.stdout b/tests/snapshots/add/preserve_unsorted.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/quiet.in b/tests/snapshots/add/quiet.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/quiet.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/quiet.out/Cargo.toml b/tests/snapshots/add/quiet.out/Cargo.toml new file mode 100644 index 00000000000..79d735a12d4 --- /dev/null +++ b/tests/snapshots/add/quiet.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = "99999.0.0" diff --git a/tests/snapshots/add/quiet.stderr b/tests/snapshots/add/quiet.stderr new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/quiet.stdout b/tests/snapshots/add/quiet.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/registry.in/Cargo.toml b/tests/snapshots/add/registry.in/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/snapshots/add/registry.in/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/registry.in/src/lib.rs b/tests/snapshots/add/registry.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/registry.out/Cargo.toml b/tests/snapshots/add/registry.out/Cargo.toml new file mode 100644 index 00000000000..e856bee5df8 --- /dev/null +++ b/tests/snapshots/add/registry.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package1 = { version = "99999.0.0", registry = "alternative" } +my-package2 = { version = "99999.0.0", registry = "alternative" } diff --git a/tests/snapshots/add/registry.stderr b/tests/snapshots/add/registry.stderr new file mode 100644 index 00000000000..437e780af58 --- /dev/null +++ b/tests/snapshots/add/registry.stderr @@ -0,0 +1,3 @@ + Updating `alternative` index + Adding my-package1 v99999.0.0 to dependencies. + Adding my-package2 v99999.0.0 to dependencies. diff --git a/tests/snapshots/add/registry.stdout b/tests/snapshots/add/registry.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/rename.in b/tests/snapshots/add/rename.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/rename.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/rename.out/Cargo.toml b/tests/snapshots/add/rename.out/Cargo.toml new file mode 100644 index 00000000000..ebcfbbd99dd --- /dev/null +++ b/tests/snapshots/add/rename.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +renamed = { version = "99999.0.0", package = "my-package" } diff --git a/tests/snapshots/add/rename.stderr b/tests/snapshots/add/rename.stderr new file mode 100644 index 00000000000..fd6b711e386 --- /dev/null +++ b/tests/snapshots/add/rename.stderr @@ -0,0 +1,2 @@ + Updating `dummy-registry` index + Adding my-package v99999.0.0 to dependencies. diff --git a/tests/snapshots/add/rename.stdout b/tests/snapshots/add/rename.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/require_weak.in/Cargo.toml b/tests/snapshots/add/require_weak.in/Cargo.toml new file mode 100644 index 00000000000..54faf173a00 --- /dev/null +++ b/tests/snapshots/add/require_weak.in/Cargo.toml @@ -0,0 +1,11 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[features] +eyes = ["your-face?/eyes"] + +[dependencies] +your-face = { version = "99999.0.0", optional = true } diff --git a/tests/snapshots/add/require_weak.in/src/lib.rs b/tests/snapshots/add/require_weak.in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/require_weak.out/Cargo.toml b/tests/snapshots/add/require_weak.out/Cargo.toml new file mode 100644 index 00000000000..a0e4b9753bc --- /dev/null +++ b/tests/snapshots/add/require_weak.out/Cargo.toml @@ -0,0 +1,11 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[features] +eyes = ["your-face/eyes"] + +[dependencies] +your-face = { version = "99999.0.0" } diff --git a/tests/snapshots/add/require_weak.stderr b/tests/snapshots/add/require_weak.stderr new file mode 100644 index 00000000000..796b9601b4d --- /dev/null +++ b/tests/snapshots/add/require_weak.stderr @@ -0,0 +1,7 @@ + Updating `dummy-registry` index + Adding your-face v99999.0.0 to dependencies. + Features: + - ears + - eyes + - mouth + - nose diff --git a/tests/snapshots/add/require_weak.stdout b/tests/snapshots/add/require_weak.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/target.in b/tests/snapshots/add/target.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/target.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/target.out/Cargo.toml b/tests/snapshots/add/target.out/Cargo.toml new file mode 100644 index 00000000000..9c96ede5148 --- /dev/null +++ b/tests/snapshots/add/target.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[target.i686-unknown-linux-gnu.dependencies] +my-package1 = "99999.0.0" +my-package2 = "99999.0.0" diff --git a/tests/snapshots/add/target.stderr b/tests/snapshots/add/target.stderr new file mode 100644 index 00000000000..3413bcc1b02 --- /dev/null +++ b/tests/snapshots/add/target.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package1 v99999.0.0 to dependencies for target `i686-unknown-linux-gnu`. + Adding my-package2 v99999.0.0 to dependencies for target `i686-unknown-linux-gnu`. diff --git a/tests/snapshots/add/target.stdout b/tests/snapshots/add/target.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/target_cfg.in b/tests/snapshots/add/target_cfg.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/target_cfg.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/target_cfg.out/Cargo.toml b/tests/snapshots/add/target_cfg.out/Cargo.toml new file mode 100644 index 00000000000..212ec571bf5 --- /dev/null +++ b/tests/snapshots/add/target_cfg.out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[target."cfg(unix)".dependencies] +my-package1 = "99999.0.0" +my-package2 = "99999.0.0" diff --git a/tests/snapshots/add/target_cfg.stderr b/tests/snapshots/add/target_cfg.stderr new file mode 100644 index 00000000000..e405c8dc19a --- /dev/null +++ b/tests/snapshots/add/target_cfg.stderr @@ -0,0 +1,3 @@ + Updating `dummy-registry` index + Adding my-package1 v99999.0.0 to dependencies for target `cfg(unix)`. + Adding my-package2 v99999.0.0 to dependencies for target `cfg(unix)`. diff --git a/tests/snapshots/add/target_cfg.stdout b/tests/snapshots/add/target_cfg.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/vers.in b/tests/snapshots/add/vers.in new file mode 120000 index 00000000000..87eae145313 --- /dev/null +++ b/tests/snapshots/add/vers.in @@ -0,0 +1 @@ +add-basic.in/ \ No newline at end of file diff --git a/tests/snapshots/add/vers.out/Cargo.toml b/tests/snapshots/add/vers.out/Cargo.toml new file mode 100644 index 00000000000..c6ca3d67afa --- /dev/null +++ b/tests/snapshots/add/vers.out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +my-package = ">=0.1.1" diff --git a/tests/snapshots/add/vers.stderr b/tests/snapshots/add/vers.stderr new file mode 100644 index 00000000000..7ef92d22eba --- /dev/null +++ b/tests/snapshots/add/vers.stderr @@ -0,0 +1,2 @@ + Updating `dummy-registry` index + Adding my-package >=0.1.1 to dependencies. diff --git a/tests/snapshots/add/vers.stdout b/tests/snapshots/add/vers.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/workspace_name.in/Cargo.toml b/tests/snapshots/add/workspace_name.in/Cargo.toml new file mode 100644 index 00000000000..57e1f30855f --- /dev/null +++ b/tests/snapshots/add/workspace_name.in/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["primary", "dependency"] diff --git a/tests/snapshots/add/workspace_name.in/dependency/Cargo.toml b/tests/snapshots/add/workspace_name.in/dependency/Cargo.toml new file mode 100644 index 00000000000..ca4f36d72f7 --- /dev/null +++ b/tests/snapshots/add/workspace_name.in/dependency/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/workspace_name.in/dependency/src/lib.rs b/tests/snapshots/add/workspace_name.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/workspace_name.in/primary/Cargo.toml b/tests/snapshots/add/workspace_name.in/primary/Cargo.toml new file mode 100644 index 00000000000..5e20016d710 --- /dev/null +++ b/tests/snapshots/add/workspace_name.in/primary/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/workspace_name.in/primary/src/lib.rs b/tests/snapshots/add/workspace_name.in/primary/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/workspace_name.out/Cargo.toml b/tests/snapshots/add/workspace_name.out/Cargo.toml new file mode 100644 index 00000000000..57e1f30855f --- /dev/null +++ b/tests/snapshots/add/workspace_name.out/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["primary", "dependency"] diff --git a/tests/snapshots/add/workspace_name.out/dependency/Cargo.toml b/tests/snapshots/add/workspace_name.out/dependency/Cargo.toml new file mode 100644 index 00000000000..ca4f36d72f7 --- /dev/null +++ b/tests/snapshots/add/workspace_name.out/dependency/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/workspace_name.out/primary/Cargo.toml b/tests/snapshots/add/workspace_name.out/primary/Cargo.toml new file mode 100644 index 00000000000..a693df54f88 --- /dev/null +++ b/tests/snapshots/add/workspace_name.out/primary/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +cargo-list-test-fixture-dependency = { version = "0.0.0", path = "../dependency" } diff --git a/tests/snapshots/add/workspace_name.stderr b/tests/snapshots/add/workspace_name.stderr new file mode 100644 index 00000000000..8109d3cc54b --- /dev/null +++ b/tests/snapshots/add/workspace_name.stderr @@ -0,0 +1 @@ + Adding cargo-list-test-fixture-dependency (local) to dependencies. diff --git a/tests/snapshots/add/workspace_name.stdout b/tests/snapshots/add/workspace_name.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/workspace_path.in/Cargo.toml b/tests/snapshots/add/workspace_path.in/Cargo.toml new file mode 100644 index 00000000000..57e1f30855f --- /dev/null +++ b/tests/snapshots/add/workspace_path.in/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["primary", "dependency"] diff --git a/tests/snapshots/add/workspace_path.in/dependency/Cargo.toml b/tests/snapshots/add/workspace_path.in/dependency/Cargo.toml new file mode 100644 index 00000000000..ca4f36d72f7 --- /dev/null +++ b/tests/snapshots/add/workspace_path.in/dependency/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/workspace_path.in/dependency/src/lib.rs b/tests/snapshots/add/workspace_path.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/workspace_path.in/primary/Cargo.toml b/tests/snapshots/add/workspace_path.in/primary/Cargo.toml new file mode 100644 index 00000000000..5e20016d710 --- /dev/null +++ b/tests/snapshots/add/workspace_path.in/primary/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/workspace_path.in/primary/src/lib.rs b/tests/snapshots/add/workspace_path.in/primary/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/workspace_path.out/Cargo.toml b/tests/snapshots/add/workspace_path.out/Cargo.toml new file mode 100644 index 00000000000..57e1f30855f --- /dev/null +++ b/tests/snapshots/add/workspace_path.out/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["primary", "dependency"] diff --git a/tests/snapshots/add/workspace_path.out/dependency/Cargo.toml b/tests/snapshots/add/workspace_path.out/dependency/Cargo.toml new file mode 100644 index 00000000000..ca4f36d72f7 --- /dev/null +++ b/tests/snapshots/add/workspace_path.out/dependency/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/workspace_path.out/primary/Cargo.toml b/tests/snapshots/add/workspace_path.out/primary/Cargo.toml new file mode 100644 index 00000000000..a693df54f88 --- /dev/null +++ b/tests/snapshots/add/workspace_path.out/primary/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +cargo-list-test-fixture-dependency = { version = "0.0.0", path = "../dependency" } diff --git a/tests/snapshots/add/workspace_path.stderr b/tests/snapshots/add/workspace_path.stderr new file mode 100644 index 00000000000..8109d3cc54b --- /dev/null +++ b/tests/snapshots/add/workspace_path.stderr @@ -0,0 +1 @@ + Adding cargo-list-test-fixture-dependency (local) to dependencies. diff --git a/tests/snapshots/add/workspace_path.stdout b/tests/snapshots/add/workspace_path.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/workspace_path_dev.in/Cargo.toml b/tests/snapshots/add/workspace_path_dev.in/Cargo.toml new file mode 100644 index 00000000000..57e1f30855f --- /dev/null +++ b/tests/snapshots/add/workspace_path_dev.in/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["primary", "dependency"] diff --git a/tests/snapshots/add/workspace_path_dev.in/dependency/Cargo.toml b/tests/snapshots/add/workspace_path_dev.in/dependency/Cargo.toml new file mode 100644 index 00000000000..ca4f36d72f7 --- /dev/null +++ b/tests/snapshots/add/workspace_path_dev.in/dependency/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/workspace_path_dev.in/dependency/src/lib.rs b/tests/snapshots/add/workspace_path_dev.in/dependency/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/workspace_path_dev.in/primary/Cargo.toml b/tests/snapshots/add/workspace_path_dev.in/primary/Cargo.toml new file mode 100644 index 00000000000..5e20016d710 --- /dev/null +++ b/tests/snapshots/add/workspace_path_dev.in/primary/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/snapshots/add/workspace_path_dev.in/primary/src/lib.rs b/tests/snapshots/add/workspace_path_dev.in/primary/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/add/workspace_path_dev.out/Cargo.toml b/tests/snapshots/add/workspace_path_dev.out/Cargo.toml new file mode 100644 index 00000000000..57e1f30855f --- /dev/null +++ b/tests/snapshots/add/workspace_path_dev.out/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["primary", "dependency"] diff --git a/tests/snapshots/add/workspace_path_dev.out/dependency/Cargo.toml b/tests/snapshots/add/workspace_path_dev.out/dependency/Cargo.toml new file mode 100644 index 00000000000..ca4f36d72f7 --- /dev/null +++ b/tests/snapshots/add/workspace_path_dev.out/dependency/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "cargo-list-test-fixture-dependency" +version = "0.0.0" diff --git a/tests/snapshots/add/workspace_path_dev.out/primary/Cargo.toml b/tests/snapshots/add/workspace_path_dev.out/primary/Cargo.toml new file mode 100644 index 00000000000..8dfa5c218b3 --- /dev/null +++ b/tests/snapshots/add/workspace_path_dev.out/primary/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dev-dependencies] +cargo-list-test-fixture-dependency = { path = "../dependency" } diff --git a/tests/snapshots/add/workspace_path_dev.stderr b/tests/snapshots/add/workspace_path_dev.stderr new file mode 100644 index 00000000000..d8093d6aece --- /dev/null +++ b/tests/snapshots/add/workspace_path_dev.stderr @@ -0,0 +1 @@ + Adding cargo-list-test-fixture-dependency (local) to dev-dependencies. diff --git a/tests/snapshots/add/workspace_path_dev.stdout b/tests/snapshots/add/workspace_path_dev.stdout new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/snapshots/copy.sh b/tests/snapshots/copy.sh new file mode 100755 index 00000000000..c09d9a3c845 --- /dev/null +++ b/tests/snapshots/copy.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +BEFORE=$1 +AFTER=$2 +if [ -z "${BEFORE}" ] || [ -z "${AFTER}" ]; then + echo "Copy a snapshot" + echo + echo "Run this from the snapshots directory, using the base name for the snapshots" + echo + echo "Usage: $0 " + exit 1 +fi + +IN_LINK=$(readlink $1.in) +if [ -n "${IN_LINK}" ]; then + echo "Linking to '${IN_LINK}'" + ln -s ${IN_LINK} $2.in +elif [ -e "$1.in" ]; then + echo "Copying '$1.in'" + cp -r $1.in $2.in +else + echo "No '$1.in'" +fi +if [ -e "$1.out" ]; then + echo "Copying '$1.out'" + cp -r $1.out $2.out +else + echo "No '$1.out'" +fi +if [ -e "$1.stdout" ]; then + echo "Copying '$1.stdout'" + cp -r $1.stdout $2.stdout +else + echo "No '$1.stdout'" +fi +if [ -e "$1.stderr" ]; then + echo "Copying '$1.stderr'" + cp -r $1.stderr $2.stderr +else + echo "No '$1.stderr'" +fi +git add $2.* diff --git a/tests/snapshots/rename.sh b/tests/snapshots/rename.sh new file mode 100755 index 00000000000..4c854f5ac62 --- /dev/null +++ b/tests/snapshots/rename.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +BEFORE=$1 +AFTER=$2 +if [ -z "${BEFORE}" ] || [ -z "${AFTER}" ]; then + echo "Rename a snapshot" + echo + echo "Run this from the snapshots directory, using the base name for the snapshots" + echo + echo "Usage: $0 " + exit 1 +fi + +if [ -e "$1.stdout" ]; then + echo "Renaming '$1.in" + mv $1.in $2.in +else + echo "No '$1.in'" +fi +if [ -e "$1.stdout" ]; then + echo "Renaming '$1.out" + mv $1.out $2.out +else + echo "No '$1.out'" +fi +if [ -e "$1.stdout" ]; then + echo "Renaming '$1.stdout" + mv $1.stdout $2.stdout +else + echo "No '$1.stdout'" +fi +if [ -e "$1.stderr" ]; then + echo "Renaming '$1.stderr'" + mv $1.stderr $2.stderr +else + echo "No '$1.stderr'" +fi +git add $2.* diff --git a/tests/testsuite/cargo_add.rs b/tests/testsuite/cargo_add.rs new file mode 100644 index 00000000000..20a48ddbe3f --- /dev/null +++ b/tests/testsuite/cargo_add.rs @@ -0,0 +1,2110 @@ +pub fn cargo_exe() -> &'static std::path::Path { + snapbox::cmd::cargo_bin!("cargo") +} + +pub fn cargo_command() -> snapbox::cmd::Command { + let mut cmd = snapbox::cmd::Command::new(cargo_exe()).with_assert(assert()); + + // In general just clear out all cargo-specific configuration already in the + // environment. Our tests all assume a "default configuration" unless + // specified otherwise. + for (k, _v) in std::env::vars() { + if k.starts_with("CARGO_") { + cmd = cmd.env_remove(&k); + } + } + + cmd = cmd + .env("HOME", cargo_test_support::paths::home()) + .env( + "CARGO_HOME", + cargo_test_support::paths::home().join(".cargo"), + ) + .env("__CARGO_TEST_ROOT", cargo_test_support::paths::root()) + // Force Cargo to think it's on the stable channel for all tests, this + // should hopefully not surprise us as we add cargo features over time and + // cargo rides the trains. + .env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "stable") + // For now disable incremental by default as support hasn't ridden to the + // stable channel yet. Once incremental support hits the stable compiler we + // can switch this to one and then fix the tests. + .env("CARGO_INCREMENTAL", "0") + .env_remove("__CARGO_DEFAULT_LIB_METADATA") + .env_remove("RUSTC") + .env_remove("RUSTDOC") + .env_remove("RUSTC_WRAPPER") + .env_remove("RUSTFLAGS") + .env_remove("RUSTDOCFLAGS") + .env_remove("XDG_CONFIG_HOME") // see #2345 + .env("GIT_CONFIG_NOSYSTEM", "1") // keep trying to sandbox ourselves + .env_remove("EMAIL") + .env_remove("USER") // not set on some rust-lang docker images + .env_remove("MFLAGS") + .env_remove("MAKEFLAGS") + .env_remove("GIT_AUTHOR_NAME") + .env_remove("GIT_AUTHOR_EMAIL") + .env_remove("GIT_COMMITTER_NAME") + .env_remove("GIT_COMMITTER_EMAIL") + .env_remove("MSYSTEM"); // assume cmd.exe everywhere on windows + + cmd +} + +pub fn project_from_template(template_path: impl AsRef) -> std::path::PathBuf { + let root = cargo_test_support::paths::root(); + let project_root = root.join("case"); + snapbox::path::copy_template(template_path.as_ref(), &project_root).unwrap(); + project_root +} + +pub fn assert() -> snapbox::Assert { + let root = cargo_test_support::paths::root(); + // Use `from_file_path` instead of `from_dir_path` so the trailing slash is + // put in the users output, rather than hidden in the variable + let root_url = url::Url::from_file_path(&root).unwrap().to_string(); + let root = root.display().to_string(); + + let mut subs = snapbox::Substitutions::new(); + subs.extend([ + ( + "[EXE]", + std::borrow::Cow::Borrowed(std::env::consts::EXE_SUFFIX), + ), + ("[ROOT]", std::borrow::Cow::Owned(root)), + ("[ROOTURL]", std::borrow::Cow::Owned(root_url)), + ]) + .unwrap(); + snapbox::Assert::new() + .action_env(snapbox::DEFAULT_ACTION_ENV) + .substitutions(subs) +} + +fn init_registry() { + cargo_test_support::registry::init(); + add_registry_packages(false); +} + +fn init_alt_registry() { + cargo_test_support::registry::alt_init(); + add_registry_packages(true); +} + +fn add_registry_packages(alt: bool) { + for name in [ + "my-package", + "my-package1", + "my-package2", + "my-dev-package1", + "my-dev-package2", + "my-build-package1", + "my-build-package2", + "toml", + "versioned-package", + "cargo-list-test-fixture-dependency", + "unrelateed-crate", + ] { + cargo_test_support::registry::Package::new(name, "0.1.1+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, "20.0.0+my-package") + .alternative(alt) + .publish(); + cargo_test_support::registry::Package::new(name, "99999.0.0+my-package") + .alternative(alt) + .publish(); + cargo_test_support::registry::Package::new(name, "99999.0.0-alpha.1+my-package") + .alternative(alt) + .publish(); + } + + cargo_test_support::registry::Package::new("prerelease_only", "0.2.0-alpha.1") + .alternative(alt) + .publish(); + cargo_test_support::registry::Package::new("test_breaking", "0.2.0") + .alternative(alt) + .publish(); + cargo_test_support::registry::Package::new("test_nonbreaking", "0.1.1") + .alternative(alt) + .publish(); + + // Normalization + cargo_test_support::registry::Package::new("linked-hash-map", "0.5.4") + .alternative(alt) + .feature("clippy", &[]) + .feature("heapsize", &[]) + .feature("heapsize_impl", &[]) + .feature("nightly", &[]) + .feature("serde", &[]) + .feature("serde_impl", &[]) + .feature("serde_test", &[]) + .publish(); + cargo_test_support::registry::Package::new("inflector", "0.11.4") + .alternative(alt) + .feature("default", &["heavyweight", "lazy_static", "regex"]) + .feature("heavyweight", &[]) + .feature("lazy_static", &[]) + .feature("regex", &[]) + .feature("unstable", &[]) + .publish(); + + cargo_test_support::registry::Package::new("your-face", "99999.0.0+my-package") + .alternative(alt) + .feature("nose", &[]) + .feature("mouth", &[]) + .feature("eyes", &[]) + .feature("ears", &[]) + .publish(); +} + +#[cargo_test] +fn add_basic() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/add_basic.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/add_basic.stdout") + .stderr_matches_path("tests/snapshots/add/add_basic.stderr"); + + assert().subset_matches("tests/snapshots/add/add_basic.out", &project_root); +} + +#[cargo_test] +fn add_multiple() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/add_multiple.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/add_multiple.stdout") + .stderr_matches_path("tests/snapshots/add/add_multiple.stderr"); + + assert().subset_matches("tests/snapshots/add/add_multiple.out", &project_root); +} + +#[cargo_test] +fn quiet() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/quiet.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["--quiet", "your-face"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/quiet.stdout") + .stderr_matches_path("tests/snapshots/add/quiet.stderr"); + + assert().subset_matches("tests/snapshots/add/quiet.out", &project_root); +} + +#[cargo_test] +fn add_normalized_name_external() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/add_normalized_name_external.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["linked_hash_map", "Inflector"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/add_normalized_name_external.stdout") + .stderr_matches_path("tests/snapshots/add/add_normalized_name_external.stderr"); + + assert().subset_matches( + "tests/snapshots/add/add_normalized_name_external.out", + &project_root, + ); +} + +#[cargo_test] +fn infer_prerelease() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/infer_prerelease.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["prerelease_only"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/infer_prerelease.stdout") + .stderr_matches_path("tests/snapshots/add/infer_prerelease.stderr"); + + assert().subset_matches("tests/snapshots/add/infer_prerelease.out", &project_root); +} + +#[cargo_test] +fn build() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/build.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["--build", "my-build-package1", "my-build-package2"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/build.stdout") + .stderr_matches_path("tests/snapshots/add/build.stderr"); + + assert().subset_matches("tests/snapshots/add/build.out", &project_root); +} + +#[cargo_test] +fn build_prefer_existing_version() { + init_alt_registry(); + let project_root = + project_from_template("tests/snapshots/add/build_prefer_existing_version.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["cargo-list-test-fixture-dependency", "--build"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/build_prefer_existing_version.stdout") + .stderr_matches_path("tests/snapshots/add/build_prefer_existing_version.stderr"); + + assert().subset_matches( + "tests/snapshots/add/build_prefer_existing_version.out", + &project_root, + ); +} + +#[cargo_test] +fn default_features() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/default_features.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2@0.4.1", "--default-features"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/default_features.stdout") + .stderr_matches_path("tests/snapshots/add/default_features.stderr"); + + assert().subset_matches("tests/snapshots/add/default_features.out", &project_root); +} + +#[cargo_test] +fn require_weak() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/require_weak.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["your-face", "--no-optional"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/require_weak.stdout") + .stderr_matches_path("tests/snapshots/add/require_weak.stderr"); + + assert().subset_matches("tests/snapshots/add/require_weak.out", &project_root); +} + +#[cargo_test] +fn dev() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/dev.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["--dev", "my-dev-package1", "my-dev-package2"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/dev.stdout") + .stderr_matches_path("tests/snapshots/add/dev.stderr"); + + assert().subset_matches("tests/snapshots/add/dev.out", &project_root); +} + +#[cargo_test] +fn dev_build_conflict() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/dev_build_conflict.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package", "--dev", "--build"]) + .current_dir(cwd) + .assert() + .code(1) + .stdout_matches_path("tests/snapshots/add/dev_build_conflict.stdout") + .stderr_matches_path("tests/snapshots/add/dev_build_conflict.stderr"); + + assert().subset_matches("tests/snapshots/add/dev_build_conflict.out", &project_root); +} + +#[cargo_test] +fn dev_prefer_existing_version() { + init_alt_registry(); + let project_root = project_from_template("tests/snapshots/add/dev_prefer_existing_version.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["cargo-list-test-fixture-dependency", "--dev"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/dev_prefer_existing_version.stdout") + .stderr_matches_path("tests/snapshots/add/dev_prefer_existing_version.stderr"); + + assert().subset_matches( + "tests/snapshots/add/dev_prefer_existing_version.out", + &project_root, + ); +} + +#[cargo_test] +fn dry_run() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/dry_run.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package", "--dry-run"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/dry_run.stdout") + .stderr_matches_path("tests/snapshots/add/dry_run.stderr"); + + assert().subset_matches("tests/snapshots/add/dry_run.out", &project_root); +} + +#[cargo_test] +fn features() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/features.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["your-face", "--features", "eyes"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/features.stdout") + .stderr_matches_path("tests/snapshots/add/features.stderr"); + + assert().subset_matches("tests/snapshots/add/features.out", &project_root); +} + +#[cargo_test] +fn features_empty() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/features_empty.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["your-face", "--features", ""]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/features_empty.stdout") + .stderr_matches_path("tests/snapshots/add/features_empty.stderr"); + + assert().subset_matches("tests/snapshots/add/features_empty.out", &project_root); +} + +#[cargo_test] +fn features_multiple_occurrences() { + init_registry(); + let project_root = + project_from_template("tests/snapshots/add/features_multiple_occurrences.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["your-face", "--features", "eyes", "--features", "nose"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/features_multiple_occurrences.stdout") + .stderr_matches_path("tests/snapshots/add/features_multiple_occurrences.stderr"); + + assert().subset_matches( + "tests/snapshots/add/features_multiple_occurrences.out", + &project_root, + ); +} + +#[cargo_test] +fn features_preserve() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/features_preserve.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["your-face"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/features_preserve.stdout") + .stderr_matches_path("tests/snapshots/add/features_preserve.stderr"); + + assert().subset_matches("tests/snapshots/add/features_preserve.out", &project_root); +} + +#[cargo_test] +fn features_spaced_values() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/features_spaced_values.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["your-face", "--features", "eyes nose"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/features_spaced_values.stdout") + .stderr_matches_path("tests/snapshots/add/features_spaced_values.stderr"); + + assert().subset_matches( + "tests/snapshots/add/features_spaced_values.out", + &project_root, + ); +} + +#[cargo_test] +fn features_unknown() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/features_unknown.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["your-face", "--features", "noze"]) + .current_dir(cwd) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/add/features_unknown.stdout") + .stderr_matches_path("tests/snapshots/add/features_unknown.stderr"); + + assert().subset_matches("tests/snapshots/add/features_unknown.out", &project_root); +} + +#[cargo_test] +fn git() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/git.in"); + let cwd = &project_root; + let git_dep = cargo_test_support::git::new("git-package", |project| { + project + .file( + "Cargo.toml", + &cargo_test_support::basic_manifest("git-package", "0.3.0+git-package"), + ) + .file("src/lib.rs", "") + }); + let git_url = git_dep.url().to_string(); + + cargo_command() + .arg("add") + .args(["git-package", "--git", &git_url]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/git.stdout") + .stderr_matches_path("tests/snapshots/add/git.stderr"); + + assert().subset_matches("tests/snapshots/add/git.out", &project_root); +} + +#[cargo_test] +fn git_inferred_name() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/git_inferred_name.in"); + let cwd = &project_root; + let git_dep = cargo_test_support::git::new("git-package", |project| { + project + .file( + "Cargo.toml", + &cargo_test_support::basic_manifest("git-package", "0.3.0+git-package"), + ) + .file("src/lib.rs", "") + }); + let git_url = git_dep.url().to_string(); + + cargo_command() + .arg("add") + .args(["--git", &git_url]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/git_inferred_name.stdout") + .stderr_matches_path("tests/snapshots/add/git_inferred_name.stderr"); + + assert().subset_matches("tests/snapshots/add/git_inferred_name.out", &project_root); +} + +#[cargo_test] +fn git_inferred_name_multiple() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/git_inferred_name_multiple.in"); + let cwd = &project_root; + let git_dep = cargo_test_support::git::new("git-package", |project| { + project + .file( + "p1/Cargo.toml", + &cargo_test_support::basic_manifest("my-package1", "0.3.0+my-package1"), + ) + .file("p1/src/lib.rs", "") + .file( + "p2/Cargo.toml", + &cargo_test_support::basic_manifest("my-package2", "0.3.0+my-package2"), + ) + .file("p2/src/lib.rs", "") + }); + let git_url = git_dep.url().to_string(); + + cargo_command() + .arg("add") + .args(["--git", &git_url]) + .current_dir(cwd) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/add/git_inferred_name_multiple.stdout") + .stderr_matches_path("tests/snapshots/add/git_inferred_name_multiple.stderr"); + + assert().subset_matches( + "tests/snapshots/add/git_inferred_name_multiple.out", + &project_root, + ); +} + +#[cargo_test] +fn git_normalized_name() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/git_normalized_name.in"); + let cwd = &project_root; + let git_dep = cargo_test_support::git::new("git-package", |project| { + project + .file( + "Cargo.toml", + &cargo_test_support::basic_manifest("git-package", "0.3.0+git-package"), + ) + .file("src/lib.rs", "") + }); + let git_url = git_dep.url().to_string(); + + cargo_command() + .arg("add") + .args(["git_package", "--git", &git_url]) + .current_dir(cwd) + .assert() + .failure() // Fuzzy searching for paths isn't supported at this time + .stdout_matches_path("tests/snapshots/add/git_normalized_name.stdout") + .stderr_matches_path("tests/snapshots/add/git_normalized_name.stderr"); + + assert().subset_matches("tests/snapshots/add/git_normalized_name.out", &project_root); +} + +#[cargo_test] +fn invalid_git_name() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/invalid_git_name.in"); + let cwd = &project_root; + let git_dep = cargo_test_support::git::new("git-package", |project| { + project + .file( + "Cargo.toml", + &cargo_test_support::basic_manifest("git-package", "0.3.0+git-package"), + ) + .file("src/lib.rs", "") + }); + let git_url = git_dep.url().to_string(); + + cargo_command() + .arg("add") + .args(["not-in-git", "--git", &git_url]) + .current_dir(cwd) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/add/invalid_git_name.stdout") + .stderr_matches_path("tests/snapshots/add/invalid_git_name.stderr"); + + assert().subset_matches("tests/snapshots/add/invalid_git_name.out", &project_root); +} + +#[cargo_test] +fn git_branch() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/git_branch.in"); + let cwd = &project_root; + let (git_dep, git_repo) = cargo_test_support::git::new_repo("git-package", |project| { + project + .file( + "Cargo.toml", + &cargo_test_support::basic_manifest("git-package", "0.3.0+git-package"), + ) + .file("src/lib.rs", "") + }); + let branch = "dev"; + let find_head = || (git_repo.head().unwrap().peel_to_commit().unwrap()); + git_repo.branch(branch, &find_head(), false).unwrap(); + let git_url = git_dep.url().to_string(); + + cargo_command() + .arg("add") + .args(["git-package", "--git", &git_url, "--branch", branch]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/git_branch.stdout") + .stderr_matches_path("tests/snapshots/add/git_branch.stderr"); + + assert().subset_matches("tests/snapshots/add/git_branch.out", &project_root); +} + +#[cargo_test] +fn git_conflicts_namever() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/git_conflicts_namever.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args([ + "my-package@0.4.3", + "--git", + "https://github.com/dcjanus/invalid", + ]) + .current_dir(cwd) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/add/git_conflicts_namever.stdout") + .stderr_matches_path("tests/snapshots/add/git_conflicts_namever.stderr"); + + assert().subset_matches( + "tests/snapshots/add/git_conflicts_namever.out", + &project_root, + ); +} + +#[cargo_test] +fn git_registry() { + init_alt_registry(); + let project_root = project_from_template("tests/snapshots/add/git_registry.in"); + let cwd = &project_root; + let git_dep = cargo_test_support::git::new("versioned-package", |project| { + project + .file( + "Cargo.toml", + &cargo_test_support::basic_manifest("versioned-package", "0.3.0+versioned-package"), + ) + .file("src/lib.rs", "") + }); + let git_url = git_dep.url().to_string(); + + cargo_command() + .arg("add") + .args([ + "versioned-package", + "--git", + &git_url, + "--registry", + "alternative", + ]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/git_registry.stdout") + .stderr_matches_path("tests/snapshots/add/git_registry.stderr"); + + assert().subset_matches("tests/snapshots/add/git_registry.out", &project_root); +} + +#[cargo_test] +fn git_dev() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/git_dev.in"); + let cwd = &project_root; + let git_dep = cargo_test_support::git::new("git-package", |project| { + project + .file( + "Cargo.toml", + &cargo_test_support::basic_manifest("git-package", "0.3.0+git-package"), + ) + .file("src/lib.rs", "") + }); + let git_url = git_dep.url().to_string(); + + cargo_command() + .arg("add") + .args(["git-package", "--git", &git_url, "--dev"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/git_dev.stdout") + .stderr_matches_path("tests/snapshots/add/git_dev.stderr"); + + assert().subset_matches("tests/snapshots/add/git_dev.out", &project_root); +} + +#[cargo_test] +fn git_rev() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/git_rev.in"); + let cwd = &project_root; + let (git_dep, git_repo) = cargo_test_support::git::new_repo("git-package", |project| { + project + .file( + "Cargo.toml", + &cargo_test_support::basic_manifest("git-package", "0.3.0+git-package"), + ) + .file("src/lib.rs", "") + }); + let find_head = || (git_repo.head().unwrap().peel_to_commit().unwrap()); + let head = find_head().id().to_string(); + let git_url = git_dep.url().to_string(); + + cargo_command() + .arg("add") + .args(["git-package", "--git", &git_url, "--rev", &head]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/git_rev.stdout") + .stderr_matches_path("tests/snapshots/add/git_rev.stderr"); + + assert().subset_matches("tests/snapshots/add/git_rev.out", &project_root); +} + +#[cargo_test] +fn git_tag() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/git_tag.in"); + let cwd = &project_root; + let (git_dep, git_repo) = cargo_test_support::git::new_repo("git-package", |project| { + project + .file( + "Cargo.toml", + &cargo_test_support::basic_manifest("git-package", "0.3.0+git-package"), + ) + .file("src/lib.rs", "") + }); + let tag = "v1.0.0"; + cargo_test_support::git::tag(&git_repo, tag); + let git_url = git_dep.url().to_string(); + + cargo_command() + .arg("add") + .args(["git-package", "--git", &git_url, "--tag", tag]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/git_tag.stdout") + .stderr_matches_path("tests/snapshots/add/git_tag.stderr"); + + assert().subset_matches("tests/snapshots/add/git_tag.out", &project_root); +} + +#[cargo_test] +fn path() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/path.in"); + let cwd = project_root.join("primary"); + + cargo_command() + .arg("add") + .args([ + "cargo-list-test-fixture-dependency", + "--path", + "../dependency", + ]) + .current_dir(&cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/path.stdout") + .stderr_matches_path("tests/snapshots/add/path.stderr"); + + assert().subset_matches("tests/snapshots/add/path.out", &project_root); +} + +#[cargo_test] +fn path_inferred_name() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/path_inferred_name.in"); + let cwd = project_root.join("primary"); + + cargo_command() + .arg("add") + .args([ + "cargo-list-test-fixture-dependency", + "--path", + "../dependency", + ]) + .current_dir(&cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/path_inferred_name.stdout") + .stderr_matches_path("tests/snapshots/add/path_inferred_name.stderr"); + + assert().subset_matches("tests/snapshots/add/path_inferred_name.out", &project_root); +} + +#[cargo_test] +fn path_inferred_name_conflicts_full_feature() { + init_registry(); + let project_root = + project_from_template("tests/snapshots/add/path_inferred_name_conflicts_full_feature.in"); + let cwd = project_root.join("primary"); + + cargo_command() + .arg("add") + .args(["--path", "../dependency", "--features", "your-face/nose"]) + .current_dir(&cwd) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/add/path_inferred_name_conflicts_full_feature.stdout") + .stderr_matches_path( + "tests/snapshots/add/path_inferred_name_conflicts_full_feature.stderr", + ); + + assert().subset_matches( + "tests/snapshots/add/path_inferred_name_conflicts_full_feature.out", + &project_root, + ); +} + +#[cargo_test] +fn path_normalized_name() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/path_normalized_name.in"); + let cwd = project_root.join("primary"); + + cargo_command() + .arg("add") + .args([ + "cargo_list_test_fixture_dependency", + "--path", + "../dependency", + ]) + .current_dir(&cwd) + .assert() + .failure() // Fuzzy searching for paths isn't supported at this time + .stdout_matches_path("tests/snapshots/add/path_normalized_name.stdout") + .stderr_matches_path("tests/snapshots/add/path_normalized_name.stderr"); + + assert().subset_matches( + "tests/snapshots/add/path_normalized_name.out", + &project_root, + ); +} + +#[cargo_test] +fn invalid_path_name() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/invalid_path_name.in"); + let cwd = project_root.join("primary"); + + cargo_command() + .arg("add") + .args(["not-at-path", "--path", "../dependency"]) + .current_dir(&cwd) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/add/invalid_path_name.stdout") + .stderr_matches_path("tests/snapshots/add/invalid_path_name.stderr"); + + assert().subset_matches("tests/snapshots/add/invalid_path_name.out", &project_root); +} + +#[cargo_test] +fn path_dev() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/path_dev.in"); + let cwd = project_root.join("primary"); + + cargo_command() + .arg("add") + .args([ + "cargo-list-test-fixture-dependency", + "--path", + "../dependency", + "--dev", + ]) + .current_dir(&cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/path_dev.stdout") + .stderr_matches_path("tests/snapshots/add/path_dev.stderr"); + + assert().subset_matches("tests/snapshots/add/path_dev.out", &project_root); +} + +#[cargo_test] +fn invalid_arg() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/invalid_arg.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package", "--flag"]) + .current_dir(cwd) + .assert() + .code(1) + .stdout_matches_path("tests/snapshots/add/invalid_arg.stdout") + .stderr_matches_path("tests/snapshots/add/invalid_arg.stderr"); + + assert().subset_matches("tests/snapshots/add/invalid_arg.out", &project_root); +} + +#[cargo_test] +fn invalid_git_external() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/invalid_git_external.in"); + let cwd = &project_root; + let git_url = url::Url::from_directory_path(cwd.join("does-not-exist")) + .unwrap() + .to_string(); + + cargo_command() + .arg("add") + .args(["fake-git", "--git", &git_url]) + .current_dir(cwd) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/add/invalid_git_external.stdout") + .stderr_matches_path("tests/snapshots/add/invalid_git_external.stderr"); + + assert().subset_matches( + "tests/snapshots/add/invalid_git_external.out", + &project_root, + ); +} + +#[cargo_test] +fn invalid_path() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/invalid_path.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args([ + "cargo-list-test-fixture", + "--path", + "./tests/fixtures/local", + ]) + .current_dir(cwd) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/add/invalid_path.stdout") + .stderr_matches_path("tests/snapshots/add/invalid_path.stderr"); + + assert().subset_matches("tests/snapshots/add/invalid_path.out", &project_root); +} + +#[cargo_test] +fn invalid_path_self() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/invalid_path_self.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["cargo-list-test-fixture", "--path", "."]) + .current_dir(cwd) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/add/invalid_path_self.stdout") + .stderr_matches_path("tests/snapshots/add/invalid_path_self.stderr"); + + assert().subset_matches("tests/snapshots/add/invalid_path_self.out", &project_root); +} + +#[cargo_test] +fn invalid_manifest() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/invalid_manifest.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package"]) + .current_dir(cwd) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/add/invalid_manifest.stdout") + .stderr_matches_path("tests/snapshots/add/invalid_manifest.stderr"); + + assert().subset_matches("tests/snapshots/add/invalid_manifest.out", &project_root); +} + +#[cargo_test] +fn invalid_name_external() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/invalid_name_external.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["lets_hope_nobody_ever_publishes_this_crate"]) + .current_dir(cwd) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/add/invalid_name_external.stdout") + .stderr_matches_path("tests/snapshots/add/invalid_name_external.stderr"); + + assert().subset_matches( + "tests/snapshots/add/invalid_name_external.out", + &project_root, + ); +} + +#[cargo_test] +fn invalid_target_empty() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/invalid_target_empty.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package", "--target", ""]) + .current_dir(cwd) + .assert() + .code(1) + .stdout_matches_path("tests/snapshots/add/invalid_target_empty.stdout") + .stderr_matches_path("tests/snapshots/add/invalid_target_empty.stderr"); + + assert().subset_matches( + "tests/snapshots/add/invalid_target_empty.out", + &project_root, + ); +} + +#[cargo_test] +fn invalid_vers() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/invalid_vers.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package@invalid version string"]) + .current_dir(cwd) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/add/invalid_vers.stdout") + .stderr_matches_path("tests/snapshots/add/invalid_vers.stderr"); + + assert().subset_matches("tests/snapshots/add/invalid_vers.out", &project_root); +} + +#[cargo_test] +fn list_features() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/list_features.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["your-face"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/list_features.stdout") + .stderr_matches_path("tests/snapshots/add/list_features.stderr"); + + assert().subset_matches("tests/snapshots/add/list_features.out", &project_root); +} + +#[cargo_test] +fn list_features_path() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/list_features_path.in"); + let cwd = project_root.join("primary"); + + cargo_command() + .arg("add") + .args(["your-face", "--path", "../dependency"]) + .current_dir(&cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/list_features_path.stdout") + .stderr_matches_path("tests/snapshots/add/list_features_path.stderr"); + + assert().subset_matches("tests/snapshots/add/list_features_path.out", &project_root); +} + +#[cargo_test] +fn list_features_path_no_default() { + init_registry(); + let project_root = + project_from_template("tests/snapshots/add/list_features_path_no_default.in"); + let cwd = project_root.join("primary"); + + cargo_command() + .arg("add") + .args([ + "your-face", + "--path", + "../dependency", + "--no-default-features", + ]) + .current_dir(&cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/list_features_path_no_default.stdout") + .stderr_matches_path("tests/snapshots/add/list_features_path_no_default.stderr"); + + assert().subset_matches( + "tests/snapshots/add/list_features_path_no_default.out", + &project_root, + ); +} + +#[cargo_test] +fn manifest_path_package() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/manifest_path_package.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args([ + "--manifest-path", + "Cargo.toml", + "--package", + "cargo-list-test-fixture", + "cargo-list-test-fixture-dependency", + ]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/manifest_path_package.stdout") + .stderr_matches_path("tests/snapshots/add/manifest_path_package.stderr"); + + assert().subset_matches( + "tests/snapshots/add/manifest_path_package.out", + &project_root, + ); +} + +#[cargo_test] +fn multiple_conflicts_with_features() { + init_registry(); + let project_root = + project_from_template("tests/snapshots/add/multiple_conflicts_with_features.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "your-face", "--features", "nose"]) + .current_dir(cwd) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/add/multiple_conflicts_with_features.stdout") + .stderr_matches_path("tests/snapshots/add/multiple_conflicts_with_features.stderr"); + + assert().subset_matches( + "tests/snapshots/add/multiple_conflicts_with_features.out", + &project_root, + ); +} + +#[cargo_test] +fn git_multiple_names() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/git_multiple_names.in"); + let cwd = &project_root; + let git_dep = cargo_test_support::git::new("git-package", |project| { + project + .file( + "p1/Cargo.toml", + &cargo_test_support::basic_manifest("my-package1", "0.3.0+my-package1"), + ) + .file("p1/src/lib.rs", "") + .file( + "p2/Cargo.toml", + &cargo_test_support::basic_manifest("my-package2", "0.3.0+my-package2"), + ) + .file("p2/src/lib.rs", "") + }); + let git_url = git_dep.url().to_string(); + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2", "--git", &git_url]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/git_multiple_names.stdout") + .stderr_matches_path("tests/snapshots/add/git_multiple_names.stderr"); + + assert().subset_matches("tests/snapshots/add/git_multiple_names.out", &project_root); +} + +#[cargo_test] +fn multiple_conflicts_with_rename() { + init_registry(); + let project_root = + project_from_template("tests/snapshots/add/multiple_conflicts_with_rename.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2", "--rename", "renamed"]) + .current_dir(cwd) + .assert() + .code(101) + .stdout_matches_path("tests/snapshots/add/multiple_conflicts_with_rename.stdout") + .stderr_matches_path("tests/snapshots/add/multiple_conflicts_with_rename.stderr"); + + assert().subset_matches( + "tests/snapshots/add/multiple_conflicts_with_rename.out", + &project_root, + ); +} + +#[cargo_test] +fn namever() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/namever.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1@>=0.1.1", "my-package2@0.2.3", "my-package"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/namever.stdout") + .stderr_matches_path("tests/snapshots/add/namever.stderr"); + + assert().subset_matches("tests/snapshots/add/namever.out", &project_root); +} + +#[cargo_test] +fn no_args() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/no_args.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .current_dir(cwd) + .assert() + .code(1) + .stdout_matches_path("tests/snapshots/add/no_args.stdout") + .stderr_matches_path("tests/snapshots/add/no_args.stderr"); + + assert().subset_matches("tests/snapshots/add/no_args.out", &project_root); +} + +#[cargo_test] +fn no_default_features() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/no_default_features.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2@0.4.1", "--no-default-features"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/no_default_features.stdout") + .stderr_matches_path("tests/snapshots/add/no_default_features.stderr"); + + assert().subset_matches("tests/snapshots/add/no_default_features.out", &project_root); +} + +#[cargo_test] +fn no_optional() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/no_optional.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2@0.4.1", "--no-optional"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/no_optional.stdout") + .stderr_matches_path("tests/snapshots/add/no_optional.stderr"); + + assert().subset_matches("tests/snapshots/add/no_optional.out", &project_root); +} + +#[cargo_test] +fn optional() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/optional.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2@0.4.1", "--optional"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/optional.stdout") + .stderr_matches_path("tests/snapshots/add/optional.stderr"); + + assert().subset_matches("tests/snapshots/add/optional.out", &project_root); +} + +#[cargo_test] +fn overwrite_default_features() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/overwrite_default_features.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2@0.4.1", "--default-features"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_default_features.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_default_features.stderr"); + + assert().subset_matches( + "tests/snapshots/add/overwrite_default_features.out", + &project_root, + ); +} + +#[cargo_test] +fn overwrite_default_features_with_no_default_features() { + init_registry(); + let project_root = project_from_template( + "tests/snapshots/add/overwrite_default_features_with_no_default_features.in", + ); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2@0.4.1", "--no-default-features"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path( + "tests/snapshots/add/overwrite_default_features_with_no_default_features.stdout", + ) + .stderr_matches_path( + "tests/snapshots/add/overwrite_default_features_with_no_default_features.stderr", + ); + + assert().subset_matches( + "tests/snapshots/add/overwrite_default_features_with_no_default_features.out", + &project_root, + ); +} + +#[cargo_test] +fn overwrite_features() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/overwrite_features.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["your-face", "--features", "nose"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_features.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_features.stderr"); + + assert().subset_matches("tests/snapshots/add/overwrite_features.out", &project_root); +} + +#[cargo_test] +fn overwrite_git_with_path() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/overwrite_git_with_path.in"); + let cwd = project_root.join("primary"); + + cargo_command() + .arg("add") + .args([ + "cargo-list-test-fixture-dependency", + "--path", + "../dependency", + ]) + .current_dir(&cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_git_with_path.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_git_with_path.stderr"); + + assert().subset_matches( + "tests/snapshots/add/overwrite_git_with_path.out", + &project_root, + ); +} + +#[cargo_test] +fn overwrite_inline_features() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/overwrite_inline_features.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args([ + "unrelateed-crate", + "your-face", + "--features", + "your-face/nose,your-face/mouth", + "-Fyour-face/ears", + ]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_inline_features.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_inline_features.stderr"); + + assert().subset_matches( + "tests/snapshots/add/overwrite_inline_features.out", + &project_root, + ); +} + +#[cargo_test] +fn overwrite_name_dev_noop() { + init_alt_registry(); + let project_root = project_from_template("tests/snapshots/add/overwrite_name_dev_noop.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["your-face", "--dev"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_name_dev_noop.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_name_dev_noop.stderr"); + + assert().subset_matches( + "tests/snapshots/add/overwrite_name_dev_noop.out", + &project_root, + ); +} + +#[cargo_test] +fn overwrite_name_noop() { + init_alt_registry(); + let project_root = project_from_template("tests/snapshots/add/overwrite_name_noop.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["your-face"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_name_noop.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_name_noop.stderr"); + + assert().subset_matches("tests/snapshots/add/overwrite_name_noop.out", &project_root); +} + +#[cargo_test] +fn overwrite_no_default_features() { + init_registry(); + let project_root = + project_from_template("tests/snapshots/add/overwrite_no_default_features.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2@0.4.1", "--no-default-features"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_no_default_features.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_no_default_features.stderr"); + + assert().subset_matches( + "tests/snapshots/add/overwrite_no_default_features.out", + &project_root, + ); +} + +#[cargo_test] +fn overwrite_no_default_features_with_default_features() { + init_registry(); + let project_root = project_from_template( + "tests/snapshots/add/overwrite_no_default_features_with_default_features.in", + ); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2@0.4.1", "--default-features"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path( + "tests/snapshots/add/overwrite_no_default_features_with_default_features.stdout", + ) + .stderr_matches_path( + "tests/snapshots/add/overwrite_no_default_features_with_default_features.stderr", + ); + + assert().subset_matches( + "tests/snapshots/add/overwrite_no_default_features_with_default_features.out", + &project_root, + ); +} + +#[cargo_test] +fn overwrite_no_optional() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/overwrite_no_optional.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2@0.4.1", "--no-optional"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_no_optional.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_no_optional.stderr"); + + assert().subset_matches( + "tests/snapshots/add/overwrite_no_optional.out", + &project_root, + ); +} + +#[cargo_test] +fn overwrite_no_optional_with_optional() { + init_registry(); + let project_root = + project_from_template("tests/snapshots/add/overwrite_no_optional_with_optional.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2@0.4.1", "--optional"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_no_optional_with_optional.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_no_optional_with_optional.stderr"); + + assert().subset_matches( + "tests/snapshots/add/overwrite_no_optional_with_optional.out", + &project_root, + ); +} + +#[cargo_test] +fn overwrite_optional() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/overwrite_optional.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2@0.4.1", "--optional"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_optional.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_optional.stderr"); + + assert().subset_matches("tests/snapshots/add/overwrite_optional.out", &project_root); +} + +#[cargo_test] +fn overwrite_optional_with_no_optional() { + init_registry(); + let project_root = + project_from_template("tests/snapshots/add/overwrite_optional_with_no_optional.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2@0.4.1", "--no-optional"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_optional_with_no_optional.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_optional_with_no_optional.stderr"); + + assert().subset_matches( + "tests/snapshots/add/overwrite_optional_with_no_optional.out", + &project_root, + ); +} + +#[cargo_test] +fn overwrite_path_noop() { + init_alt_registry(); + let project_root = project_from_template("tests/snapshots/add/overwrite_path_noop.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["your-face", "--path", "./dependency"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_path_noop.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_path_noop.stderr"); + + assert().subset_matches("tests/snapshots/add/overwrite_path_noop.out", &project_root); +} + +#[cargo_test] +fn overwrite_path_with_version() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/overwrite_path_with_version.in"); + let cwd = project_root.join("primary"); + + cargo_command() + .arg("add") + .args(["cargo-list-test-fixture-dependency@20.0"]) + .current_dir(&cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_path_with_version.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_path_with_version.stderr"); + + assert().subset_matches( + "tests/snapshots/add/overwrite_path_with_version.out", + &project_root, + ); +} + +#[cargo_test] +fn overwrite_rename_with_no_rename() { + init_registry(); + let project_root = + project_from_template("tests/snapshots/add/overwrite_rename_with_no_rename.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["versioned-package"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_rename_with_no_rename.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_rename_with_no_rename.stderr"); + + assert().subset_matches( + "tests/snapshots/add/overwrite_rename_with_no_rename.out", + &project_root, + ); +} + +#[cargo_test] +fn overwrite_rename_with_rename() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/overwrite_rename_with_rename.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["versioned-package", "--rename", "a2"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_rename_with_rename.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_rename_with_rename.stderr"); + + assert().subset_matches( + "tests/snapshots/add/overwrite_rename_with_rename.out", + &project_root, + ); +} + +#[cargo_test] +fn change_rename_target() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/change_rename_target.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package2", "--rename", "some-package"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/change_rename_target.stdout") + .stderr_matches_path("tests/snapshots/add/change_rename_target.stderr"); + + assert().subset_matches( + "tests/snapshots/add/change_rename_target.out", + &project_root, + ); +} + +#[cargo_test] +fn overwrite_rename_with_rename_noop() { + init_registry(); + let project_root = + project_from_template("tests/snapshots/add/overwrite_rename_with_rename_noop.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["versioned-package", "--rename", "a1"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_rename_with_rename_noop.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_rename_with_rename_noop.stderr"); + + assert().subset_matches( + "tests/snapshots/add/overwrite_rename_with_rename_noop.out", + &project_root, + ); +} + +#[cargo_test] +fn overwrite_version_with_git() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/overwrite_version_with_git.in"); + let cwd = &project_root; + let git_dep = cargo_test_support::git::new("versioned-package", |project| { + project + .file( + "Cargo.toml", + &cargo_test_support::basic_manifest("versioned-package", "0.3.0+versioned-package"), + ) + .file("src/lib.rs", "") + }); + let git_url = git_dep.url().to_string(); + + cargo_command() + .arg("add") + .args(["versioned-package", "--git", &git_url]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_version_with_git.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_version_with_git.stderr"); + + assert().subset_matches( + "tests/snapshots/add/overwrite_version_with_git.out", + &project_root, + ); +} + +#[cargo_test] +fn overwrite_version_with_path() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/overwrite_version_with_path.in"); + let cwd = project_root.join("primary"); + + cargo_command() + .arg("add") + .args([ + "cargo-list-test-fixture-dependency", + "--path", + "../dependency", + ]) + .current_dir(&cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_version_with_path.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_version_with_path.stderr"); + + assert().subset_matches( + "tests/snapshots/add/overwrite_version_with_path.out", + &project_root, + ); +} + +#[cargo_test] +fn overwrite_with_rename() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/overwrite_with_rename.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["versioned-package", "--rename", "renamed"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/overwrite_with_rename.stdout") + .stderr_matches_path("tests/snapshots/add/overwrite_with_rename.stderr"); + + assert().subset_matches( + "tests/snapshots/add/overwrite_with_rename.out", + &project_root, + ); +} + +#[cargo_test] +fn preserve_sorted() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/preserve_sorted.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["toml"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/preserve_sorted.stdout") + .stderr_matches_path("tests/snapshots/add/preserve_sorted.stderr"); + + assert().subset_matches("tests/snapshots/add/preserve_sorted.out", &project_root); +} + +#[cargo_test] +fn preserve_unsorted() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/preserve_unsorted.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["toml"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/preserve_unsorted.stdout") + .stderr_matches_path("tests/snapshots/add/preserve_unsorted.stderr"); + + assert().subset_matches("tests/snapshots/add/preserve_unsorted.out", &project_root); +} + +#[cargo_test] +fn registry() { + init_alt_registry(); + let project_root = project_from_template("tests/snapshots/add/registry.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2", "--registry", "alternative"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/registry.stdout") + .stderr_matches_path("tests/snapshots/add/registry.stderr"); + + assert().subset_matches("tests/snapshots/add/registry.out", &project_root); +} + +#[cargo_test] +fn rename() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/rename.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package", "--rename", "renamed"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/rename.stdout") + .stderr_matches_path("tests/snapshots/add/rename.stderr"); + + assert().subset_matches("tests/snapshots/add/rename.out", &project_root); +} + +#[cargo_test] +fn target() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/target.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args([ + "my-package1", + "my-package2", + "--target", + "i686-unknown-linux-gnu", + ]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/target.stdout") + .stderr_matches_path("tests/snapshots/add/target.stderr"); + + assert().subset_matches("tests/snapshots/add/target.out", &project_root); +} + +#[cargo_test] +fn target_cfg() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/target_cfg.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package1", "my-package2", "--target", "cfg(unix)"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/target_cfg.stdout") + .stderr_matches_path("tests/snapshots/add/target_cfg.stderr"); + + assert().subset_matches("tests/snapshots/add/target_cfg.out", &project_root); +} + +#[cargo_test] +fn vers() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/vers.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package@>=0.1.1"]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/vers.stdout") + .stderr_matches_path("tests/snapshots/add/vers.stderr"); + + assert().subset_matches("tests/snapshots/add/vers.out", &project_root); +} + +#[cargo_test] +fn workspace_path() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/workspace_path.in"); + let cwd = project_root.join("primary"); + + cargo_command() + .arg("add") + .args([ + "cargo-list-test-fixture-dependency", + "--path", + "../dependency", + ]) + .current_dir(&cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/workspace_path.stdout") + .stderr_matches_path("tests/snapshots/add/workspace_path.stderr"); + + assert().subset_matches("tests/snapshots/add/workspace_path.out", &project_root); +} + +#[cargo_test] +fn workspace_path_dev() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/workspace_path_dev.in"); + let cwd = project_root.join("primary"); + + cargo_command() + .arg("add") + .args([ + "cargo-list-test-fixture-dependency", + "--path", + "../dependency", + "--dev", + ]) + .current_dir(&cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/workspace_path_dev.stdout") + .stderr_matches_path("tests/snapshots/add/workspace_path_dev.stderr"); + + assert().subset_matches("tests/snapshots/add/workspace_path_dev.out", &project_root); +} + +#[cargo_test] +fn workspace_name() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/workspace_name.in"); + let cwd = project_root.join("primary"); + + cargo_command() + .arg("add") + .args(["cargo-list-test-fixture-dependency"]) + .current_dir(&cwd) + .assert() + .success() + .stdout_matches_path("tests/snapshots/add/workspace_name.stdout") + .stderr_matches_path("tests/snapshots/add/workspace_name.stderr"); + + assert().subset_matches("tests/snapshots/add/workspace_name.out", &project_root); +} + +#[cargo_test] +fn deprecated_default_features() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/deprecated_default_features.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package"]) + .current_dir(&cwd) + .assert() + .failure() + .stdout_matches_path("tests/snapshots/add/deprecated_default_features.stdout") + .stderr_matches_path("tests/snapshots/add/deprecated_default_features.stderr"); + + assert().subset_matches( + "tests/snapshots/add/deprecated_default_features.out", + &project_root, + ); +} + +#[cargo_test] +fn deprecated_section() { + init_registry(); + let project_root = project_from_template("tests/snapshots/add/deprecated_section.in"); + let cwd = &project_root; + + cargo_command() + .arg("add") + .args(["my-package"]) + .current_dir(&cwd) + .assert() + .failure() + .stdout_matches_path("tests/snapshots/add/deprecated_section.stdout") + .stderr_matches_path("tests/snapshots/add/deprecated_section.stderr"); + + assert().subset_matches("tests/snapshots/add/deprecated_section.out", &project_root); +} diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index a89324f9f95..134bbf5d9fb 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -19,6 +19,7 @@ mod build_script; mod build_script_env; mod build_script_extra_link_arg; mod cache_messages; +mod cargo_add; mod cargo_alias_config; mod cargo_command; mod cargo_config;