From bc3db7c1ded0db2d3804b5ac3e5c35dd53350228 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 2 Jun 2020 18:02:58 +0200 Subject: Fix tests --- crates/ra_ide/src/runnables.rs | 225 +++++++++++++++++++++++-- crates/rust-analyzer/src/lsp_ext.rs | 1 + crates/rust-analyzer/tests/heavy_tests/main.rs | 113 +++++++------ 3 files changed, 270 insertions(+), 69 deletions(-) diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index 9239ca61b..f32ce0d22 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs @@ -228,12 +228,38 @@ mod tests { @r###" [ Runnable { - range: 1..21, + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 1..21, + name: "main", + kind: FN_DEF, + focus_range: Some( + 12..16, + ), + container_name: None, + description: None, + docs: None, + }, kind: Bin, cfg_exprs: [], }, Runnable { - range: 22..46, + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 22..46, + name: "test_foo", + kind: FN_DEF, + focus_range: Some( + 33..41, + ), + container_name: None, + description: None, + docs: None, + }, kind: Test { test_id: Path( "test_foo", @@ -245,7 +271,20 @@ mod tests { cfg_exprs: [], }, Runnable { - range: 47..81, + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 47..81, + name: "test_foo", + kind: FN_DEF, + focus_range: Some( + 68..76, + ), + container_name: None, + description: None, + docs: None, + }, kind: Test { test_id: Path( "test_foo", @@ -280,12 +319,38 @@ mod tests { @r###" [ Runnable { - range: 1..21, + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 1..21, + name: "main", + kind: FN_DEF, + focus_range: Some( + 12..16, + ), + container_name: None, + description: None, + docs: None, + }, kind: Bin, cfg_exprs: [], }, Runnable { - range: 22..64, + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 22..64, + name: "foo", + kind: FN_DEF, + focus_range: Some( + 56..59, + ), + container_name: None, + description: None, + docs: None, + }, kind: DocTest { test_id: Path( "foo", @@ -320,12 +385,38 @@ mod tests { @r###" [ Runnable { - range: 1..21, + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 1..21, + name: "main", + kind: FN_DEF, + focus_range: Some( + 12..16, + ), + container_name: None, + description: None, + docs: None, + }, kind: Bin, cfg_exprs: [], }, Runnable { - range: 51..105, + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 51..105, + name: "foo", + kind: FN_DEF, + focus_range: Some( + 97..100, + ), + container_name: None, + description: None, + docs: None, + }, kind: DocTest { test_id: Path( "Data::foo", @@ -355,14 +446,40 @@ mod tests { @r###" [ Runnable { - range: 1..59, + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 1..59, + name: "test_mod", + kind: MODULE, + focus_range: Some( + 13..21, + ), + container_name: None, + description: None, + docs: None, + }, kind: TestMod { path: "test_mod", }, cfg_exprs: [], }, Runnable { - range: 28..57, + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 28..57, + name: "test_foo1", + kind: FN_DEF, + focus_range: Some( + 43..52, + ), + container_name: None, + description: None, + docs: None, + }, kind: Test { test_id: Path( "test_mod::test_foo1", @@ -397,14 +514,40 @@ mod tests { @r###" [ Runnable { - range: 23..85, + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 23..85, + name: "test_mod", + kind: MODULE, + focus_range: Some( + 27..35, + ), + container_name: None, + description: None, + docs: None, + }, kind: TestMod { path: "foo::test_mod", }, cfg_exprs: [], }, Runnable { - range: 46..79, + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 46..79, + name: "test_foo1", + kind: FN_DEF, + focus_range: Some( + 65..74, + ), + container_name: None, + description: None, + docs: None, + }, kind: Test { test_id: Path( "foo::test_mod::test_foo1", @@ -441,14 +584,40 @@ mod tests { @r###" [ Runnable { - range: 41..115, + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 41..115, + name: "test_mod", + kind: MODULE, + focus_range: Some( + 45..53, + ), + container_name: None, + description: None, + docs: None, + }, kind: TestMod { path: "foo::bar::test_mod", }, cfg_exprs: [], }, Runnable { - range: 68..105, + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 68..105, + name: "test_foo1", + kind: FN_DEF, + focus_range: Some( + 91..100, + ), + container_name: None, + description: None, + docs: None, + }, kind: Test { test_id: Path( "foo::bar::test_mod::test_foo1", @@ -480,7 +649,20 @@ mod tests { @r###" [ Runnable { - range: 1..58, + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 1..58, + name: "test_foo1", + kind: FN_DEF, + focus_range: Some( + 44..53, + ), + container_name: None, + description: None, + docs: None, + }, kind: Test { test_id: Path( "test_foo1", @@ -517,7 +699,20 @@ mod tests { @r###" [ Runnable { - range: 1..80, + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 1..80, + name: "test_foo1", + kind: FN_DEF, + focus_range: Some( + 66..75, + ), + container_name: None, + description: None, + docs: None, + }, kind: Test { test_id: Path( "test_foo1", diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index 5fa1eba1c..ec24ce5e0 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs @@ -139,6 +139,7 @@ pub enum RunnableKind { #[derive(Deserialize, Serialize, Debug)] #[serde(rename_all = "camelCase")] pub struct CargoRunnable { + #[serde(skip_serializing_if = "Option::is_none")] pub workspace_root: Option, // command, --package and --lib stuff pub cargo_args: Vec, diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs index 8b473ff74..e18f973b8 100644 --- a/crates/rust-analyzer/tests/heavy_tests/main.rs +++ b/crates/rust-analyzer/tests/heavy_tests/main.rs @@ -76,30 +76,33 @@ fn foo() { server.request::( RunnablesParams { text_document: server.doc_id("lib.rs"), position: None }, json!([ - { - "args": [ "test" ], - "extraArgs": [ "foo", "--nocapture" ], - "kind": "cargo", - "env": { "RUST_BACKTRACE": "short" }, - "cwd": null, - "label": "test foo", - "range": { - "end": { "character": 1, "line": 2 }, - "start": { "character": 0, "line": 0 } - } - }, - { - "args": ["check", "--workspace"], - "extraArgs": [], - "kind": "cargo", - "env": {}, - "cwd": null, - "label": "cargo check --workspace", - "range": { - "end": { "character": 0, "line": 0 }, - "start": { "character": 0, "line": 0 } + { + "args": { + "cargoArgs": ["test"], + "executableArgs": ["foo", "--nocapture"], + }, + "kind": "cargo", + "label": "test foo", + "location": { + "targetRange": { + "end": { "character": 1, "line": 2 }, + "start": { "character": 0, "line": 0 } + }, + "targetSelectionRange": { + "end": { "character": 6, "line": 1 }, + "start": { "character": 3, "line": 1 } + }, + "targetUri": "file:///[..]/lib.rs" + } + }, + { + "args": { + "cargoArgs": ["check", "--workspace"], + "executableArgs": [], + }, + "kind": "cargo", + "label": "cargo check --workspace" } - } ]), ); } @@ -138,42 +141,44 @@ fn main() {} server.request::( RunnablesParams { text_document: server.doc_id("foo/tests/spam.rs"), position: None }, json!([ - { - "args": [ "test", "--package", "foo", "--test", "spam" ], - "extraArgs": [ "test_eggs", "--exact", "--nocapture" ], - "kind": "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") + { + "args": { + "cargoArgs": ["test", "--package", "foo", "--test", "spam"], + "executableArgs": ["test_eggs", "--exact", "--nocapture"], + "workspaceRoot": server.path().join("foo") }, - { - "args": [ "check", "--package", "foo" ], - "extraArgs": [], - "kind": "cargo", - "env": {}, - "label": "cargo check -p foo", - "range": { - "end": { "character": 0, "line": 0 }, + "kind": "cargo", + "label": "test test_eggs", + "location": { + "targetRange": { + "end": { "character": 17, "line": 1 }, "start": { "character": 0, "line": 0 } }, - "cwd": server.path().join("foo") - }, - { - "args": [ "test", "--package", "foo" ], - "extraArgs": [], - "kind": "cargo", - "env": {}, - "label": "cargo test -p foo", - "range": { - "end": { "character": 0, "line": 0 }, - "start": { "character": 0, "line": 0 } + "targetSelectionRange": { + "end": { "character": 12, "line": 1 }, + "start": { "character": 3, "line": 1 } }, - "cwd": server.path().join("foo") + "targetUri": "file:///[..]/tests/spam.rs" } + }, + { + "args": { + "cargoArgs": ["check", "--package", "foo"], + "executableArgs": [], + "workspaceRoot": server.path().join("foo") + }, + "kind": "cargo", + "label": "cargo check -p foo" + }, + { + "args": { + "cargoArgs": ["test", "--package", "foo"], + "executableArgs": [], + "workspaceRoot": server.path().join("foo") + }, + "kind": "cargo", + "label": "cargo test -p foo" + } ]), ); } -- cgit v1.2.3