mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-04 12:44:40 +00:00
Modifies runnables test to use multi-workspace root
This commit is contained in:
parent
7c7cfc5f04
commit
c2dfc8a229
@ -14,7 +14,7 @@ use ra_lsp_server::req::{
|
||||
use serde_json::json;
|
||||
use tempfile::TempDir;
|
||||
|
||||
use crate::support::{project, project_with_tmpdir};
|
||||
use crate::support::{project, Project};
|
||||
|
||||
const LOG: &'static str = "";
|
||||
|
||||
@ -95,25 +95,34 @@ fn foo() {
|
||||
|
||||
#[test]
|
||||
fn test_runnables_project() {
|
||||
let server = project(
|
||||
r#"
|
||||
//- Cargo.toml
|
||||
let code = r#"
|
||||
//- foo/Cargo.toml
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.0.0"
|
||||
|
||||
//- src/lib.rs
|
||||
//- foo/src/lib.rs
|
||||
pub fn foo() {}
|
||||
|
||||
//- tests/spam.rs
|
||||
//- foo/tests/spam.rs
|
||||
#[test]
|
||||
fn test_eggs() {}
|
||||
"#,
|
||||
);
|
||||
|
||||
//- bar/Cargo.toml
|
||||
[package]
|
||||
name = "bar"
|
||||
version = "0.0.0"
|
||||
|
||||
//- bar/src/main.rs
|
||||
fn main() {}
|
||||
"#;
|
||||
|
||||
let server = Project::with_fixture(code).root("foo").root("bar").server();
|
||||
|
||||
server.wait_until_workspace_is_loaded();
|
||||
server.request::<Runnables>(
|
||||
RunnablesParams {
|
||||
text_document: server.doc_id("tests/spam.rs"),
|
||||
text_document: server.doc_id("foo/tests/spam.rs"),
|
||||
position: None,
|
||||
},
|
||||
json!([
|
||||
@ -126,7 +135,7 @@ fn test_eggs() {}
|
||||
"end": { "character": 17, "line": 1 },
|
||||
"start": { "character": 0, "line": 0 }
|
||||
},
|
||||
"cwd": server.path()
|
||||
"cwd": server.path().join("foo")
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
@ -138,7 +147,7 @@ fn test_eggs() {}
|
||||
],
|
||||
"bin": "cargo",
|
||||
"env": {},
|
||||
"cwd": server.path(),
|
||||
"cwd": server.path().join("foo"),
|
||||
"label": "cargo check -p foo",
|
||||
"range": {
|
||||
"end": {
|
||||
@ -287,7 +296,9 @@ fn main() {{}}
|
||||
"#,
|
||||
PROJECT = project.to_string(),
|
||||
);
|
||||
let server = project_with_tmpdir(tmp_dir, &code);
|
||||
|
||||
let server = Project::with_fixture(&code).tmp_dir(tmp_dir).server();
|
||||
|
||||
server.wait_until_workspace_is_loaded();
|
||||
let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None };
|
||||
server.request::<CodeActionRequest>(
|
||||
|
@ -26,12 +26,29 @@ use ra_lsp_server::{
|
||||
InitializationOptions,
|
||||
};
|
||||
|
||||
pub fn project(fixture: &str) -> Server {
|
||||
let tmp_dir = TempDir::new().unwrap();
|
||||
project_with_tmpdir(tmp_dir, fixture)
|
||||
pub struct Project<'a> {
|
||||
fixture: &'a str,
|
||||
tmp_dir: Option<TempDir>,
|
||||
roots: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
pub fn project_with_tmpdir(tmp_dir: TempDir, fixture: &str) -> Server {
|
||||
impl<'a> Project<'a> {
|
||||
pub fn with_fixture(fixture: &str) -> Project {
|
||||
Project { fixture, tmp_dir: None, roots: vec![] }
|
||||
}
|
||||
|
||||
pub fn tmp_dir(mut self, tmp_dir: TempDir) -> Project<'a> {
|
||||
self.tmp_dir = Some(tmp_dir);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn root(mut self, path: &str) -> Project<'a> {
|
||||
self.roots.push(path.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn server(self) -> Server {
|
||||
let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap());
|
||||
static INIT: Once = Once::new();
|
||||
INIT.call_once(|| {
|
||||
let _ = Logger::with_env_or_str(crate::LOG).start().unwrap();
|
||||
@ -39,13 +56,21 @@ pub fn project_with_tmpdir(tmp_dir: TempDir, fixture: &str) -> Server {
|
||||
|
||||
let mut paths = vec![];
|
||||
|
||||
for entry in parse_fixture(fixture) {
|
||||
for entry in parse_fixture(self.fixture) {
|
||||
let path = tmp_dir.path().join(entry.meta);
|
||||
fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
fs::write(path.as_path(), entry.text.as_bytes()).unwrap();
|
||||
paths.push((path, entry.text));
|
||||
}
|
||||
Server::new(tmp_dir, paths)
|
||||
|
||||
let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect();
|
||||
|
||||
Server::new(tmp_dir, roots, paths)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn project(fixture: &str) -> Server {
|
||||
Project::with_fixture(fixture).server()
|
||||
}
|
||||
|
||||
pub struct Server {
|
||||
@ -56,14 +81,17 @@ pub struct Server {
|
||||
}
|
||||
|
||||
impl Server {
|
||||
fn new(dir: TempDir, files: Vec<(PathBuf, String)>) -> Server {
|
||||
fn new(dir: TempDir, roots: Vec<PathBuf>, files: Vec<(PathBuf, String)>) -> Server {
|
||||
let path = dir.path().to_path_buf();
|
||||
|
||||
let roots = if roots.is_empty() { vec![path] } else { roots };
|
||||
|
||||
let worker = Worker::<RawMessage, RawMessage>::spawn(
|
||||
"test server",
|
||||
128,
|
||||
move |mut msg_receiver, mut msg_sender| {
|
||||
main_loop(
|
||||
vec![path],
|
||||
roots,
|
||||
InitializationOptions::default(),
|
||||
&mut msg_receiver,
|
||||
&mut msg_sender,
|
||||
|
Loading…
Reference in New Issue
Block a user