From 72f84271f98e40a1969ec8523fe97c09b5e8b882 Mon Sep 17 00:00:00 2001 From: Robert Vally Date: Mon, 22 May 2017 21:14:03 +0800 Subject: [PATCH] 3360 - Allow for features to be either comma or space delimited. --- src/cargo/ops/resolve.rs | 9 ++- tests/features.rs | 118 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 3 deletions(-) diff --git a/src/cargo/ops/resolve.rs b/src/cargo/ops/resolve.rs index 9a13ac5c9f1..2aa60d056dc 100644 --- a/src/cargo/ops/resolve.rs +++ b/src/cargo/ops/resolve.rs @@ -28,9 +28,12 @@ pub fn resolve_ws_precisely<'a>(ws: &Workspace<'a>, no_default_features: bool, specs: &[PackageIdSpec]) -> CargoResult<(PackageSet<'a>, Resolve)> { - let features = features.iter().flat_map(|s| { - s.split_whitespace() - }).map(|s| s.to_string()).collect::>(); + let features = features.iter() + .flat_map(|s| s.split_whitespace()) + .flat_map(|s| s.split(',')) + .filter(|s| s.len() > 0) + .map(|s| s.to_string()) + .collect::>(); let mut registry = PackageRegistry::new(ws.config())?; if let Some(source) = source { diff --git a/tests/features.rs b/tests/features.rs index 0c53b921837..786db0470e4 100644 --- a/tests/features.rs +++ b/tests/features.rs @@ -1007,3 +1007,121 @@ fn all_features_flag_enables_all_features() { assert_that(p.cargo_process("build").arg("--all-features"), execs().with_status(0)); } + +#[test] +fn many_cli_features_comma_delimited() { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies.bar] + path = "bar" + optional = true + + [dependencies.baz] + path = "baz" + optional = true + "#) + .file("src/main.rs", r#" + extern crate bar; + extern crate baz; + fn main() {} + "#) + .file("bar/Cargo.toml", r#" + [package] + name = "bar" + version = "0.0.1" + authors = [] + "#) + .file("bar/src/lib.rs", "pub fn bar() {}") + .file("baz/Cargo.toml", r#" + [package] + name = "baz" + version = "0.0.1" + authors = [] + "#) + .file("baz/src/lib.rs", "pub fn baz() {}"); + + assert_that(p.cargo_process("build").arg("--features").arg("bar,baz"), + execs().with_status(0).with_stderr(format!("\ +[COMPILING] ba[..] v0.0.1 ({dir}/ba[..]) +[COMPILING] ba[..] v0.0.1 ({dir}/ba[..]) +[COMPILING] foo v0.0.1 ({dir}) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", dir = p.url()))); +} + +#[test] +fn many_cli_features_comma_and_space_delimited() { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies.bar] + path = "bar" + optional = true + + [dependencies.baz] + path = "baz" + optional = true + + [dependencies.bam] + path = "bam" + optional = true + + [dependencies.bap] + path = "bap" + optional = true + "#) + .file("src/main.rs", r#" + extern crate bar; + extern crate baz; + extern crate bam; + extern crate bap; + fn main() {} + "#) + .file("bar/Cargo.toml", r#" + [package] + name = "bar" + version = "0.0.1" + authors = [] + "#) + .file("bar/src/lib.rs", "pub fn bar() {}") + .file("baz/Cargo.toml", r#" + [package] + name = "baz" + version = "0.0.1" + authors = [] + "#) + .file("baz/src/lib.rs", "pub fn baz() {}") + .file("bam/Cargo.toml", r#" + [package] + name = "bam" + version = "0.0.1" + authors = [] + "#) + .file("bam/src/lib.rs", "pub fn bam() {}") + .file("bap/Cargo.toml", r#" + [package] + name = "bap" + version = "0.0.1" + authors = [] + "#) + .file("bap/src/lib.rs", "pub fn bap() {}"); + + assert_that(p.cargo_process("build").arg("--features").arg("bar,baz bam bap"), + execs().with_status(0).with_stderr(format!("\ +[COMPILING] ba[..] v0.0.1 ({dir}/ba[..]) +[COMPILING] ba[..] v0.0.1 ({dir}/ba[..]) +[COMPILING] ba[..] v0.0.1 ({dir}/ba[..]) +[COMPILING] ba[..] v0.0.1 ({dir}/ba[..]) +[COMPILING] foo v0.0.1 ({dir}) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", dir = p.url()))); +}