Skip to content

Commit

Permalink
3360 - Allow for features to be either comma or space delimited.
Browse files Browse the repository at this point in the history
  • Loading branch information
shiver committed May 22, 2017
1 parent 80e653b commit 72f8427
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/cargo/ops/resolve.rs
Expand Up @@ -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::<Vec<String>>();
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::<Vec<String>>();

let mut registry = PackageRegistry::new(ws.config())?;
if let Some(source) = source {
Expand Down
118 changes: 118 additions & 0 deletions tests/features.rs
Expand Up @@ -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())));
}

0 comments on commit 72f8427

Please sign in to comment.