Skip to content

Commit

Permalink
Merge #4154
Browse files Browse the repository at this point in the history
4154: Add `cargo test` to the list of Run commands r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
  • Loading branch information
bors[bot] and matklad committed Apr 26, 2020
2 parents fe99a29 + 5ef0f44 commit d22d88f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 62 deletions.
1 change: 1 addition & 0 deletions crates/rust-analyzer/src/cargo_target_spec.rs
Expand Up @@ -9,6 +9,7 @@ use crate::{world::WorldSnapshot, Result};
///
/// We use it to cook up the set of cli args we need to pass to Cargo to
/// build/test/run the target.
#[derive(Clone)]
pub(crate) struct CargoTargetSpec {
pub(crate) package: String,
pub(crate) target: String,
Expand Down
41 changes: 25 additions & 16 deletions crates/rust-analyzer/src/main_loop/handlers.rs
Expand Up @@ -393,28 +393,37 @@ pub fn handle_runnables(
}
res.push(to_lsp_runnable(&world, file_id, runnable)?);
}
let mut check_args = vec!["check".to_string()];
let label;
// Add `cargo check` and `cargo test` for the whole package
match CargoTargetSpec::for_file(&world, file_id)? {
Some(spec) => {
label = format!("cargo check -p {}", spec.package);
spec.push_to(&mut check_args);
for &cmd in ["check", "test"].iter() {
res.push(req::Runnable {
range: Default::default(),
label: format!("cargo {} -p {}", cmd, spec.package),
bin: "cargo".to_string(),
args: {
let mut args = vec![cmd.to_string()];
spec.clone().push_to(&mut args);
args
},
extra_args: Vec::new(),
env: FxHashMap::default(),
cwd: workspace_root.map(|root| root.to_owned()),
})
}
}
None => {
label = "cargo check --all".to_string();
check_args.push("--all".to_string())
res.push(req::Runnable {
range: Default::default(),
label: "cargo check --workspace".to_string(),
bin: "cargo".to_string(),
args: vec!["check".to_string(), "--workspace".to_string()],
extra_args: Vec::new(),
env: FxHashMap::default(),
cwd: workspace_root.map(|root| root.to_owned()),
});
}
}
// Always add `cargo check`.
res.push(req::Runnable {
range: Default::default(),
label,
bin: "cargo".to_string(),
args: check_args,
extra_args: Vec::new(),
env: FxHashMap::default(),
cwd: workspace_root.map(|root| root.to_owned()),
});
Ok(res)
}

Expand Down
83 changes: 37 additions & 46 deletions crates/rust-analyzer/tests/heavy_tests/main.rs
Expand Up @@ -87,24 +87,15 @@ fn foo() {
}
},
{
"args": [
"check",
"--all"
],
"args": ["check", "--workspace"],
"extraArgs": [],
"bin": "cargo",
"env": {},
"cwd": null,
"label": "cargo check --all",
"label": "cargo check --workspace",
"range": {
"end": {
"character": 0,
"line": 0
},
"start": {
"character": 0,
"line": 0
}
"end": { "character": 0, "line": 0 },
"start": { "character": 0, "line": 0 }
}
}
]),
Expand Down Expand Up @@ -145,42 +136,42 @@ fn main() {}
server.request::<Runnables>(
RunnablesParams { text_document: server.doc_id("foo/tests/spam.rs"), position: None },
json!([
{
"args": [ "test", "--package", "foo", "--test", "spam" ],
"extraArgs": [ "test_eggs", "--exact", "--nocapture" ],
"bin": "cargo",
"env": { "RUST_BACKTRACE": "short" },
"label": "test test_eggs",
"range": {
"end": { "character": 17, "line": 1 },
"start": { "character": 0, "line": 0 }
{
"args": [ "test", "--package", "foo", "--test", "spam" ],
"extraArgs": [ "test_eggs", "--exact", "--nocapture" ],
"bin": "cargo",
"env": { "RUST_BACKTRACE": "short" },
"label": "test test_eggs",
"range": {
"end": { "character": 17, "line": 1 },
"start": { "character": 0, "line": 0 }
},
"cwd": server.path().join("foo")
},
"cwd": server.path().join("foo")
},
{
"args": [
"check",
"--package",
"foo",
"--test",
"spam"
],
"extraArgs": [],
"bin": "cargo",
"env": {},
"cwd": server.path().join("foo"),
"label": "cargo check -p foo",
"range": {
"end": {
"character": 0,
"line": 0
{
"args": [ "check", "--package", "foo", "--test", "spam" ],
"extraArgs": [],
"bin": "cargo",
"env": {},
"label": "cargo check -p foo",
"range": {
"end": { "character": 0, "line": 0 },
"start": { "character": 0, "line": 0 }
},
"start": {
"character": 0,
"line": 0
}
"cwd": server.path().join("foo")
},
{
"args": [ "test", "--package", "foo", "--test", "spam" ],
"extraArgs": [],
"bin": "cargo",
"env": {},
"label": "cargo test -p foo",
"range": {
"end": { "character": 0, "line": 0 },
"start": { "character": 0, "line": 0 }
},
"cwd": server.path().join("foo")
}
}
]),
);
}
Expand Down

0 comments on commit d22d88f

Please sign in to comment.