Skip to content

Commit e77a267

Browse files
committed
Support more runnable kinds for project json
Allows project JSON users to run a whole module of tests, benchmarks, doctests.
1 parent 14001c5 commit e77a267

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

crates/project-model/src/project_json.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,21 @@ pub enum RunnableKind {
365365
/// May include {test_id} which will get the test clicked on by the user.
366366
TestOne,
367367

368+
/// Run tests matching a pattern (in RA, usually a path::to::module::of::tests)
369+
/// May include {label} which will get the label from the `build` section of a crate.
370+
/// May include {test_pattern} which will get the test module clicked on by the user.
371+
TestMod,
372+
373+
/// Run a single doctest
374+
/// May include {label} which will get the label from the `build` section of a crate.
375+
/// May include {test_id} which will get the doctest clicked on by the user.
376+
DocTestOne,
377+
378+
/// Run a single benchmark
379+
/// May include {label} which will get the label from the `build` section of a crate.
380+
/// May include {bench_id} which will get the benchmark clicked on by the user.
381+
BenchOne,
382+
368383
/// Template for checking a target, emitting rustc JSON diagnostics.
369384
/// May include {label} which will get the label from the `build` section of a crate.
370385
Flycheck,
@@ -481,6 +496,9 @@ pub enum RunnableKindData {
481496
Check,
482497
Run,
483498
TestOne,
499+
TestMod,
500+
DocTestOne,
501+
BenchOne,
484502

485503
/// For forwards-compatibility, i.e. old rust-analyzer binary with newer workspace discovery tools
486504
#[allow(unused)]
@@ -553,6 +571,9 @@ impl From<RunnableKindData> for RunnableKind {
553571
RunnableKindData::Check => RunnableKind::Check,
554572
RunnableKindData::Run => RunnableKind::Run,
555573
RunnableKindData::TestOne => RunnableKind::TestOne,
574+
RunnableKindData::TestMod => RunnableKind::TestMod,
575+
RunnableKindData::DocTestOne => RunnableKind::DocTestOne,
576+
RunnableKindData::BenchOne => RunnableKind::BenchOne,
556577
RunnableKindData::Flycheck => RunnableKind::Flycheck,
557578
RunnableKindData::Unknown => RunnableKind::Unknown,
558579
}

crates/rust-analyzer/src/target_spec.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,20 @@ impl ProjectJsonTargetSpec {
103103
arg.replace("{label}", &this.label).replace("{test_id}", &test_id.to_string())
104104
})
105105
}
106-
RunnableKind::TestMod { .. } => None,
107-
RunnableKind::Bench { .. } => None,
108-
RunnableKind::DocTest { .. } => None,
106+
RunnableKind::TestMod { path } => self
107+
.find_replace_runnable(project_json::RunnableKind::TestMod, &|this, arg| {
108+
arg.replace("{label}", &this.label).replace("{test_pattern}", path)
109+
}),
110+
RunnableKind::Bench { test_id } => {
111+
self.find_replace_runnable(project_json::RunnableKind::BenchOne, &|this, arg| {
112+
arg.replace("{label}", &this.label).replace("{bench_id}", &test_id.to_string())
113+
})
114+
}
115+
RunnableKind::DocTest { test_id } => {
116+
self.find_replace_runnable(project_json::RunnableKind::DocTestOne, &|this, arg| {
117+
arg.replace("{label}", &this.label).replace("{test_id}", &test_id.to_string())
118+
})
119+
}
109120
}
110121
}
111122
}

0 commit comments

Comments
 (0)