Skip to content

Commit a419ced

Browse files
committed
Fix tests, apply code review proposals
1 parent 030d783 commit a419ced

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_proc_macro_srv/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ cargo_metadata = "0.10.0"
2222
difference = "2.0.0"
2323
# used as proc macro test target
2424
serde_derive = "1.0.106"
25+
ra_toolchain = { path = "../ra_toolchain" }

crates/ra_proc_macro_srv/src/tests/utils.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::dylib;
44
use crate::ProcMacroSrv;
5-
pub use difference::Changeset as __Changeset;
65
use ra_proc_macro::ListMacrosTask;
76
use std::str::FromStr;
87
use test_utils::assert_eq_text;
@@ -13,7 +12,7 @@ mod fixtures {
1312

1413
// Use current project metadata to get the proc-macro dylib path
1514
pub fn dylib_path(crate_name: &str, version: &str) -> std::path::PathBuf {
16-
let command = Command::new("cargo")
15+
let command = Command::new(ra_toolchain::cargo())
1716
.args(&["check", "--message-format", "json"])
1817
.output()
1918
.unwrap()

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ pub fn handle_runnables(
427427
res.push(lsp_ext::Runnable {
428428
range: Default::default(),
429429
label: format!("cargo {} -p {}", cmd, spec.package),
430-
bin: "cargo".to_string(),
430+
bin: cargo_path()?,
431431
args: vec![cmd.to_string(), "--package".to_string(), spec.package.clone()],
432432
extra_args: Vec::new(),
433433
env: FxHashMap::default(),
@@ -439,7 +439,7 @@ pub fn handle_runnables(
439439
res.push(lsp_ext::Runnable {
440440
range: Default::default(),
441441
label: "cargo check --workspace".to_string(),
442-
bin: "cargo".to_string(),
442+
bin: cargo_path()?,
443443
args: vec!["check".to_string(), "--workspace".to_string()],
444444
extra_args: Vec::new(),
445445
env: FxHashMap::default(),
@@ -450,6 +450,13 @@ pub fn handle_runnables(
450450
Ok(res)
451451
}
452452

453+
fn cargo_path() -> Result<String> {
454+
Ok(ra_toolchain::cargo()
455+
.to_str()
456+
.context("Path to `cargo` executable contains invalid UTF8 characters")?
457+
.to_owned())
458+
}
459+
453460
pub fn handle_completion(
454461
world: WorldSnapshot,
455462
params: lsp_types::CompletionParams,
@@ -983,15 +990,11 @@ fn to_lsp_runnable(
983990
target.map_or_else(|| "run binary".to_string(), |t| format!("run {}", t))
984991
}
985992
};
986-
let cargo_path = ra_toolchain::cargo()
987-
.to_str()
988-
.context("Path to cargo executable contains invalid UTF8 characters")?
989-
.to_owned();
990993

991994
Ok(lsp_ext::Runnable {
992995
range: to_proto::range(&line_index, runnable.range),
993996
label,
994-
bin: cargo_path,
997+
bin: cargo_path()?,
995998
args,
996999
extra_args,
9971000
env: {

crates/rust-analyzer/tests/heavy_tests/main.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ use std::collections::Spam;
5858
eprintln!("completion took {:?}", completion_start.elapsed());
5959
}
6060

61+
fn cargo_path() -> String {
62+
ra_toolchain::cargo().to_str().unwrap().to_owned()
63+
}
64+
6165
#[test]
6266
fn test_runnables_no_project() {
6367
if skip_slow_tests() {
@@ -79,7 +83,7 @@ fn foo() {
7983
{
8084
"args": [ "test" ],
8185
"extraArgs": [ "foo", "--nocapture" ],
82-
"bin": "cargo",
86+
"bin": cargo_path(),
8387
"env": { "RUST_BACKTRACE": "short" },
8488
"cwd": null,
8589
"label": "test foo",
@@ -91,7 +95,7 @@ fn foo() {
9195
{
9296
"args": ["check", "--workspace"],
9397
"extraArgs": [],
94-
"bin": "cargo",
98+
"bin": cargo_path(),
9599
"env": {},
96100
"cwd": null,
97101
"label": "cargo check --workspace",
@@ -141,7 +145,7 @@ fn main() {}
141145
{
142146
"args": [ "test", "--package", "foo", "--test", "spam" ],
143147
"extraArgs": [ "test_eggs", "--exact", "--nocapture" ],
144-
"bin": "cargo",
148+
"bin": cargo_path(),
145149
"env": { "RUST_BACKTRACE": "short" },
146150
"label": "test test_eggs",
147151
"range": {
@@ -153,7 +157,7 @@ fn main() {}
153157
{
154158
"args": [ "check", "--package", "foo" ],
155159
"extraArgs": [],
156-
"bin": "cargo",
160+
"bin": cargo_path(),
157161
"env": {},
158162
"label": "cargo check -p foo",
159163
"range": {
@@ -165,7 +169,7 @@ fn main() {}
165169
{
166170
"args": [ "test", "--package", "foo" ],
167171
"extraArgs": [],
168-
"bin": "cargo",
172+
"bin": cargo_path(),
169173
"env": {},
170174
"label": "cargo test -p foo",
171175
"range": {

0 commit comments

Comments
 (0)