Skip to content

Commit

Permalink
Add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab committed Feb 4, 2025
1 parent f327379 commit b0dc18d
Showing 1 changed file with 148 additions and 0 deletions.
148 changes: 148 additions & 0 deletions tests/testsuite/package_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,154 @@ feature set
.run();
}

#[cargo_test]
fn command_line_optional_dep() {
// Enabling a dependency used as a `dep:` errors
Package::new("bar", "1.0.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "a"
version = "0.1.0"
edition = "2015"
[features]
foo = ["dep:bar"]
[dependencies]
bar = { version = "1.0.0", optional = true }
"#,
)
.file("src/lib.rs", r#""#)
.build();

p.cargo("check --features bar")
.with_status(101)
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[ERROR] Package `a v0.1.0 ([ROOT]/foo)` does not have feature `bar`. It has an optional dependency with that name, but that dependency uses the "dep:" syntax in the features table, so it does not have an implicit feature with that name.
"#]])
.run();
}

#[cargo_test]
fn command_line_optional_dep_three_options() {
// Trying to enable an optional dependency used as a `dep:` errors, when there are three features which would enable the dependency
Package::new("bar", "1.0.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "a"
version = "0.1.0"
edition = "2015"
[features]
f1 = ["dep:bar"]
f2 = ["dep:bar"]
f3 = ["dep:bar"]
[dependencies]
bar = { version = "1.0.0", optional = true }
"#,
)
.file("src/lib.rs", r#""#)
.build();

p.cargo("check --features bar")
.with_status(101)
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[ERROR] Package `a v0.1.0 ([ROOT]/foo)` does not have feature `bar`. It has an optional dependency with that name, but that dependency uses the "dep:" syntax in the features table, so it does not have an implicit feature with that name.
"#]])
.run();
}

#[cargo_test]
fn command_line_optional_dep_many_options() {
// Trying to enable an optional dependency used as a `dep:` errors, when there are many features which would enable the dependency
Package::new("bar", "1.0.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "a"
version = "0.1.0"
edition = "2015"
[features]
f1 = ["dep:bar"]
f2 = ["dep:bar"]
f3 = ["dep:bar"]
f4 = ["dep:bar"]
[dependencies]
bar = { version = "1.0.0", optional = true }
"#,
)
.file("src/lib.rs", r#""#)
.build();

p.cargo("check --features bar")
.with_status(101)
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[ERROR] Package `a v0.1.0 ([ROOT]/foo)` does not have feature `bar`. It has an optional dependency with that name, but that dependency uses the "dep:" syntax in the features table, so it does not have an implicit feature with that name.
"#]])
.run();
}

#[cargo_test]
fn command_line_optional_dep_many_paths() {
// Trying to enable an optional dependency used as a `dep:` errors, when a features would enable the dependency in multiple ways
Package::new("bar", "1.0.0")
.feature("a", &[])
.feature("b", &[])
.feature("c", &[])
.feature("d", &[])
.publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "a"
version = "0.1.0"
edition = "2015"
[features]
f1 = ["dep:bar", "bar/a", "bar/b"] # Remove the implicit feature
f2 = ["bar/b", "bar/c"] # Overlaps with previous
f3 = ["bar/d"] # No overlap with previous
[dependencies]
bar = { version = "1.0.0", optional = true }
"#,
)
.file("src/lib.rs", r#""#)
.build();

p.cargo("check --features bar")
.with_status(101)
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[ERROR] Package `a v0.1.0 ([ROOT]/foo)` does not have feature `bar`. It has an optional dependency with that name, but that dependency uses the "dep:" syntax in the features table, so it does not have an implicit feature with that name.
"#]])
.run();
}

#[cargo_test]
fn virtual_member_slash() {
// member slash feature syntax
Expand Down

0 comments on commit b0dc18d

Please sign in to comment.