Skip to content

Commit 82aa714

Browse files
committed
test: add tests for optional dependency resolution check
1 parent 0436f86 commit 82aa714

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

tests/testsuite/features.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use crate::prelude::*;
44
use cargo_test_support::registry::{Dependency, Package};
5-
use cargo_test_support::str;
65
use cargo_test_support::{basic_manifest, project};
6+
use cargo_test_support::{rustc_host, str};
77

88
#[cargo_test]
99
fn feature_activates_missing_feature() {
@@ -2368,3 +2368,38 @@ fn invalid_feature_name_slash_error() {
23682368
"#]])
23692369
.run();
23702370
}
2371+
2372+
#[cargo_test(ignore_windows = "test windows only dependency on unix systems")]
2373+
fn dont_demand_not_required_dep() {
2374+
Package::new("win-only", "1.0.0").publish();
2375+
2376+
let p = project()
2377+
.file(
2378+
"Cargo.toml",
2379+
r#"
2380+
[package]
2381+
name = "sample"
2382+
version = "0.1.0"
2383+
edition = "2024"
2384+
2385+
[features]
2386+
default = ["feat"]
2387+
feat = ["dep:win-only"]
2388+
2389+
[target.'cfg(windows)'.dependencies]
2390+
win-only = { version = "1.0", optional = true }
2391+
2392+
[[example]]
2393+
name = "demo"
2394+
required-features = ["feat"]
2395+
"#,
2396+
)
2397+
.file("src/main.rs", "fn main() {}")
2398+
.file("examples/demo.rs", "fn main() {}")
2399+
.build();
2400+
2401+
let host = rustc_host();
2402+
p.cargo(&format!("fetch --target={host}")).run();
2403+
p.cargo(&format!("check --target={host} --examples --frozen"))
2404+
.run();
2405+
}

0 commit comments

Comments
 (0)