Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3360 - Allow for features to be either comma or space delimited. #4084

Merged
merged 1 commit into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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())));
}