diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-08-26 18:41:45 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-08-26 18:41:45 +0100 |
commit | 7e012ae8b54705bc254154cdff3a503cce3299a7 (patch) | |
tree | c1105a002b0e866bbd397188841f46243b336b6d /crates | |
parent | 3d6c4c143b4b4c74810318eca1b5493e43535fff (diff) | |
parent | 964219f0be87d189e13dd63a6ffc4d9d53eafbb4 (diff) |
Merge #5893
5893: Allow running a test as a binary r=matklad a=jonas-schievink
If a test uses `harness = false`, it just contains an `fn main` that is executed via `cargo test`. This adds support for that.
Note though that Cargo doesn't actually tell us whether `harness = false`, so this hint will always show up when you put an `fn main` into an integration test. Normally people shouldn't be doing that if they do use the harness though.
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/cargo_target_spec.rs | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 5 |
2 files changed, 9 insertions, 2 deletions
diff --git a/crates/rust-analyzer/src/cargo_target_spec.rs b/crates/rust-analyzer/src/cargo_target_spec.rs index 3041915e1..ddc028148 100644 --- a/crates/rust-analyzer/src/cargo_target_spec.rs +++ b/crates/rust-analyzer/src/cargo_target_spec.rs | |||
@@ -72,7 +72,11 @@ impl CargoTargetSpec { | |||
72 | extra_args.push("--nocapture".to_string()); | 72 | extra_args.push("--nocapture".to_string()); |
73 | } | 73 | } |
74 | RunnableKind::Bin => { | 74 | RunnableKind::Bin => { |
75 | args.push("run".to_string()); | 75 | let subcommand = match spec { |
76 | Some(CargoTargetSpec { target_kind: TargetKind::Test, .. }) => "test", | ||
77 | _ => "run", | ||
78 | }; | ||
79 | args.push(subcommand.to_string()); | ||
76 | if let Some(spec) = spec { | 80 | if let Some(spec) = spec { |
77 | spec.push_to(&mut args, kind); | 81 | spec.push_to(&mut args, kind); |
78 | } | 82 | } |
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 33e60b500..8568f7b05 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -1399,7 +1399,10 @@ fn should_skip_target(runnable: &Runnable, cargo_spec: Option<&CargoTargetSpec>) | |||
1399 | RunnableKind::Bin => { | 1399 | RunnableKind::Bin => { |
1400 | // Do not suggest binary run on other target than binary | 1400 | // Do not suggest binary run on other target than binary |
1401 | match &cargo_spec { | 1401 | match &cargo_spec { |
1402 | Some(spec) => !matches!(spec.target_kind, TargetKind::Bin | TargetKind::Example), | 1402 | Some(spec) => !matches!( |
1403 | spec.target_kind, | ||
1404 | TargetKind::Bin | TargetKind::Example | TargetKind::Test | ||
1405 | ), | ||
1403 | None => true, | 1406 | None => true, |
1404 | } | 1407 | } |
1405 | } | 1408 | } |