2020-10-19 23:51:02 +00:00
|
|
|
//! Tests for namespaced features.
|
|
|
|
|
2021-03-19 21:36:26 +00:00
|
|
|
use super::features2::switch_to_resolver_2;
|
2023-02-19 05:26:59 +00:00
|
|
|
use cargo_test_support::registry::{Dependency, Package, RegistryBuilder};
|
2020-11-12 18:44:10 +00:00
|
|
|
use cargo_test_support::{project, publish};
|
2020-10-19 23:51:02 +00:00
|
|
|
|
2020-10-20 18:15:48 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn dependency_with_crate_syntax() {
|
2020-10-25 19:51:27 +00:00
|
|
|
// Registry dependency uses dep: syntax.
|
2020-10-20 18:15:48 +00:00
|
|
|
Package::new("baz", "1.0.0").publish();
|
|
|
|
Package::new("bar", "1.0.0")
|
|
|
|
.add_dep(Dependency::new("baz", "1.0").optional(true))
|
2020-10-25 19:51:27 +00:00
|
|
|
.feature("feat", &["dep:baz"])
|
2020-10-20 18:15:48 +00:00
|
|
|
.publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = {version="1.0", features=["feat"]}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("check")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[UPDATING] [..]
|
|
|
|
[DOWNLOADING] crates ...
|
|
|
|
[DOWNLOADED] [..]
|
|
|
|
[DOWNLOADED] [..]
|
|
|
|
[CHECKING] baz v1.0.0
|
|
|
|
[CHECKING] bar v1.0.0
|
|
|
|
[CHECKING] foo v0.1.0 [..]
|
|
|
|
[FINISHED] [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn namespaced_invalid_feature() {
|
|
|
|
// Specifies a feature that doesn't exist.
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
2020-10-19 23:51:02 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
bar = ["baz"]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2023-02-15 23:15:38 +00:00
|
|
|
p.cargo("check")
|
2020-10-19 23:51:02 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
|
|
|
|
|
|
|
Caused by:
|
2020-10-20 18:15:48 +00:00
|
|
|
feature `bar` includes `baz` which is neither a dependency nor another feature
|
2020-10-19 23:51:02 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn namespaced_invalid_dependency() {
|
2020-10-25 19:51:27 +00:00
|
|
|
// Specifies a dep:name that doesn't exist.
|
2020-10-19 23:51:02 +00:00
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-10-20 18:15:48 +00:00
|
|
|
[package]
|
2020-10-19 23:51:02 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[features]
|
2020-10-25 19:51:27 +00:00
|
|
|
bar = ["dep:baz"]
|
2020-10-19 23:51:02 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2023-02-15 23:15:38 +00:00
|
|
|
p.cargo("check")
|
2020-10-19 23:51:02 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
|
|
|
|
|
|
|
Caused by:
|
2020-10-25 19:51:27 +00:00
|
|
|
feature `bar` includes `dep:baz`, but `baz` is not listed as a dependency
|
2020-10-19 23:51:02 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn namespaced_non_optional_dependency() {
|
2020-10-25 19:51:27 +00:00
|
|
|
// Specifies a dep:name for a dependency that is not optional.
|
2020-10-19 23:51:02 +00:00
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-10-20 18:15:48 +00:00
|
|
|
[package]
|
2020-10-19 23:51:02 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[features]
|
2020-10-25 19:51:27 +00:00
|
|
|
bar = ["dep:baz"]
|
2020-10-19 23:51:02 +00:00
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
baz = "0.1"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2023-02-15 23:15:38 +00:00
|
|
|
p.cargo("check")
|
2022-01-06 23:46:15 +00:00
|
|
|
|
2020-10-19 23:51:02 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
|
|
|
|
|
|
|
Caused by:
|
2020-10-25 19:51:27 +00:00
|
|
|
feature `bar` includes `dep:baz`, but `baz` is not an optional dependency
|
2020-10-20 18:15:48 +00:00
|
|
|
A non-optional dependency of the same name is defined; consider adding `optional = true` to its definition.
|
2020-10-19 23:51:02 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn namespaced_implicit_feature() {
|
2020-10-20 18:15:48 +00:00
|
|
|
// Backwards-compatible with old syntax.
|
|
|
|
Package::new("baz", "0.1.0").publish();
|
|
|
|
|
2020-10-19 23:51:02 +00:00
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-10-20 18:15:48 +00:00
|
|
|
[package]
|
2020-10-19 23:51:02 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[features]
|
|
|
|
bar = ["baz"]
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
baz = { version = "0.1", optional = true }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("check")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[UPDATING] [..]
|
|
|
|
[CHECKING] foo v0.0.1 [..]
|
|
|
|
[FINISHED] [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("check --features baz")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[DOWNLOADING] crates ...
|
|
|
|
[DOWNLOADED] baz v0.1.0 [..]
|
|
|
|
[CHECKING] baz v0.1.0
|
|
|
|
[CHECKING] foo v0.0.1 [..]
|
|
|
|
[FINISHED] [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
2020-10-19 23:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn namespaced_shadowed_dep() {
|
2020-10-20 18:15:48 +00:00
|
|
|
// An optional dependency is not listed in the features table, and its
|
|
|
|
// implicit feature is overridden.
|
2020-10-19 23:51:02 +00:00
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-10-20 18:15:48 +00:00
|
|
|
[package]
|
2020-10-19 23:51:02 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[features]
|
|
|
|
baz = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
baz = { version = "0.1", optional = true }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2023-02-15 23:15:38 +00:00
|
|
|
p.cargo("check")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2020-10-19 23:51:02 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
|
|
|
|
|
|
|
Caused by:
|
2020-10-20 18:15:48 +00:00
|
|
|
optional dependency `baz` is not included in any feature
|
2020-10-25 19:51:27 +00:00
|
|
|
Make sure that `dep:baz` is included in one of features in the [features] table.
|
2020-10-19 23:51:02 +00:00
|
|
|
",
|
2020-10-20 18:15:48 +00:00
|
|
|
)
|
2020-10-19 23:51:02 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn namespaced_shadowed_non_optional() {
|
2020-10-20 18:15:48 +00:00
|
|
|
// Able to specify a feature with the same name as a required dependency.
|
|
|
|
Package::new("baz", "0.1.0").publish();
|
2020-10-19 23:51:02 +00:00
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-10-20 18:15:48 +00:00
|
|
|
[package]
|
2020-10-19 23:51:02 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[features]
|
|
|
|
baz = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
baz = "0.1"
|
|
|
|
"#,
|
|
|
|
)
|
2020-10-20 18:15:48 +00:00
|
|
|
.file("src/lib.rs", "")
|
2020-10-19 23:51:02 +00:00
|
|
|
.build();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("check").run();
|
2020-10-19 23:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn namespaced_implicit_non_optional() {
|
2020-10-20 18:15:48 +00:00
|
|
|
// Includes a non-optional dependency in [features] table.
|
2020-10-19 23:51:02 +00:00
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-10-20 18:15:48 +00:00
|
|
|
[package]
|
2020-10-19 23:51:02 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[features]
|
|
|
|
bar = ["baz"]
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
baz = "0.1"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2023-02-15 23:15:38 +00:00
|
|
|
p.cargo("check").with_status(101).with_stderr(
|
2020-10-19 23:51:02 +00:00
|
|
|
"\
|
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
|
|
|
|
|
|
|
Caused by:
|
2020-10-20 18:15:48 +00:00
|
|
|
feature `bar` includes `baz`, but `baz` is not an optional dependency
|
|
|
|
A non-optional dependency of the same name is defined; consider adding `optional = true` to its definition.
|
2020-10-19 23:51:02 +00:00
|
|
|
",
|
|
|
|
).run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn namespaced_same_name() {
|
2020-10-20 18:15:48 +00:00
|
|
|
// Explicitly listing an optional dependency in the [features] table.
|
|
|
|
Package::new("baz", "0.1.0").publish();
|
|
|
|
|
2020-10-19 23:51:02 +00:00
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-10-20 18:15:48 +00:00
|
|
|
[package]
|
2020-10-19 23:51:02 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[features]
|
2020-10-25 19:51:27 +00:00
|
|
|
baz = ["dep:baz"]
|
2020-10-19 23:51:02 +00:00
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
baz = { version = "0.1", optional = true }
|
|
|
|
"#,
|
|
|
|
)
|
2020-10-20 18:15:48 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
|
|
|
fn main() {
|
|
|
|
if cfg!(feature="baz") { println!("baz"); }
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("run")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[UPDATING] [..]
|
|
|
|
[COMPILING] foo v0.0.1 [..]
|
|
|
|
[FINISHED] [..]
|
|
|
|
[RUNNING] [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("run --features baz")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[DOWNLOADING] crates ...
|
|
|
|
[DOWNLOADED] baz v0.1.0 [..]
|
|
|
|
[COMPILING] baz v0.1.0
|
|
|
|
[COMPILING] foo v0.0.1 [..]
|
|
|
|
[FINISHED] [..]
|
|
|
|
[RUNNING] [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stdout("baz")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn no_implicit_feature() {
|
2020-10-25 19:51:27 +00:00
|
|
|
// Using `dep:` will not create an implicit feature.
|
2020-10-20 18:15:48 +00:00
|
|
|
Package::new("regex", "1.0.0").publish();
|
|
|
|
Package::new("lazy_static", "1.0.0").publish();
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
regex = { version = "1.0", optional = true }
|
|
|
|
lazy_static = { version = "1.0", optional = true }
|
|
|
|
|
|
|
|
[features]
|
2020-10-25 19:51:27 +00:00
|
|
|
regex = ["dep:regex", "dep:lazy_static"]
|
2020-10-20 18:15:48 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
|
|
|
fn main() {
|
|
|
|
if cfg!(feature = "regex") { println!("regex"); }
|
|
|
|
if cfg!(feature = "lazy_static") { println!("lazy_static"); }
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("run")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[UPDATING] [..]
|
|
|
|
[COMPILING] foo v0.1.0 [..]
|
|
|
|
[FINISHED] [..]
|
|
|
|
[RUNNING] `target/debug/foo[EXE]`
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("run --features regex")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_stderr_unordered(
|
|
|
|
"\
|
|
|
|
[DOWNLOADING] crates ...
|
|
|
|
[DOWNLOADED] regex v1.0.0 [..]
|
|
|
|
[DOWNLOADED] lazy_static v1.0.0 [..]
|
|
|
|
[COMPILING] regex v1.0.0
|
|
|
|
[COMPILING] lazy_static v1.0.0
|
|
|
|
[COMPILING] foo v0.1.0 [..]
|
|
|
|
[FINISHED] [..]
|
|
|
|
[RUNNING] `target/debug/foo[EXE]`
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stdout("regex")
|
|
|
|
.run();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("run --features lazy_static")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] Package `foo v0.1.0 [..]` does not have feature `lazy_static`. \
|
2020-10-25 19:51:27 +00:00
|
|
|
It has an optional dependency with that name, but that dependency uses the \"dep:\" \
|
2020-10-20 18:15:48 +00:00
|
|
|
syntax in the features table, so it does not have an implicit feature with that name.
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn crate_syntax_bad_name() {
|
2020-10-25 19:51:27 +00:00
|
|
|
// "dep:bar" = []
|
2020-10-20 18:15:48 +00:00
|
|
|
Package::new("bar", "1.0.0").publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { version="1.0", optional=true }
|
|
|
|
|
|
|
|
[features]
|
2020-10-25 19:51:27 +00:00
|
|
|
"dep:bar" = []
|
2020-10-20 18:15:48 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("check --features dep:bar")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2023-12-14 22:28:05 +00:00
|
|
|
[ERROR] feature named `dep:bar` is not allowed to start with `dep:`
|
|
|
|
--> Cargo.toml:10:17
|
|
|
|
|
|
|
|
|
10 | \"dep:bar\" = []
|
|
|
|
| ^^^^^^^^^
|
|
|
|
|
|
2020-10-20 18:15:48 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn crate_syntax_in_dep() {
|
2020-10-25 19:51:27 +00:00
|
|
|
// features = ["dep:baz"]
|
2020-10-20 18:15:48 +00:00
|
|
|
Package::new("baz", "1.0.0").publish();
|
|
|
|
Package::new("bar", "1.0.0")
|
|
|
|
.add_dep(Dependency::new("baz", "1.0").optional(true))
|
|
|
|
.publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
2020-10-25 19:51:27 +00:00
|
|
|
bar = { version = "1.0", features = ["dep:baz"] }
|
2020-10-20 18:15:48 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("check")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2021-03-19 21:36:26 +00:00
|
|
|
error: failed to parse manifest at `[CWD]/Cargo.toml`
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
feature `dep:baz` in dependency `bar` is not allowed to use explicit `dep:` syntax
|
|
|
|
If you want to enable [..]
|
2020-10-20 18:15:48 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn crate_syntax_cli() {
|
2020-10-25 19:51:27 +00:00
|
|
|
// --features dep:bar
|
2020-10-20 18:15:48 +00:00
|
|
|
Package::new("bar", "1.0.0").publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { version = "1.0", optional=true }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("check --features dep:bar")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2021-03-19 21:36:26 +00:00
|
|
|
[ERROR] feature `dep:bar` is not allowed to use explicit `dep:` syntax
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
switch_to_resolver_2(&p);
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("check --features dep:bar")
|
2021-03-19 21:36:26 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] feature `dep:bar` is not allowed to use explicit `dep:` syntax
|
2020-10-20 18:15:48 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn crate_required_features() {
|
2020-10-25 19:51:27 +00:00
|
|
|
// required-features = ["dep:bar"]
|
2020-10-20 18:15:48 +00:00
|
|
|
Package::new("bar", "1.0.0").publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { version = "1.0", optional=true }
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
2020-10-25 19:51:27 +00:00
|
|
|
required-features = ["dep:bar"]
|
2020-10-20 18:15:48 +00:00
|
|
|
"#,
|
|
|
|
)
|
2020-10-19 23:51:02 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("check")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[UPDATING] [..]
|
2020-10-25 19:51:27 +00:00
|
|
|
[ERROR] invalid feature `dep:bar` in required-features of target `foo`: \
|
|
|
|
`dep:` prefixed feature values are not allowed in required-features
|
2020-10-20 18:15:48 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
2020-10-22 16:48:45 +00:00
|
|
|
fn json_exposed() {
|
2020-10-25 19:51:27 +00:00
|
|
|
// Checks that the implicit dep: values are exposed in JSON.
|
2020-10-20 18:15:48 +00:00
|
|
|
Package::new("bar", "1.0.0").publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { version = "1.0", optional=true }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("metadata --no-deps")
|
2020-10-22 16:48:45 +00:00
|
|
|
.with_json(
|
|
|
|
r#"
|
|
|
|
{
|
|
|
|
"packages": [
|
|
|
|
{
|
|
|
|
"name": "foo",
|
|
|
|
"version": "0.1.0",
|
2023-11-02 16:37:14 +00:00
|
|
|
"id": "[..]foo#0.1.0",
|
2020-10-22 16:48:45 +00:00
|
|
|
"license": null,
|
|
|
|
"license_file": null,
|
|
|
|
"description": null,
|
|
|
|
"homepage": null,
|
|
|
|
"documentation": null,
|
|
|
|
"source": null,
|
|
|
|
"dependencies": "{...}",
|
|
|
|
"targets": "{...}",
|
|
|
|
"features": {
|
2020-10-25 19:51:27 +00:00
|
|
|
"bar": ["dep:bar"]
|
2020-10-22 16:48:45 +00:00
|
|
|
},
|
|
|
|
"manifest_path": "[..]foo/Cargo.toml",
|
|
|
|
"metadata": null,
|
|
|
|
"publish": null,
|
|
|
|
"authors": [],
|
|
|
|
"categories": [],
|
2021-06-07 06:17:34 +00:00
|
|
|
"default_run": null,
|
2020-10-22 16:48:45 +00:00
|
|
|
"keywords": [],
|
|
|
|
"readme": null,
|
|
|
|
"repository": null,
|
2021-10-08 17:00:39 +00:00
|
|
|
"rust_version": null,
|
2020-10-22 16:48:45 +00:00
|
|
|
"edition": "2015",
|
|
|
|
"links": null
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"workspace_members": "{...}",
|
2023-05-03 08:37:37 +00:00
|
|
|
"workspace_default_members": "{...}",
|
2020-10-22 16:48:45 +00:00
|
|
|
"resolve": null,
|
|
|
|
"target_directory": "[..]foo/target",
|
|
|
|
"version": 1,
|
|
|
|
"workspace_root": "[..]foo",
|
|
|
|
"metadata": null
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
2020-10-20 18:15:48 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn crate_feature_with_explicit() {
|
|
|
|
// crate_name/feat_name syntax where crate_name already has a feature defined.
|
|
|
|
// NOTE: I don't know if this is actually ideal behavior.
|
|
|
|
Package::new("bar", "1.0.0")
|
|
|
|
.feature("bar_feat", &[])
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#[cfg(not(feature="bar_feat"))]
|
|
|
|
compile_error!("bar_feat is not enabled");
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { version="1.0", optional = true }
|
|
|
|
|
|
|
|
[features]
|
|
|
|
f1 = ["bar/bar_feat"]
|
2020-10-25 19:51:27 +00:00
|
|
|
bar = ["dep:bar", "f2"]
|
2020-10-20 18:15:48 +00:00
|
|
|
f2 = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#[cfg(not(feature="bar"))]
|
|
|
|
compile_error!("bar should be enabled");
|
|
|
|
|
|
|
|
#[cfg(not(feature="f2"))]
|
|
|
|
compile_error!("f2 should be enabled");
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("check --features f1")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[UPDATING] [..]
|
|
|
|
[DOWNLOADING] crates ...
|
|
|
|
[DOWNLOADED] bar v1.0.0 [..]
|
|
|
|
[CHECKING] bar v1.0.0
|
|
|
|
[CHECKING] foo v0.1.0 [..]
|
|
|
|
[FINISHED] [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn optional_explicit_without_crate() {
|
|
|
|
// "feat" syntax when there is no implicit "feat" feature because it is
|
|
|
|
// explicitly listed elsewhere.
|
|
|
|
Package::new("bar", "1.0.0").publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { version = "1.0", optional = true }
|
|
|
|
|
|
|
|
[features]
|
2020-10-25 19:51:27 +00:00
|
|
|
feat1 = ["dep:bar"]
|
2020-10-20 18:15:48 +00:00
|
|
|
feat2 = ["bar"]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2023-02-15 23:15:38 +00:00
|
|
|
p.cargo("check")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] failed to parse manifest at [..]
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
feature `feat2` includes `bar`, but `bar` is an optional dependency without an implicit feature
|
2020-10-25 19:51:27 +00:00
|
|
|
Use `dep:bar` to enable the dependency.
|
2020-10-20 18:15:48 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn tree() {
|
|
|
|
Package::new("baz", "1.0.0").publish();
|
|
|
|
Package::new("bar", "1.0.0")
|
|
|
|
.add_dep(Dependency::new("baz", "1.0").optional(true))
|
2020-10-25 19:51:27 +00:00
|
|
|
.feature("feat1", &["dep:baz"])
|
2020-10-20 18:15:48 +00:00
|
|
|
.feature("feat2", &[])
|
|
|
|
.publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { version = "1.0", features = ["feat1"], optional=true }
|
|
|
|
|
|
|
|
[features]
|
|
|
|
a = ["bar/feat2"]
|
2020-10-25 19:51:27 +00:00
|
|
|
bar = ["dep:bar"]
|
2020-10-20 18:15:48 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("tree -e features")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_stdout("foo v0.1.0 ([ROOT]/foo)")
|
|
|
|
.run();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("tree -e features --features a")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_stdout(
|
|
|
|
"\
|
|
|
|
foo v0.1.0 ([ROOT]/foo)
|
|
|
|
├── bar feature \"default\"
|
|
|
|
│ └── bar v1.0.0
|
|
|
|
│ └── baz feature \"default\"
|
|
|
|
│ └── baz v1.0.0
|
|
|
|
└── bar feature \"feat1\"
|
|
|
|
└── bar v1.0.0 (*)
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("tree -e features --features a -i bar")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_stdout(
|
|
|
|
"\
|
|
|
|
bar v1.0.0
|
|
|
|
├── bar feature \"default\"
|
|
|
|
│ └── foo v0.1.0 ([ROOT]/foo)
|
|
|
|
│ ├── foo feature \"a\" (command-line)
|
|
|
|
│ ├── foo feature \"bar\"
|
|
|
|
│ │ └── foo feature \"a\" (command-line)
|
|
|
|
│ └── foo feature \"default\" (command-line)
|
|
|
|
├── bar feature \"feat1\"
|
|
|
|
│ └── foo v0.1.0 ([ROOT]/foo) (*)
|
|
|
|
└── bar feature \"feat2\"
|
|
|
|
└── foo feature \"a\" (command-line)
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("tree -e features --features bar")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_stdout(
|
|
|
|
"\
|
|
|
|
foo v0.1.0 ([ROOT]/foo)
|
|
|
|
├── bar feature \"default\"
|
|
|
|
│ └── bar v1.0.0
|
|
|
|
│ └── baz feature \"default\"
|
|
|
|
│ └── baz v1.0.0
|
|
|
|
└── bar feature \"feat1\"
|
|
|
|
└── bar v1.0.0 (*)
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("tree -e features --features bar -i bar")
|
2020-10-20 18:15:48 +00:00
|
|
|
.with_stdout(
|
|
|
|
"\
|
|
|
|
bar v1.0.0
|
|
|
|
├── bar feature \"default\"
|
|
|
|
│ └── foo v0.1.0 ([ROOT]/foo)
|
|
|
|
│ ├── foo feature \"bar\" (command-line)
|
|
|
|
│ └── foo feature \"default\" (command-line)
|
|
|
|
└── bar feature \"feat1\"
|
|
|
|
└── foo v0.1.0 ([ROOT]/foo) (*)
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
2020-10-19 23:51:02 +00:00
|
|
|
}
|
2020-11-12 18:44:10 +00:00
|
|
|
|
2021-03-19 21:36:26 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn tree_no_implicit() {
|
|
|
|
// tree without an implicit feature
|
|
|
|
Package::new("bar", "1.0.0").publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { version = "1.0", optional=true }
|
|
|
|
|
|
|
|
[features]
|
|
|
|
a = ["dep:bar"]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("tree -e features")
|
2021-03-19 21:36:26 +00:00
|
|
|
.with_stdout("foo v0.1.0 ([ROOT]/foo)")
|
|
|
|
.run();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("tree -e features --all-features")
|
2021-03-19 21:36:26 +00:00
|
|
|
.with_stdout(
|
|
|
|
"\
|
|
|
|
foo v0.1.0 ([ROOT]/foo)
|
|
|
|
└── bar feature \"default\"
|
|
|
|
└── bar v1.0.0
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
2022-01-06 23:46:15 +00:00
|
|
|
p.cargo("tree -e features -i bar --all-features")
|
2021-03-19 21:36:26 +00:00
|
|
|
.with_stdout(
|
|
|
|
"\
|
|
|
|
bar v1.0.0
|
|
|
|
└── bar feature \"default\"
|
|
|
|
└── foo v0.1.0 ([ROOT]/foo)
|
2022-01-27 15:36:16 +00:00
|
|
|
├── foo feature \"a\" (command-line)
|
|
|
|
└── foo feature \"default\" (command-line)
|
2021-03-19 21:36:26 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-11-12 18:44:10 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn publish_no_implicit() {
|
2023-02-19 05:26:59 +00:00
|
|
|
let registry = RegistryBuilder::new().http_api().http_index().build();
|
2022-10-07 20:19:16 +00:00
|
|
|
|
2020-11-12 18:44:10 +00:00
|
|
|
// Does not include implicit features or dep: syntax on publish.
|
|
|
|
Package::new("opt-dep1", "1.0.0").publish();
|
|
|
|
Package::new("opt-dep2", "1.0.0").publish();
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
description = "foo"
|
|
|
|
license = "MIT"
|
|
|
|
homepage = "https://example.com/"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
opt-dep1 = { version = "1.0", optional = true }
|
|
|
|
opt-dep2 = { version = "1.0", optional = true }
|
|
|
|
|
|
|
|
[features]
|
|
|
|
feat = ["opt-dep1"]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2022-08-31 05:53:47 +00:00
|
|
|
p.cargo("publish --no-verify")
|
|
|
|
.replace_crates_io(registry.index_url())
|
2020-11-12 18:44:10 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[UPDATING] [..]
|
|
|
|
[PACKAGING] foo v0.1.0 [..]
|
2022-10-19 18:33:17 +00:00
|
|
|
[PACKAGED] [..]
|
2020-11-12 18:44:10 +00:00
|
|
|
[UPLOADING] foo v0.1.0 [..]
|
2023-02-17 17:44:53 +00:00
|
|
|
[UPLOADED] foo v0.1.0 [..]
|
2023-02-14 20:57:25 +00:00
|
|
|
note: Waiting [..]
|
|
|
|
You may press ctrl-c [..]
|
2023-02-17 17:44:53 +00:00
|
|
|
[PUBLISHED] foo v0.1.0 [..]
|
2020-11-12 18:44:10 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
publish::validate_upload_with_contents(
|
|
|
|
r#"
|
|
|
|
{
|
|
|
|
"authors": [],
|
|
|
|
"badges": {},
|
|
|
|
"categories": [],
|
|
|
|
"deps": [
|
|
|
|
{
|
|
|
|
"default_features": true,
|
|
|
|
"features": [],
|
|
|
|
"kind": "normal",
|
|
|
|
"name": "opt-dep1",
|
|
|
|
"optional": true,
|
|
|
|
"target": null,
|
|
|
|
"version_req": "^1.0"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"default_features": true,
|
|
|
|
"features": [],
|
|
|
|
"kind": "normal",
|
|
|
|
"name": "opt-dep2",
|
|
|
|
"optional": true,
|
|
|
|
"target": null,
|
|
|
|
"version_req": "^1.0"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"description": "foo",
|
|
|
|
"documentation": null,
|
|
|
|
"features": {
|
|
|
|
"feat": ["opt-dep1"]
|
|
|
|
},
|
|
|
|
"homepage": "https://example.com/",
|
|
|
|
"keywords": [],
|
|
|
|
"license": "MIT",
|
|
|
|
"license_file": null,
|
|
|
|
"links": null,
|
|
|
|
"name": "foo",
|
|
|
|
"readme": null,
|
|
|
|
"readme_file": null,
|
|
|
|
"repository": null,
|
2023-03-24 20:46:59 +00:00
|
|
|
"rust_version": null,
|
2020-11-12 18:44:10 +00:00
|
|
|
"vers": "0.1.0"
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
"foo-0.1.0.crate",
|
|
|
|
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
|
|
|
|
&[(
|
|
|
|
"Cargo.toml",
|
2021-06-16 02:23:17 +00:00
|
|
|
&format!(
|
|
|
|
r#"{}
|
2020-11-12 18:44:10 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
description = "foo"
|
|
|
|
homepage = "https://example.com/"
|
|
|
|
license = "MIT"
|
2021-11-02 00:18:32 +00:00
|
|
|
|
2020-11-12 18:44:10 +00:00
|
|
|
[dependencies.opt-dep1]
|
|
|
|
version = "1.0"
|
|
|
|
optional = true
|
|
|
|
|
|
|
|
[dependencies.opt-dep2]
|
|
|
|
version = "1.0"
|
|
|
|
optional = true
|
|
|
|
|
|
|
|
[features]
|
|
|
|
feat = ["opt-dep1"]
|
|
|
|
"#,
|
2021-06-16 02:23:17 +00:00
|
|
|
cargo::core::package::MANIFEST_PREAMBLE
|
|
|
|
),
|
2020-11-12 18:44:10 +00:00
|
|
|
)],
|
|
|
|
);
|
|
|
|
}
|
2021-02-10 19:15:19 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn publish() {
|
2023-02-19 05:26:59 +00:00
|
|
|
let registry = RegistryBuilder::new().http_api().http_index().build();
|
2022-10-07 20:19:16 +00:00
|
|
|
|
2021-02-10 19:15:19 +00:00
|
|
|
// Publish behavior with explicit dep: syntax.
|
|
|
|
Package::new("bar", "1.0.0").publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
description = "foo"
|
|
|
|
license = "MIT"
|
|
|
|
homepage = "https://example.com/"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { version = "1.0", optional = true }
|
|
|
|
|
|
|
|
[features]
|
|
|
|
feat1 = []
|
|
|
|
feat2 = ["dep:bar"]
|
|
|
|
feat3 = ["feat2"]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2022-08-31 05:53:47 +00:00
|
|
|
p.cargo("publish")
|
|
|
|
.replace_crates_io(registry.index_url())
|
2021-02-10 19:15:19 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[UPDATING] [..]
|
|
|
|
[PACKAGING] foo v0.1.0 [..]
|
|
|
|
[VERIFYING] foo v0.1.0 [..]
|
2023-02-19 05:26:59 +00:00
|
|
|
[UPDATING] [..]
|
2021-02-10 19:15:19 +00:00
|
|
|
[COMPILING] foo v0.1.0 [..]
|
|
|
|
[FINISHED] [..]
|
2022-10-19 18:33:17 +00:00
|
|
|
[PACKAGED] [..]
|
2021-02-10 19:15:19 +00:00
|
|
|
[UPLOADING] foo v0.1.0 [..]
|
2023-02-17 17:44:53 +00:00
|
|
|
[UPLOADED] foo v0.1.0 [..]
|
2023-02-14 20:57:25 +00:00
|
|
|
note: Waiting [..]
|
|
|
|
You may press ctrl-c [..]
|
2023-02-17 17:44:53 +00:00
|
|
|
[PUBLISHED] foo v0.1.0 [..]
|
2021-02-10 19:15:19 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
publish::validate_upload_with_contents(
|
|
|
|
r#"
|
|
|
|
{
|
|
|
|
"authors": [],
|
|
|
|
"badges": {},
|
|
|
|
"categories": [],
|
|
|
|
"deps": [
|
|
|
|
{
|
|
|
|
"default_features": true,
|
|
|
|
"features": [],
|
|
|
|
"kind": "normal",
|
|
|
|
"name": "bar",
|
|
|
|
"optional": true,
|
|
|
|
"target": null,
|
|
|
|
"version_req": "^1.0"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"description": "foo",
|
|
|
|
"documentation": null,
|
|
|
|
"features": {
|
|
|
|
"feat1": [],
|
|
|
|
"feat2": ["dep:bar"],
|
|
|
|
"feat3": ["feat2"]
|
|
|
|
},
|
|
|
|
"homepage": "https://example.com/",
|
|
|
|
"keywords": [],
|
|
|
|
"license": "MIT",
|
|
|
|
"license_file": null,
|
|
|
|
"links": null,
|
|
|
|
"name": "foo",
|
|
|
|
"readme": null,
|
|
|
|
"readme_file": null,
|
|
|
|
"repository": null,
|
2023-03-24 20:46:59 +00:00
|
|
|
"rust_version": null,
|
2021-02-10 19:15:19 +00:00
|
|
|
"vers": "0.1.0"
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
"foo-0.1.0.crate",
|
|
|
|
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
|
|
|
|
&[(
|
|
|
|
"Cargo.toml",
|
2021-06-16 02:23:17 +00:00
|
|
|
&format!(
|
|
|
|
r#"{}
|
2021-02-10 19:15:19 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
description = "foo"
|
|
|
|
homepage = "https://example.com/"
|
|
|
|
license = "MIT"
|
2021-11-02 00:18:32 +00:00
|
|
|
|
2021-02-10 19:15:19 +00:00
|
|
|
[dependencies.bar]
|
|
|
|
version = "1.0"
|
|
|
|
optional = true
|
|
|
|
|
|
|
|
[features]
|
|
|
|
feat1 = []
|
|
|
|
feat2 = ["dep:bar"]
|
|
|
|
feat3 = ["feat2"]
|
|
|
|
"#,
|
2021-06-16 02:23:17 +00:00
|
|
|
cargo::core::package::MANIFEST_PREAMBLE
|
|
|
|
),
|
2021-02-10 19:15:19 +00:00
|
|
|
)],
|
|
|
|
);
|
|
|
|
}
|
2022-10-03 01:03:01 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn namespaced_feature_together() {
|
|
|
|
// Check for an error when `dep:` is used with `/`
|
|
|
|
Package::new("bar", "1.0.0")
|
|
|
|
.feature("bar-feat", &[])
|
|
|
|
.publish();
|
|
|
|
|
|
|
|
// Non-optional shouldn't have extra err.
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = "1.0"
|
|
|
|
|
|
|
|
[features]
|
|
|
|
f1 = ["dep:bar/bar-feat"]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
p.cargo("check")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
error: failed to parse manifest at `[ROOT]/foo/Cargo.toml`
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
feature `f1` includes `dep:bar/bar-feat` with both `dep:` and `/`
|
|
|
|
To fix this, remove the `dep:` prefix.
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
// Weak dependency shouldn't have extra err.
|
|
|
|
p.change_file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = {version = "1.0", optional = true }
|
|
|
|
|
|
|
|
[features]
|
|
|
|
f1 = ["dep:bar?/bar-feat"]
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
p.cargo("check")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
error: failed to parse manifest at `[ROOT]/foo/Cargo.toml`
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
feature `f1` includes `dep:bar?/bar-feat` with both `dep:` and `/`
|
|
|
|
To fix this, remove the `dep:` prefix.
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
// If dep: is already specified, shouldn't have extra err.
|
|
|
|
p.change_file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = {version = "1.0", optional = true }
|
|
|
|
|
|
|
|
[features]
|
|
|
|
f1 = ["dep:bar", "dep:bar/bar-feat"]
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
p.cargo("check")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
error: failed to parse manifest at `[ROOT]/foo/Cargo.toml`
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
feature `f1` includes `dep:bar/bar-feat` with both `dep:` and `/`
|
|
|
|
To fix this, remove the `dep:` prefix.
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
// Only when the other 3 cases aren't true should it give some extra help.
|
|
|
|
p.change_file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = {version = "1.0", optional = true }
|
|
|
|
|
|
|
|
[features]
|
|
|
|
f1 = ["dep:bar/bar-feat"]
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
p.cargo("check")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
error: failed to parse manifest at `[ROOT]/foo/Cargo.toml`
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
feature `f1` includes `dep:bar/bar-feat` with both `dep:` and `/`
|
|
|
|
To fix this, remove the `dep:` prefix.
|
|
|
|
If the intent is to avoid creating an implicit feature `bar` for an optional \
|
|
|
|
dependency, then consider replacing this with two values:
|
|
|
|
\"dep:bar\", \"bar/bar-feat\"
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
2023-05-11 16:34:38 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn dep_feature_when_hidden() {
|
|
|
|
// Checks for behavior with dep:bar and bar/feat syntax when there is no
|
|
|
|
// `bar` feature.
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar", optional = true }
|
|
|
|
|
|
|
|
[features]
|
|
|
|
f1 = ["dep:bar"]
|
|
|
|
f2 = ["bar/bar_feat"]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[features]
|
|
|
|
bar_feat = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("tree -f")
|
|
|
|
.arg("{p} features={f}")
|
|
|
|
.with_stdout(
|
|
|
|
"\
|
|
|
|
foo v0.1.0 ([ROOT]/foo) features=",
|
|
|
|
)
|
|
|
|
.with_stderr("")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("tree -F f1 -f")
|
|
|
|
.arg("{p} features={f}")
|
|
|
|
.with_stdout(
|
|
|
|
"\
|
|
|
|
foo v0.1.0 ([ROOT]/foo) features=f1
|
|
|
|
└── bar v0.1.0 ([ROOT]/foo/bar) features=
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stderr("")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("tree -F f2 -f")
|
|
|
|
.arg("{p} features={f}")
|
|
|
|
.with_stdout(
|
|
|
|
"\
|
|
|
|
foo v0.1.0 ([ROOT]/foo) features=f2
|
|
|
|
└── bar v0.1.0 ([ROOT]/foo/bar) features=bar_feat
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stderr("")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("tree --all-features -f")
|
|
|
|
.arg("{p} features={f}")
|
|
|
|
.with_stdout(
|
|
|
|
"\
|
|
|
|
foo v0.1.0 ([ROOT]/foo) features=f1,f2
|
|
|
|
└── bar v0.1.0 ([ROOT]/foo/bar) features=bar_feat
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stderr("")
|
|
|
|
.run();
|
|
|
|
}
|