Skip to content

Commit 7e012ae

Browse files
bors[bot]Jonas Schievink
andauthored
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 <jonas.schievink@ferrous-systems.com>
2 parents 3d6c4c1 + 964219f commit 7e012ae

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

crates/rust-analyzer/src/cargo_target_spec.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ impl CargoTargetSpec {
7272
extra_args.push("--nocapture".to_string());
7373
}
7474
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());
7680
if let Some(spec) = spec {
7781
spec.push_to(&mut args, kind);
7882
}

crates/rust-analyzer/src/handlers.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,10 @@ fn should_skip_target(runnable: &Runnable, cargo_spec: Option<&CargoTargetSpec>)
13991399
RunnableKind::Bin => {
14001400
// Do not suggest binary run on other target than binary
14011401
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+
),
14031406
None => true,
14041407
}
14051408
}

0 commit comments

Comments
 (0)