Skip to content

Commit 4de0204

Browse files
committed
Auto merge of #16880 - HKalbasi:test-explorer, r=HKalbasi
Use `--workspace` and `--no-fail-fast` in test explorer This PR contains: * Using `--workspace` in `cargo test` command, to running all tests even when there is a crate in the root of a workspace * Using `--no-fail-fast` to run all requested tests * Excluding bench in the test explorer * Fixing a bug in the `hack_recover_crate_name` fix #16874
2 parents 59b9cc1 + 92300e8 commit 4de0204

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

crates/flycheck/src/test_runner.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ pub struct CargoTestHandle {
5555
}
5656

5757
// Example of a cargo test command:
58-
// cargo test -- module::func -Z unstable-options --format=json
58+
// cargo test --workspace --no-fail-fast -- module::func -Z unstable-options --format=json
5959

6060
impl CargoTestHandle {
6161
pub fn new(path: Option<&str>) -> std::io::Result<Self> {
6262
let mut cmd = Command::new(Tool::Cargo.path());
6363
cmd.env("RUSTC_BOOTSTRAP", "1");
6464
cmd.arg("test");
65+
cmd.arg("--workspace");
66+
// --no-fail-fast is needed to ensure that all requested tests will run
67+
cmd.arg("--no-fail-fast");
6568
cmd.arg("--");
6669
if let Some(path) = path {
6770
cmd.arg(path);

crates/rust-analyzer/src/handlers/request.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ pub(crate) fn handle_discover_test(
248248
Ok(lsp_ext::DiscoverTestResults {
249249
tests: tests
250250
.into_iter()
251-
.map(|t| {
251+
.filter_map(|t| {
252252
let line_index = t.file.and_then(|f| snap.file_line_index(f).ok());
253253
to_proto::test_item(&snap, t, line_index.as_ref())
254254
})

crates/rust-analyzer/src/lsp/to_proto.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1516,8 +1516,8 @@ pub(crate) fn test_item(
15161516
snap: &GlobalStateSnapshot,
15171517
test_item: ide::TestItem,
15181518
line_index: Option<&LineIndex>,
1519-
) -> lsp_ext::TestItem {
1520-
lsp_ext::TestItem {
1519+
) -> Option<lsp_ext::TestItem> {
1520+
Some(lsp_ext::TestItem {
15211521
id: test_item.id,
15221522
label: test_item.label,
15231523
kind: match test_item.kind {
@@ -1532,9 +1532,9 @@ pub(crate) fn test_item(
15321532
| project_model::TargetKind::Example
15331533
| project_model::TargetKind::BuildScript
15341534
| project_model::TargetKind::Other => lsp_ext::TestItemKind::Package,
1535-
project_model::TargetKind::Test | project_model::TargetKind::Bench => {
1536-
lsp_ext::TestItemKind::Test
1537-
}
1535+
project_model::TargetKind::Test => lsp_ext::TestItemKind::Test,
1536+
// benches are not tests needed to be shown in the test explorer
1537+
project_model::TargetKind::Bench => return None,
15381538
}
15391539
}
15401540
ide::TestItemKind::Module => lsp_ext::TestItemKind::Module,
@@ -1550,7 +1550,7 @@ pub(crate) fn test_item(
15501550
.map(|f| lsp_types::TextDocumentIdentifier { uri: url(snap, f) }),
15511551
range: line_index.and_then(|l| Some(range(l, test_item.text_range?))),
15521552
runnable: test_item.runnable.and_then(|r| runnable(snap, r).ok()),
1553-
}
1553+
})
15541554
}
15551555

15561556
pub(crate) mod command {

crates/rust-analyzer/src/main_loop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ impl GlobalState {
552552
Task::DiscoverTest(lsp_ext::DiscoverTestResults {
553553
tests: tests
554554
.into_iter()
555-
.map(|t| {
555+
.filter_map(|t| {
556556
let line_index = t.file.and_then(|f| snapshot.file_line_index(f).ok());
557557
to_proto::test_item(&snapshot, t, line_index.as_ref())
558558
})

editors/code/src/test_explorer.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ export const prepareTestExplorer = (
105105
testSet.add(test.id);
106106
}
107107
// FIXME(hack_recover_crate_name): We eagerly resolve every test if we got a lazy top level response (detected
108-
// by `!scope`). ctx is not a good thing and wastes cpu and memory unnecessarily, so we should remove it.
109-
if (!scope) {
108+
// by checking that `scope` is empty). This is not a good thing and wastes cpu and memory unnecessarily, so we
109+
// should remove it.
110+
if (scope.length === 0) {
110111
for (const test of tests) {
111112
void testController.resolveHandler!(idToTestMap.get(test.id));
112113
}

0 commit comments

Comments
 (0)