mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +00:00
Fix tests, apply code review proposals
This commit is contained in:
parent
030d78345f
commit
a419cedb1c
5 changed files with 22 additions and 14 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1119,6 +1119,7 @@ dependencies = [
|
||||||
"memmap",
|
"memmap",
|
||||||
"ra_mbe",
|
"ra_mbe",
|
||||||
"ra_proc_macro",
|
"ra_proc_macro",
|
||||||
|
"ra_toolchain",
|
||||||
"ra_tt",
|
"ra_tt",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"test_utils",
|
"test_utils",
|
||||||
|
|
|
@ -22,3 +22,4 @@ cargo_metadata = "0.10.0"
|
||||||
difference = "2.0.0"
|
difference = "2.0.0"
|
||||||
# used as proc macro test target
|
# used as proc macro test target
|
||||||
serde_derive = "1.0.106"
|
serde_derive = "1.0.106"
|
||||||
|
ra_toolchain = { path = "../ra_toolchain" }
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
use crate::dylib;
|
use crate::dylib;
|
||||||
use crate::ProcMacroSrv;
|
use crate::ProcMacroSrv;
|
||||||
pub use difference::Changeset as __Changeset;
|
|
||||||
use ra_proc_macro::ListMacrosTask;
|
use ra_proc_macro::ListMacrosTask;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use test_utils::assert_eq_text;
|
use test_utils::assert_eq_text;
|
||||||
|
@ -13,7 +12,7 @@ mod fixtures {
|
||||||
|
|
||||||
// Use current project metadata to get the proc-macro dylib path
|
// Use current project metadata to get the proc-macro dylib path
|
||||||
pub fn dylib_path(crate_name: &str, version: &str) -> std::path::PathBuf {
|
pub fn dylib_path(crate_name: &str, version: &str) -> std::path::PathBuf {
|
||||||
let command = Command::new("cargo")
|
let command = Command::new(ra_toolchain::cargo())
|
||||||
.args(&["check", "--message-format", "json"])
|
.args(&["check", "--message-format", "json"])
|
||||||
.output()
|
.output()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -427,7 +427,7 @@ pub fn handle_runnables(
|
||||||
res.push(lsp_ext::Runnable {
|
res.push(lsp_ext::Runnable {
|
||||||
range: Default::default(),
|
range: Default::default(),
|
||||||
label: format!("cargo {} -p {}", cmd, spec.package),
|
label: format!("cargo {} -p {}", cmd, spec.package),
|
||||||
bin: "cargo".to_string(),
|
bin: cargo_path()?,
|
||||||
args: vec![cmd.to_string(), "--package".to_string(), spec.package.clone()],
|
args: vec![cmd.to_string(), "--package".to_string(), spec.package.clone()],
|
||||||
extra_args: Vec::new(),
|
extra_args: Vec::new(),
|
||||||
env: FxHashMap::default(),
|
env: FxHashMap::default(),
|
||||||
|
@ -439,7 +439,7 @@ pub fn handle_runnables(
|
||||||
res.push(lsp_ext::Runnable {
|
res.push(lsp_ext::Runnable {
|
||||||
range: Default::default(),
|
range: Default::default(),
|
||||||
label: "cargo check --workspace".to_string(),
|
label: "cargo check --workspace".to_string(),
|
||||||
bin: "cargo".to_string(),
|
bin: cargo_path()?,
|
||||||
args: vec!["check".to_string(), "--workspace".to_string()],
|
args: vec!["check".to_string(), "--workspace".to_string()],
|
||||||
extra_args: Vec::new(),
|
extra_args: Vec::new(),
|
||||||
env: FxHashMap::default(),
|
env: FxHashMap::default(),
|
||||||
|
@ -450,6 +450,13 @@ pub fn handle_runnables(
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cargo_path() -> Result<String> {
|
||||||
|
Ok(ra_toolchain::cargo()
|
||||||
|
.to_str()
|
||||||
|
.context("Path to `cargo` executable contains invalid UTF8 characters")?
|
||||||
|
.to_owned())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn handle_completion(
|
pub fn handle_completion(
|
||||||
world: WorldSnapshot,
|
world: WorldSnapshot,
|
||||||
params: lsp_types::CompletionParams,
|
params: lsp_types::CompletionParams,
|
||||||
|
@ -983,15 +990,11 @@ fn to_lsp_runnable(
|
||||||
target.map_or_else(|| "run binary".to_string(), |t| format!("run {}", t))
|
target.map_or_else(|| "run binary".to_string(), |t| format!("run {}", t))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let cargo_path = ra_toolchain::cargo()
|
|
||||||
.to_str()
|
|
||||||
.context("Path to cargo executable contains invalid UTF8 characters")?
|
|
||||||
.to_owned();
|
|
||||||
|
|
||||||
Ok(lsp_ext::Runnable {
|
Ok(lsp_ext::Runnable {
|
||||||
range: to_proto::range(&line_index, runnable.range),
|
range: to_proto::range(&line_index, runnable.range),
|
||||||
label,
|
label,
|
||||||
bin: cargo_path,
|
bin: cargo_path()?,
|
||||||
args,
|
args,
|
||||||
extra_args,
|
extra_args,
|
||||||
env: {
|
env: {
|
||||||
|
|
|
@ -58,6 +58,10 @@ use std::collections::Spam;
|
||||||
eprintln!("completion took {:?}", completion_start.elapsed());
|
eprintln!("completion took {:?}", completion_start.elapsed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cargo_path() -> String {
|
||||||
|
ra_toolchain::cargo().to_str().unwrap().to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_runnables_no_project() {
|
fn test_runnables_no_project() {
|
||||||
if skip_slow_tests() {
|
if skip_slow_tests() {
|
||||||
|
@ -79,7 +83,7 @@ fn foo() {
|
||||||
{
|
{
|
||||||
"args": [ "test" ],
|
"args": [ "test" ],
|
||||||
"extraArgs": [ "foo", "--nocapture" ],
|
"extraArgs": [ "foo", "--nocapture" ],
|
||||||
"bin": "cargo",
|
"bin": cargo_path(),
|
||||||
"env": { "RUST_BACKTRACE": "short" },
|
"env": { "RUST_BACKTRACE": "short" },
|
||||||
"cwd": null,
|
"cwd": null,
|
||||||
"label": "test foo",
|
"label": "test foo",
|
||||||
|
@ -91,7 +95,7 @@ fn foo() {
|
||||||
{
|
{
|
||||||
"args": ["check", "--workspace"],
|
"args": ["check", "--workspace"],
|
||||||
"extraArgs": [],
|
"extraArgs": [],
|
||||||
"bin": "cargo",
|
"bin": cargo_path(),
|
||||||
"env": {},
|
"env": {},
|
||||||
"cwd": null,
|
"cwd": null,
|
||||||
"label": "cargo check --workspace",
|
"label": "cargo check --workspace",
|
||||||
|
@ -141,7 +145,7 @@ fn main() {}
|
||||||
{
|
{
|
||||||
"args": [ "test", "--package", "foo", "--test", "spam" ],
|
"args": [ "test", "--package", "foo", "--test", "spam" ],
|
||||||
"extraArgs": [ "test_eggs", "--exact", "--nocapture" ],
|
"extraArgs": [ "test_eggs", "--exact", "--nocapture" ],
|
||||||
"bin": "cargo",
|
"bin": cargo_path(),
|
||||||
"env": { "RUST_BACKTRACE": "short" },
|
"env": { "RUST_BACKTRACE": "short" },
|
||||||
"label": "test test_eggs",
|
"label": "test test_eggs",
|
||||||
"range": {
|
"range": {
|
||||||
|
@ -153,7 +157,7 @@ fn main() {}
|
||||||
{
|
{
|
||||||
"args": [ "check", "--package", "foo" ],
|
"args": [ "check", "--package", "foo" ],
|
||||||
"extraArgs": [],
|
"extraArgs": [],
|
||||||
"bin": "cargo",
|
"bin": cargo_path(),
|
||||||
"env": {},
|
"env": {},
|
||||||
"label": "cargo check -p foo",
|
"label": "cargo check -p foo",
|
||||||
"range": {
|
"range": {
|
||||||
|
@ -165,7 +169,7 @@ fn main() {}
|
||||||
{
|
{
|
||||||
"args": [ "test", "--package", "foo" ],
|
"args": [ "test", "--package", "foo" ],
|
||||||
"extraArgs": [],
|
"extraArgs": [],
|
||||||
"bin": "cargo",
|
"bin": cargo_path(),
|
||||||
"env": {},
|
"env": {},
|
||||||
"label": "cargo test -p foo",
|
"label": "cargo test -p foo",
|
||||||
"range": {
|
"range": {
|
||||||
|
|
Loading…
Reference in a new issue