mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 14:51:48 +00:00
Merge #10503
10503: Only include targets of packages that are workspace members r=Veykril a=bcully CargoWorkspace's package list includes packages that are path dependencies, even if those packages aren't actually members of the cargo workspace. As a result, rust-analyzer's runnable finder, which returns the target from the first workspace that has a matching package, may select the wrong working directory, causing runnables to fail, e.g., ``` error: package `root` cannot be tested because it requires dev-dependencies and is not a member of the workspace ``` To fix this, we filter out packages that aren't members of the workspace when searching for targets. Fixes #7764 Co-authored-by: Brendan Cully <brendan@cully.org>
This commit is contained in:
commit
c5354877c9
2 changed files with 95 additions and 2 deletions
|
@ -202,6 +202,93 @@ fn main() {}
|
|||
);
|
||||
}
|
||||
|
||||
// Each package in these workspaces should be run from its own root
|
||||
#[test]
|
||||
fn test_path_dependency_runnables() {
|
||||
if skip_slow_tests() {
|
||||
return;
|
||||
}
|
||||
|
||||
let server = Project::with_fixture(
|
||||
r#"
|
||||
//- /consumer/Cargo.toml
|
||||
[package]
|
||||
name = "consumer"
|
||||
version = "0.1.0"
|
||||
[dependencies]
|
||||
dependency = { path = "../dependency" }
|
||||
|
||||
//- /consumer/src/lib.rs
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn consumer() {}
|
||||
}
|
||||
|
||||
//- /dependency/Cargo.toml
|
||||
[package]
|
||||
name = "dependency"
|
||||
version = "0.1.0"
|
||||
[dev-dependencies]
|
||||
devdependency = { path = "../devdependency" }
|
||||
|
||||
//- /dependency/src/lib.rs
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn dependency() {}
|
||||
}
|
||||
|
||||
//- /devdependency/Cargo.toml
|
||||
[package]
|
||||
name = "devdependency"
|
||||
version = "0.1.0"
|
||||
|
||||
//- /devdependency/src/lib.rs
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn devdependency() {}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.root("consumer")
|
||||
.root("dependency")
|
||||
.root("devdependency")
|
||||
.server()
|
||||
.wait_until_workspace_is_loaded();
|
||||
|
||||
for runnable in ["consumer", "dependency", "devdependency"] {
|
||||
server.request::<Runnables>(
|
||||
RunnablesParams {
|
||||
text_document: server.doc_id(&format!("{}/src/lib.rs", runnable)),
|
||||
position: None,
|
||||
},
|
||||
json!([
|
||||
"{...}",
|
||||
{
|
||||
"label": "cargo test -p [..] --all-targets",
|
||||
"kind": "cargo",
|
||||
"args": {
|
||||
"overrideCargo": null,
|
||||
"workspaceRoot": server.path().join(runnable),
|
||||
"cargoArgs": [
|
||||
"test",
|
||||
"--package",
|
||||
runnable,
|
||||
"--all-targets"
|
||||
],
|
||||
"cargoExtraArgs": [],
|
||||
"executableArgs": []
|
||||
},
|
||||
},
|
||||
"{...}",
|
||||
"{...}"
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_document() {
|
||||
if skip_slow_tests() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue