Skip to content

Commit 2d23c27

Browse files
committed
Rust: Test deterministic dependency configuration selection
Add tests for extraction of dependency files with different features enabled in different manifest files.
1 parent c59c72c commit 2d23c27

17 files changed

Lines changed: 191 additions & 10 deletions

File tree

‎rust/extractor/src/configuration.rs‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,19 @@ mod tests {
126126
}
127127
cfg
128128
};
129-
let root = crate::cwd().unwrap();
130-
let manifest = |path| ProjectManifest::from_manifest_file(root.join(path)).unwrap();
131129
let candidates = [
132-
(manifest("z/Cargo.toml"), cfg(&["z"])),
133-
(manifest("a/Cargo.toml"), cfg(&["a", "b"])),
134-
(manifest("b/Cargo.toml"), cfg(&["a", "b"])),
130+
("z", cfg(&["z"])),
131+
("a", cfg(&["a", "b"])),
132+
("b", cfg(&["a", "b"])),
135133
];
136134
for order in [[0, 1, 2], [2, 1, 0]] {
137135
let mut plan = DependencyFiles::default();
138-
for (manifest, cfg) in order.map(|index| &candidates[index]) {
139-
plan.add_candidate(Path::new("lib.rs"), Some(cfg.clone()), manifest);
136+
for index in order {
137+
let (workspace, cfg) = &candidates[index];
138+
plan.add_candidate(Path::new("lib.rs"), Some(cfg.clone()), Path::new(workspace));
140139
}
141-
let expected = HashMap::from([(&candidates[2].0, vec![PathBuf::from("lib.rs")])]);
142-
assert_eq!(plan.by_manifests(), expected);
140+
let expected = HashMap::from([(Path::new("b"), vec![PathBuf::from("lib.rs")])]);
141+
assert_eq!(plan.by_workspaces(), expected);
143142
}
144143
}
145144
}

‎rust/extractor/src/diagnostics.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ mod tests {
292292
use super::*;
293293

294294
#[test]
295-
fn counts_unique_manifests() {
295+
fn counts_unique_manifests_but_includes_reload_duration() {
296296
let steps: Vec<_> = ["a/Cargo.toml", "b/Cargo.toml", "a/Cargo.toml"]
297297
.into_iter()
298298
.map(|path| ExtractionStep {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Add a source definition backed by the directories in "dependencies"
2+
[source.test-dependencies]
3+
directory = "dependencies"
4+
5+
# Map crates.io to our local source definition
6+
[source.crates-io]
7+
replace-with = "test-dependencies"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"files": {}, "package": null}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "alpha"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[features]
7+
a = []
8+
b = []
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#[cfg(feature = "a")]
2+
pub fn a() {}
3+
4+
#[cfg(feature = "b")]
5+
pub fn b() {}
6+
7+
#[cfg(feature = "b")]
8+
#[macro_export]
9+
macro_rules! invoke {
10+
() => {
11+
$crate::b()
12+
};
13+
}
14+
15+
#[cfg(not(feature = "b"))]
16+
#[macro_export]
17+
macro_rules! invoke {
18+
() => {
19+
$crate::a()
20+
};
21+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"files": {}, "package": null}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "beta"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[features]
7+
a = []
8+
b = []
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#[cfg(feature = "a")]
2+
pub fn a() {}
3+
4+
#[cfg(feature = "b")]
5+
pub fn b() {}
6+
7+
#[cfg(feature = "b")]
8+
#[macro_export]
9+
macro_rules! invoke {
10+
() => {
11+
$crate::b()
12+
};
13+
}
14+
15+
#[cfg(not(feature = "b"))]
16+
#[macro_export]
17+
macro_rules! invoke {
18+
() => {
19+
$crate::a()
20+
};
21+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import rust
2+
3+
from Call c, string target
4+
where
5+
c.getFile().getRelativePath() in [
6+
"first/src/lib.rs", "second/src/lib.rs", "src/lib.rs", "build.rs"
7+
] and
8+
(
9+
target = c.getStaticTarget().getCanonicalPath()
10+
or
11+
not exists(c.getStaticTarget()) and target = "<unresolved>"
12+
)
13+
select c, target

0 commit comments

Comments
 (0)