mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
exclude build script targets from testing
This commit is contained in:
parent
6d50737732
commit
d51ecf8a41
@ -195,6 +195,8 @@ pub(crate) fn handle_view_item_tree(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cargo test requires:
|
// cargo test requires:
|
||||||
|
// - the package is a member of the workspace
|
||||||
|
// - the target in the package is not a build script (custom-build)
|
||||||
// - the package name - the root of the test identifier supplied to this handler can be
|
// - the package name - the root of the test identifier supplied to this handler can be
|
||||||
// a package or a target inside a package.
|
// a package or a target inside a package.
|
||||||
// - the target name - if the test identifier is a target, it's needed in addition to the
|
// - the target name - if the test identifier is a target, it's needed in addition to the
|
||||||
@ -202,39 +204,26 @@ pub(crate) fn handle_view_item_tree(
|
|||||||
// - real names - the test identifier uses the namespace form where hyphens are replaced with
|
// - real names - the test identifier uses the namespace form where hyphens are replaced with
|
||||||
// underscores. cargo test requires the real name.
|
// underscores. cargo test requires the real name.
|
||||||
// - the target kind e.g. bin or lib
|
// - the target kind e.g. bin or lib
|
||||||
fn find_test_target(namespace_root: &str, cargo: &CargoWorkspace) -> Option<TestTarget> {
|
fn all_test_targets(cargo: &CargoWorkspace) -> impl Iterator<Item = TestTarget> {
|
||||||
cargo.packages().filter(|p| cargo[*p].is_member).find_map(|p| {
|
cargo.packages().filter(|p| cargo[*p].is_member).flat_map(|p| {
|
||||||
let package_name = &cargo[p].name;
|
let package = &cargo[p];
|
||||||
for target in cargo[p].targets.iter() {
|
package.targets.iter().filter_map(|t| {
|
||||||
let target_name = &cargo[*target].name;
|
let target = &cargo[*t];
|
||||||
if target_name.replace('-', "_") == namespace_root {
|
if target.kind == TargetKind::BuildScript {
|
||||||
return Some(TestTarget {
|
None
|
||||||
package: package_name.clone(),
|
} else {
|
||||||
target: target_name.clone(),
|
Some(TestTarget {
|
||||||
kind: cargo[*target].kind,
|
package: package.name.clone(),
|
||||||
});
|
target: target.name.clone(),
|
||||||
|
kind: target.kind,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
None
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_all_targets(cargo: &CargoWorkspace) -> Vec<TestTarget> {
|
fn find_test_target(namespace_root: &str, cargo: &CargoWorkspace) -> Option<TestTarget> {
|
||||||
cargo
|
all_test_targets(cargo).find(|t| namespace_root == t.target.replace('-', "_"))
|
||||||
.packages()
|
|
||||||
.filter(|p| cargo[*p].is_member)
|
|
||||||
.flat_map(|p| {
|
|
||||||
let package_name = &cargo[p].name;
|
|
||||||
cargo[p].targets.iter().map(|target| {
|
|
||||||
let target_name = &cargo[*target].name;
|
|
||||||
TestTarget {
|
|
||||||
package: package_name.clone(),
|
|
||||||
target: target_name.clone(),
|
|
||||||
kind: cargo[*target].kind,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn handle_run_test(
|
pub(crate) fn handle_run_test(
|
||||||
@ -266,7 +255,7 @@ pub(crate) fn handle_run_test(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect_vec(),
|
.collect_vec(),
|
||||||
None => get_all_targets(cargo).into_iter().map(|target| (target, None)).collect(),
|
None => all_test_targets(cargo).into_iter().map(|target| (target, None)).collect(),
|
||||||
};
|
};
|
||||||
|
|
||||||
for (target, path) in tests {
|
for (target, path) in tests {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user