Skip to content

Commit 2bfb66f

Browse files
committed
Add test for #60
1 parent 24df688 commit 2bfb66f

File tree

11 files changed

+1598
-8
lines changed

11 files changed

+1598
-8
lines changed

tests/feature-bug/Cargo.toml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[workspace.dependencies]
2+
ndarray-linalg = { path = "ndarray-linalg" }
3+
lax = { path = "lax" }
4+
5+
workspace.members = ["lax", "ndarray-linalg", "sub-crate"]
6+
7+
[package]
8+
name = "feature-bug"
9+
version = "0.1.0"
10+
edition = "2021"
11+
12+
[dependencies]
13+
sub-crate = { path = "sub-crate", version = "0.1", default-features = false, features = [
14+
"simple",
15+
] }
16+
17+
[dev-dependencies]
18+
ndarray-linalg = { workspace = true, features = ["intel-mkl-static"] }

tests/feature-bug/lax/Cargo.toml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[package]
2+
name = "lax"
3+
version = "0.16.0"
4+
edition = "2021"
5+
6+
[features]
7+
default = []
8+
9+
netlib = ["netlib-static"]
10+
openblas = ["openblas-static"]
11+
intel-mkl = ["intel-mkl-static"]
12+
13+
netlib-static = ["netlib-src/static"]
14+
netlib-system = ["netlib-src/system"]
15+
16+
openblas-static = ["openblas-src/static"]
17+
openblas-system = ["openblas-src/system"]
18+
19+
intel-mkl-static = ["intel-mkl-src/mkl-static-lp64-seq"]
20+
intel-mkl-system = ["intel-mkl-src/mkl-dynamic-lp64-seq"]
21+
22+
[dependencies]
23+
itoa = "1.0"
24+
25+
[dependencies.intel-mkl-src]
26+
version = "0.8.1"
27+
default-features = false
28+
optional = true
29+
30+
[dependencies.netlib-src]
31+
version = "0.8.0"
32+
optional = true
33+
features = ["cblas"]
34+
default-features = false
35+
36+
[dependencies.openblas-src]
37+
version = "0.10.4"
38+
optional = true
39+
default-features = false
40+
features = ["cblas"]

tests/feature-bug/lax/src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub fn add(left: usize, right: usize) -> usize {
2+
left + right
3+
}
4+
5+
#[cfg(test)]
6+
mod tests {
7+
use super::*;
8+
9+
#[test]
10+
fn it_works() {
11+
let result = add(2, 2);
12+
assert_eq!(result, 4);
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[package]
2+
name = "ndarray-linalg"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[features]
7+
default = []
8+
9+
netlib = ["lax/netlib"]
10+
openblas = ["lax/openblas"]
11+
intel-mkl = ["lax/intel-mkl"]
12+
13+
netlib-static = ["lax/netlib-static"]
14+
netlib-system = ["lax/netlib-system"]
15+
16+
openblas-static = ["lax/openblas-static"]
17+
openblas-system = ["lax/openblas-system"]
18+
19+
intel-mkl-static = ["lax/intel-mkl-static"]
20+
intel-mkl-system = ["lax/intel-mkl-system"]
21+
22+
[dependencies]
23+
libc = "0.2"
24+
25+
[dependencies.ndarray]
26+
version = "0.15.2"
27+
features = ["blas", "approx", "std"]
28+
default-features = false
29+
30+
[dependencies.lax]
31+
version = "0.16.0"
32+
workspace = true
33+
default-features = false
34+
35+
[dev-dependencies]
36+
paste = "1.0.5"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub fn add(left: usize, right: usize) -> usize {
2+
left + right
3+
}
4+
5+
#[cfg(test)]
6+
mod tests {
7+
use super::*;
8+
9+
#[test]
10+
fn it_works() {
11+
let result = add(2, 2);
12+
assert_eq!(result, 4);
13+
}
14+
}

tests/feature-bug/src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub fn add(left: usize, right: usize) -> usize {
2+
left + right
3+
}
4+
5+
#[cfg(test)]
6+
mod tests {
7+
use super::*;
8+
9+
#[test]
10+
fn it_works() {
11+
let result = add(2, 2);
12+
assert_eq!(result, 4);
13+
}
14+
}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "sub-crate"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[features]
7+
default = []
8+
simple = ["dep:ndarray-linalg"]
9+
10+
[target.'cfg(target_os = "windows")'.dependencies]
11+
ndarray-linalg = { workspace = true, default-features = false, optional = true }
12+
13+
[target.'cfg(target_os = "linux")'.dependencies]
14+
ndarray-linalg = { workspace = true, default-features = false, features = [
15+
"netlib",
16+
], optional = true }
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tests/features.rs

+17
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,23 @@ fn handles_cyclic_features() {
234234
assert_features!(md, "features-galore", ["cycle", "midi", "subfeatcycle"]);
235235
}
236236

237+
/// Ensures that features only brought in by eg dev-dependencies are not used if
238+
/// dev-dependencies are ignored
239+
/// <https://github.com/EmbarkStudios/krates/issues/60>
240+
#[test]
241+
fn ignores_features_for_ignored_kinds() {
242+
let mut cmd = krates::Cmd::new();
243+
cmd.manifest_path("tests/feature-bug/Cargo.toml")
244+
.all_features();
245+
246+
let mut builder = krates::Builder::new();
247+
builder.ignore_kind(krates::DepKind::Dev, krates::Scope::All);
248+
let md: krates::Krates<util::JustId> = builder.build(cmd, krates::NoneFilter).unwrap();
249+
250+
let dotgraph = krates::petgraph::dot::Dot::new(md.graph()).to_string();
251+
insta::assert_snapshot!(dotgraph);
252+
}
253+
237254
/// Tests validating <https://github.com/EmbarkStudios/krates/issues/46>
238255
mod prefer_index {
239256
fn confirm_index_snapshot(builder: krates::Builder) {

tests/features/src/lib.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
#[cfg(test)]
2-
mod tests {
3-
#[test]
4-
fn it_works() {
5-
let result = 2 + 2;
6-
assert_eq!(result, 4);
7-
}
8-
}
1+

tests/snapshots/features__ignores_features_for_ignored_kinds.snap

+1,427
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)