Skip to content

Commit ea459ea

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

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tests/testsuite/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ mod registry_overlay;
164164
mod rename_deps;
165165
mod replace;
166166
mod required_features;
167+
mod resolve_optional_dependency;
167168
mod run;
168169
mod rust_version;
169170
mod rustc;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use crate::prelude::*;
2+
use cargo_test_support::project;
3+
4+
#[cargo_test(ignore_windows = "test windows only dependency on unix systems")]
5+
fn cargo_test_should_not_demand_not_required_dep() {
6+
let p = project()
7+
.file(
8+
"Cargo.toml",
9+
r#"
10+
[package]
11+
name = "sample"
12+
version = "0.1.0"
13+
edition = "2024"
14+
15+
[features]
16+
default = ["feat"]
17+
feat = ["dep:ipconfig"]
18+
19+
[target.'cfg(windows)'.dependencies]
20+
ipconfig = { version = "0.3.2", optional = true }
21+
22+
[[example]]
23+
name = "demo"
24+
required-features = ["feat"]
25+
"#,
26+
)
27+
.file("src/main.rs", "fn main() {}")
28+
.file("examples/demo.rs", "fn main() {}")
29+
.build();
30+
31+
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
32+
{
33+
p.cargo("fetch --target=x86_64-unknown-linux-gnu").run();
34+
p.cargo("test --target=x86_64-unknown-linux-gnu --frozen")
35+
.run();
36+
}
37+
38+
#[cfg(all(target_os = "linux", target_arch = "aarch64"))]
39+
{
40+
p.cargo("fetch --target=aarch64-unknown-linux-gnu").run();
41+
p.cargo("test --target=aarch64-unknown-linux-gnu --frozen")
42+
.run();
43+
}
44+
45+
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
46+
{
47+
p.cargo("fetch --target=aarch64-apple-darwin").run();
48+
p.cargo("test --target=aarch64-apple-darwin --frozen").run();
49+
}
50+
}

0 commit comments

Comments
 (0)