2018-12-06 19:17:36 +00:00
|
|
|
use crate::support::install::{cargo_home, assert_has_installed_exe, assert_has_not_installed_exe};
|
|
|
|
use crate::support::is_nightly;
|
|
|
|
use crate::support::project;
|
2017-02-08 00:20:21 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn build_bin_default_features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-08 00:20:21 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
default = ["a"]
|
|
|
|
a = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-02-13 17:59:36 +00:00
|
|
|
extern crate foo;
|
|
|
|
|
|
|
|
#[cfg(feature = "a")]
|
|
|
|
fn test() {
|
|
|
|
foo::foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("src/lib.rs", r#"#[cfg(feature = "a")] pub fn foo() {}"#)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("foo").is_file());
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --no-default-features").run();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --bin=foo").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("foo").is_file());
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --bin=foo --no-default-features")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-08-07 20:05:22 +00:00
|
|
|
error: target `foo` in package `foo` requires the features: `a`
|
2017-02-08 00:20:21 +00:00
|
|
|
Consider enabling them by passing e.g. `--features=\"a\"`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
).run();
|
2017-02-08 00:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn build_bin_arg_features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-08 00:20:21 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
a = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("src/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --features a").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("foo").is_file());
|
2017-02-08 00:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn build_bin_multiple_required_features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-08 00:20:21 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
default = ["a", "b"]
|
|
|
|
a = []
|
|
|
|
b = ["a"]
|
|
|
|
c = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo_1"
|
|
|
|
path = "src/foo_1.rs"
|
|
|
|
required-features = ["b", "c"]
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo_2"
|
|
|
|
path = "src/foo_2.rs"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("src/foo_1.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo_2.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build").run();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(!p.bin("foo_1").is_file());
|
|
|
|
assert!(p.bin("foo_2").is_file());
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --features c").run();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("foo_1").is_file());
|
|
|
|
assert!(p.bin("foo_2").is_file());
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --no-default-features").run();
|
2017-02-08 00:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn build_example_default_features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-08 00:20:21 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
default = ["a"]
|
|
|
|
a = []
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("examples/foo.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --example=foo").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("examples/foo").is_file());
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --example=foo --no-default-features")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-08-07 20:05:22 +00:00
|
|
|
error: target `foo` in package `foo` requires the features: `a`
|
2017-02-08 00:20:21 +00:00
|
|
|
Consider enabling them by passing e.g. `--features=\"a\"`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
).run();
|
2017-02-08 00:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn build_example_arg_features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-08 00:20:21 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
a = []
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("examples/foo.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --example=foo --features a").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("examples/foo").is_file());
|
2017-02-08 00:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn build_example_multiple_required_features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-08 00:20:21 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
default = ["a", "b"]
|
|
|
|
a = []
|
|
|
|
b = ["a"]
|
|
|
|
c = []
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "foo_1"
|
|
|
|
required-features = ["b", "c"]
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "foo_2"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("examples/foo_1.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("examples/foo_2.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --example=foo_1")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-08-07 20:05:22 +00:00
|
|
|
error: target `foo_1` in package `foo` requires the features: `b`, `c`
|
2017-02-08 00:20:21 +00:00
|
|
|
Consider enabling them by passing e.g. `--features=\"b c\"`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
).run();
|
|
|
|
p.cargo("build --example=foo_2").run();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(!p.bin("examples/foo_1").is_file());
|
|
|
|
assert!(p.bin("examples/foo_2").is_file());
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --example=foo_1 --features c").run();
|
|
|
|
p.cargo("build --example=foo_2 --features c").run();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("examples/foo_1").is_file());
|
|
|
|
assert!(p.bin("examples/foo_2").is_file());
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --example=foo_1 --no-default-features")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-08-07 20:05:22 +00:00
|
|
|
error: target `foo_1` in package `foo` requires the features: `b`, `c`
|
2017-02-08 00:20:21 +00:00
|
|
|
Consider enabling them by passing e.g. `--features=\"b c\"`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
).run();
|
|
|
|
p.cargo("build --example=foo_2 --no-default-features")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-08-07 20:05:22 +00:00
|
|
|
error: target `foo_2` in package `foo` requires the features: `a`
|
2017-02-08 00:20:21 +00:00
|
|
|
Consider enabling them by passing e.g. `--features=\"a\"`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
).run();
|
2017-02-08 00:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_default_features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-08 00:20:21 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
default = ["a"]
|
|
|
|
a = []
|
|
|
|
|
|
|
|
[[test]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("tests/foo.rs", "#[test]\nfn test() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-02-08 00:20:21 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] target/debug/deps/foo-[..][EXE]",
|
2018-09-03 09:38:29 +00:00
|
|
|
).with_stdout_contains("test test ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test --no-default-features")
|
|
|
|
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test --test=foo")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2017-02-08 00:20:21 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-08-28 09:20:03 +00:00
|
|
|
[RUNNING] target/debug/deps/foo-[..][EXE]",
|
|
|
|
).with_stdout_contains("test test ... ok")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test --test=foo --no-default-features")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-08-07 20:05:22 +00:00
|
|
|
error: target `foo` in package `foo` requires the features: `a`
|
2017-02-08 00:20:21 +00:00
|
|
|
Consider enabling them by passing e.g. `--features=\"a\"`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
).run();
|
2017-02-08 00:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_arg_features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-08 00:20:21 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
a = []
|
|
|
|
|
|
|
|
[[test]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("tests/foo.rs", "#[test]\nfn test() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --features a")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-02-08 00:20:21 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] target/debug/deps/foo-[..][EXE]",
|
2018-09-03 09:38:29 +00:00
|
|
|
).with_stdout_contains("test test ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-02-08 00:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_multiple_required_features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-08 00:20:21 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
default = ["a", "b"]
|
|
|
|
a = []
|
|
|
|
b = ["a"]
|
|
|
|
c = []
|
|
|
|
|
|
|
|
[[test]]
|
|
|
|
name = "foo_1"
|
|
|
|
required-features = ["b", "c"]
|
|
|
|
|
|
|
|
[[test]]
|
|
|
|
name = "foo_2"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("tests/foo_1.rs", "#[test]\nfn test() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("tests/foo_2.rs", "#[test]\nfn test() {}")
|
|
|
|
.build();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-02-08 00:20:21 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] target/debug/deps/foo_2-[..][EXE]",
|
2018-09-03 09:38:29 +00:00
|
|
|
).with_stdout_contains("test test ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --features c")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-02-08 00:20:21 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] target/debug/deps/foo_1-[..][EXE]
|
|
|
|
[RUNNING] target/debug/deps/foo_2-[..][EXE]",
|
2018-09-03 09:38:29 +00:00
|
|
|
).with_stdout_contains_n("test test ... ok", 2)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test --no-default-features")
|
|
|
|
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
2017-02-08 00:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn bench_default_features() {
|
2017-02-08 21:31:55 +00:00
|
|
|
if !is_nightly() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-08 00:20:21 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
default = ["a"]
|
|
|
|
a = []
|
|
|
|
|
|
|
|
[[bench]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"benches/foo.rs",
|
|
|
|
r#"
|
2017-02-08 00:20:21 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench(_: &mut test::Bencher) {
|
2018-03-14 15:17:44 +00:00
|
|
|
}"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-02-08 00:20:21 +00:00
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] target/release/deps/foo-[..][EXE]",
|
2018-09-03 09:38:29 +00:00
|
|
|
).with_stdout_contains("test bench ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("bench --no-default-features")
|
|
|
|
.with_stderr("[FINISHED] release [optimized] target(s) in [..]".to_string())
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("bench --bench=foo")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2017-02-08 00:20:21 +00:00
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
2018-08-28 09:20:03 +00:00
|
|
|
[RUNNING] target/release/deps/foo-[..][EXE]",
|
|
|
|
).with_stdout_contains("test bench ... bench: [..]")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("bench --bench=foo --no-default-features")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-08-07 20:05:22 +00:00
|
|
|
error: target `foo` in package `foo` requires the features: `a`
|
2017-02-08 00:20:21 +00:00
|
|
|
Consider enabling them by passing e.g. `--features=\"a\"`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
).run();
|
2017-02-08 00:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn bench_arg_features() {
|
2017-02-08 21:31:55 +00:00
|
|
|
if !is_nightly() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-08 00:20:21 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
a = []
|
|
|
|
|
|
|
|
[[bench]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"benches/foo.rs",
|
|
|
|
r#"
|
2017-02-08 00:20:21 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench(_: &mut test::Bencher) {
|
2018-03-14 15:17:44 +00:00
|
|
|
}"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench --features a")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-02-08 00:20:21 +00:00
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] target/release/deps/foo-[..][EXE]",
|
2018-09-03 09:38:29 +00:00
|
|
|
).with_stdout_contains("test bench ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-02-08 00:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn bench_multiple_required_features() {
|
2017-02-08 21:31:55 +00:00
|
|
|
if !is_nightly() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-08 00:20:21 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
default = ["a", "b"]
|
|
|
|
a = []
|
|
|
|
b = ["a"]
|
|
|
|
c = []
|
|
|
|
|
|
|
|
[[bench]]
|
|
|
|
name = "foo_1"
|
|
|
|
required-features = ["b", "c"]
|
|
|
|
|
|
|
|
[[bench]]
|
|
|
|
name = "foo_2"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"benches/foo_1.rs",
|
|
|
|
r#"
|
2017-02-08 00:20:21 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench(_: &mut test::Bencher) {
|
2018-03-14 15:17:44 +00:00
|
|
|
}"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"benches/foo_2.rs",
|
|
|
|
r#"
|
2017-02-08 00:20:21 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench(_: &mut test::Bencher) {
|
2018-03-14 15:17:44 +00:00
|
|
|
}"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2017-02-08 00:20:21 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-02-08 00:20:21 +00:00
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] target/release/deps/foo_2-[..][EXE]",
|
2018-09-03 09:38:29 +00:00
|
|
|
).with_stdout_contains("test bench ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench --features c")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-02-08 00:20:21 +00:00
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] target/release/deps/foo_1-[..][EXE]
|
|
|
|
[RUNNING] target/release/deps/foo_2-[..][EXE]",
|
2018-09-03 09:38:29 +00:00
|
|
|
).with_stdout_contains_n("test bench ... bench: [..]", 2)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench --no-default-features")
|
|
|
|
.with_stderr("[FINISHED] release [optimized] target(s) in [..]")
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
2017-02-08 00:20:21 +00:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:08:23 +00:00
|
|
|
#[test]
|
|
|
|
fn install_default_features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-10 20:08:23 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
default = ["a"]
|
|
|
|
a = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["a"]
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("src/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("examples/foo.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-02-10 20:08:23 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("install --path .").run();
|
2018-08-29 06:32:28 +00:00
|
|
|
assert_has_installed_exe(cargo_home(), "foo");
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("uninstall foo").run();
|
2017-02-10 20:08:23 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("install --path . --no-default-features")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2017-02-10 20:08:23 +00:00
|
|
|
[INSTALLING] foo v0.0.1 ([..])
|
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
|
|
|
[ERROR] no binaries are available for install using the selected features
|
2018-08-28 09:20:03 +00:00
|
|
|
",
|
|
|
|
).run();
|
2018-08-29 06:32:28 +00:00
|
|
|
assert_has_not_installed_exe(cargo_home(), "foo");
|
2017-02-10 20:08:23 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("install --path . --bin=foo").run();
|
2018-08-29 06:32:28 +00:00
|
|
|
assert_has_installed_exe(cargo_home(), "foo");
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("uninstall foo").run();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("install --path . --bin=foo --no-default-features")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2017-02-10 20:08:23 +00:00
|
|
|
[INSTALLING] foo v0.0.1 ([..])
|
|
|
|
[ERROR] failed to compile `foo v0.0.1 ([..])`, intermediate artifacts can be found at \
|
|
|
|
`[..]target`
|
|
|
|
|
|
|
|
Caused by:
|
2018-08-07 20:05:22 +00:00
|
|
|
target `foo` in package `foo` requires the features: `a`
|
2017-02-10 20:08:23 +00:00
|
|
|
Consider enabling them by passing e.g. `--features=\"a\"`
|
2018-08-28 09:20:03 +00:00
|
|
|
",
|
|
|
|
).run();
|
2018-08-29 06:32:28 +00:00
|
|
|
assert_has_not_installed_exe(cargo_home(), "foo");
|
2017-02-10 20:08:23 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("install --path . --example=foo").run();
|
2018-08-29 06:32:28 +00:00
|
|
|
assert_has_installed_exe(cargo_home(), "foo");
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("uninstall foo").run();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("install --path . --example=foo --no-default-features")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2017-02-10 20:08:23 +00:00
|
|
|
[INSTALLING] foo v0.0.1 ([..])
|
|
|
|
[ERROR] failed to compile `foo v0.0.1 ([..])`, intermediate artifacts can be found at \
|
|
|
|
`[..]target`
|
|
|
|
|
|
|
|
Caused by:
|
2018-08-07 20:05:22 +00:00
|
|
|
target `foo` in package `foo` requires the features: `a`
|
2017-02-10 20:08:23 +00:00
|
|
|
Consider enabling them by passing e.g. `--features=\"a\"`
|
2018-08-28 09:20:03 +00:00
|
|
|
",
|
|
|
|
).run();
|
2018-08-29 06:32:28 +00:00
|
|
|
assert_has_not_installed_exe(cargo_home(), "foo");
|
2017-02-10 20:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn install_arg_features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-10 20:08:23 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
a = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("src/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-02-10 20:08:23 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("install --features a").run();
|
2018-08-29 06:32:28 +00:00
|
|
|
assert_has_installed_exe(cargo_home(), "foo");
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("uninstall foo").run();
|
2017-02-10 20:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn install_multiple_required_features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-10 20:08:23 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
default = ["a", "b"]
|
|
|
|
a = []
|
|
|
|
b = ["a"]
|
|
|
|
c = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo_1"
|
|
|
|
path = "src/foo_1.rs"
|
|
|
|
required-features = ["b", "c"]
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo_2"
|
|
|
|
path = "src/foo_2.rs"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("src/foo_1.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo_2.rs", "fn main() {}")
|
|
|
|
.build();
|
2017-02-10 20:08:23 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("install --path .").run();
|
2018-08-29 06:32:28 +00:00
|
|
|
assert_has_not_installed_exe(cargo_home(), "foo_1");
|
|
|
|
assert_has_installed_exe(cargo_home(), "foo_2");
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("uninstall foo").run();
|
2017-02-10 20:08:23 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("install --path . --features c").run();
|
2018-08-29 06:32:28 +00:00
|
|
|
assert_has_installed_exe(cargo_home(), "foo_1");
|
|
|
|
assert_has_installed_exe(cargo_home(), "foo_2");
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("uninstall foo").run();
|
2017-02-10 20:08:23 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("install --path . --no-default-features")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2017-02-10 20:08:23 +00:00
|
|
|
[INSTALLING] foo v0.0.1 ([..])
|
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
|
|
|
[ERROR] no binaries are available for install using the selected features
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
).run();
|
2018-08-29 06:32:28 +00:00
|
|
|
assert_has_not_installed_exe(cargo_home(), "foo_1");
|
|
|
|
assert_has_not_installed_exe(cargo_home(), "foo_2");
|
2017-02-10 20:08:23 +00:00
|
|
|
}
|
2017-02-20 19:31:03 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn dep_feature_in_toml() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-20 19:31:03 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar", features = ["a"] }
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["bar/a"]
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["bar/a"]
|
|
|
|
|
|
|
|
[[test]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["bar/a"]
|
|
|
|
|
|
|
|
[[bench]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["bar/a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("src/main.rs", "fn main() {}")
|
2017-02-20 19:31:03 +00:00
|
|
|
.file("examples/foo.rs", "fn main() {}")
|
|
|
|
.file("tests/foo.rs", "#[test]\nfn test() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"benches/foo.rs",
|
|
|
|
r#"
|
2017-02-20 19:31:03 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench(_: &mut test::Bencher) {
|
2018-03-14 15:17:44 +00:00
|
|
|
}"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2017-02-20 19:31:03 +00:00
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
a = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("bar/src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-02-20 19:31:03 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build").run();
|
2017-02-20 19:31:03 +00:00
|
|
|
|
|
|
|
// bin
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --bin=foo").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("foo").is_file());
|
2017-02-20 19:31:03 +00:00
|
|
|
|
|
|
|
// example
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --example=foo").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("examples/foo").is_file());
|
2017-02-20 19:31:03 +00:00
|
|
|
|
|
|
|
// test
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --test=foo")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-02-20 19:31:03 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] target/debug/deps/foo-[..][EXE]",
|
2018-09-03 09:38:29 +00:00
|
|
|
).with_stdout_contains("test test ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-02-20 19:31:03 +00:00
|
|
|
|
|
|
|
// bench
|
|
|
|
if is_nightly() {
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench --bench=foo")
|
2018-08-29 17:56:48 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] bar v0.0.1 ([CWD]/bar)
|
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-02-20 19:31:03 +00:00
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] target/release/deps/foo-[..][EXE]",
|
2018-08-29 17:56:48 +00:00
|
|
|
).with_stdout_contains("test bench ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-02-20 19:31:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// install
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("install").run();
|
2018-08-29 06:32:28 +00:00
|
|
|
assert_has_installed_exe(cargo_home(), "foo");
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("uninstall foo").run();
|
2017-02-20 19:31:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn dep_feature_in_cmd_line() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-20 19:31:03 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["bar/a"]
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["bar/a"]
|
|
|
|
|
|
|
|
[[test]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["bar/a"]
|
|
|
|
|
|
|
|
[[bench]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["bar/a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("src/main.rs", "fn main() {}")
|
2017-02-20 19:31:03 +00:00
|
|
|
.file("examples/foo.rs", "fn main() {}")
|
|
|
|
.file("tests/foo.rs", "#[test]\nfn test() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"benches/foo.rs",
|
|
|
|
r#"
|
2017-02-20 19:31:03 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench(_: &mut test::Bencher) {
|
2018-03-14 15:17:44 +00:00
|
|
|
}"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2017-02-20 19:31:03 +00:00
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
a = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("bar/src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-02-20 19:31:03 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build").run();
|
2017-02-20 19:31:03 +00:00
|
|
|
|
|
|
|
// bin
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --bin=foo")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-08-07 20:05:22 +00:00
|
|
|
error: target `foo` in package `foo` requires the features: `bar/a`
|
2017-02-20 19:31:03 +00:00
|
|
|
Consider enabling them by passing e.g. `--features=\"bar/a\"`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
).run();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --bin=foo --features bar/a").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("foo").is_file());
|
2017-02-20 19:31:03 +00:00
|
|
|
|
|
|
|
// example
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --example=foo")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-08-07 20:05:22 +00:00
|
|
|
error: target `foo` in package `foo` requires the features: `bar/a`
|
2017-02-20 19:31:03 +00:00
|
|
|
Consider enabling them by passing e.g. `--features=\"bar/a\"`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
).run();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --example=foo --features bar/a").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("examples/foo").is_file());
|
2017-02-20 19:31:03 +00:00
|
|
|
|
|
|
|
// test
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
|
|
|
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test --test=foo --features bar/a")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-02-20 19:31:03 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] target/debug/deps/foo-[..][EXE]",
|
2018-09-03 09:38:29 +00:00
|
|
|
).with_stdout_contains("test test ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-02-20 19:31:03 +00:00
|
|
|
|
|
|
|
// bench
|
|
|
|
if is_nightly() {
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench")
|
|
|
|
.with_stderr("[FINISHED] release [optimized] target(s) in [..]")
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("bench --bench=foo --features bar/a")
|
2018-08-29 17:56:48 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] bar v0.0.1 ([CWD]/bar)
|
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-02-20 19:31:03 +00:00
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] target/release/deps/foo-[..][EXE]",
|
2018-08-29 17:56:48 +00:00
|
|
|
).with_stdout_contains("test bench ... bench: [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-02-20 19:31:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// install
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("install --path .")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2017-02-20 19:31:03 +00:00
|
|
|
[INSTALLING] foo v0.0.1 ([..])
|
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
|
|
|
[ERROR] no binaries are available for install using the selected features
|
2018-08-28 09:20:03 +00:00
|
|
|
",
|
|
|
|
).run();
|
2018-08-29 06:32:28 +00:00
|
|
|
assert_has_not_installed_exe(cargo_home(), "foo");
|
2017-02-20 19:31:03 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("install --features bar/a").run();
|
2018-08-29 06:32:28 +00:00
|
|
|
assert_has_installed_exe(cargo_home(), "foo");
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("uninstall foo").run();
|
2017-02-20 19:31:03 +00:00
|
|
|
}
|
2017-02-27 21:19:34 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_skips_compiling_bin_with_missing_required_features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-27 21:19:34 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
a = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "bin_foo"
|
|
|
|
path = "src/bin/foo.rs"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("src/bin/foo.rs", "extern crate bar; fn main() {}")
|
2017-02-27 21:19:34 +00:00
|
|
|
.file("tests/foo.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("benches/foo.rs", "")
|
|
|
|
.build();
|
2017-02-27 21:19:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-02-27 21:19:34 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] target/debug/deps/foo-[..][EXE]",
|
2018-09-03 09:38:29 +00:00
|
|
|
).with_stdout_contains("running 0 tests")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --features a -j 1")
|
|
|
|
.with_status(101)
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr_contains(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2018-03-14 15:17:44 +00:00
|
|
|
error[E0463]: can't find crate for `bar`",
|
2018-09-03 09:38:29 +00:00
|
|
|
).run();
|
2017-02-27 21:19:34 +00:00
|
|
|
|
|
|
|
if is_nightly() {
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench")
|
2018-08-29 17:56:48 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-02-27 21:19:34 +00:00
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] target/release/deps/foo-[..][EXE]",
|
2018-08-29 17:56:48 +00:00
|
|
|
).with_stdout_contains("running 0 tests")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("bench --features a -j 1")
|
|
|
|
.with_status(101)
|
2018-08-29 17:56:48 +00:00
|
|
|
.with_stderr_contains(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2018-03-14 15:17:44 +00:00
|
|
|
error[E0463]: can't find crate for `bar`",
|
2018-08-29 17:56:48 +00:00
|
|
|
).run();
|
2017-02-27 21:19:34 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-29 20:48:43 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_default() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-03-29 20:48:43 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
default = []
|
|
|
|
a = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
required-features = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "extern crate foo; fn main() {}")
|
|
|
|
.build();
|
2017-03-29 20:48:43 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("run")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-08-07 20:05:22 +00:00
|
|
|
error: target `foo` in package `foo` requires the features: `a`
|
2017-03-29 20:48:43 +00:00
|
|
|
Consider enabling them by passing e.g. `--features=\"a\"`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
).run();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("run --features a").run();
|
2017-03-29 20:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_default_multiple_required_features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-03-29 20:48:43 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
default = ["a"]
|
|
|
|
a = []
|
|
|
|
b = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo1"
|
|
|
|
path = "src/foo1.rs"
|
|
|
|
required-features = ["a"]
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo2"
|
|
|
|
path = "src/foo2.rs"
|
|
|
|
required-features = ["b"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("src/lib.rs", "")
|
2017-03-29 20:48:43 +00:00
|
|
|
.file("src/foo1.rs", "extern crate foo; fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo2.rs", "extern crate foo; fn main() {}")
|
|
|
|
.build();
|
2017-03-29 20:48:43 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("run")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-21 06:47:09 +00:00
|
|
|
error: `cargo run` requires that a package only have one executable; \
|
2018-03-14 15:17:44 +00:00
|
|
|
use the `--bin` option to specify which one to run\navailable binaries: foo1, foo2",
|
2018-08-28 09:20:03 +00:00
|
|
|
).run();
|
2017-07-22 03:12:21 +00:00
|
|
|
}
|