aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/tests
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-10-16 14:44:24 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-10-16 14:44:24 +0100
commit1216878f7be20dd0e652fb8cdc395009fdcfae07 (patch)
tree6551967cc8c6e921b66071453ad7888a9121d326 /crates/ra_lsp_server/tests
parent39cb6c6d3f78b193f5873c3492e530bbd24d5dd2 (diff)
parent61f3a438d3a729a6be941bca1ff4c6a97a33f221 (diff)
Merge #134
134: Cargo Format run r=kjeremy a=kjeremy I'm not sure how appreciated this is but I figured I would run `cargo fmt` and see what came up. I made sure that `cargo test` still passes. Co-authored-by: Jeremy A. Kolb <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/tests')
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/main.rs23
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/support.rs78
2 files changed, 46 insertions, 55 deletions
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs
index 7265b5999..8e566d3c8 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/main.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs
@@ -1,12 +1,12 @@
1#[macro_use] 1#[macro_use]
2extern crate crossbeam_channel; 2extern crate crossbeam_channel;
3extern crate tempdir; 3extern crate flexi_logger;
4extern crate gen_lsp_server;
4extern crate languageserver_types; 5extern crate languageserver_types;
6extern crate ra_lsp_server;
5extern crate serde; 7extern crate serde;
6extern crate serde_json; 8extern crate serde_json;
7extern crate gen_lsp_server; 9extern crate tempdir;
8extern crate flexi_logger;
9extern crate ra_lsp_server;
10 10
11mod support; 11mod support;
12 12
@@ -14,17 +14,18 @@ use ra_lsp_server::req::{Runnables, RunnablesParams};
14 14
15use crate::support::project; 15use crate::support::project;
16 16
17
18const LOG: &'static str = ""; 17const LOG: &'static str = "";
19 18
20#[test] 19#[test]
21fn test_runnables_no_project() { 20fn test_runnables_no_project() {
22 let server = project(r" 21 let server = project(
22 r"
23//- lib.rs 23//- lib.rs
24#[test] 24#[test]
25fn foo() { 25fn foo() {
26} 26}
27"); 27",
28 );
28 server.request::<Runnables>( 29 server.request::<Runnables>(
29 RunnablesParams { 30 RunnablesParams {
30 text_document: server.doc_id("lib.rs"), 31 text_document: server.doc_id("lib.rs"),
@@ -41,13 +42,14 @@ fn foo() {
41 "start": { "character": 0, "line": 0 } 42 "start": { "character": 0, "line": 0 }
42 } 43 }
43 } 44 }
44 ]"# 45 ]"#,
45 ); 46 );
46} 47}
47 48
48#[test] 49#[test]
49fn test_runnables_project() { 50fn test_runnables_project() {
50 let server = project(r#" 51 let server = project(
52 r#"
51//- Cargo.toml 53//- Cargo.toml
52[package] 54[package]
53name = "foo" 55name = "foo"
@@ -59,7 +61,8 @@ pub fn foo() {}
59//- tests/spam.rs 61//- tests/spam.rs
60#[test] 62#[test]
61fn test_eggs() {} 63fn test_eggs() {}
62"#); 64"#,
65 );
63 server.wait_for_feedback("workspace loaded"); 66 server.wait_for_feedback("workspace loaded");
64 server.request::<Runnables>( 67 server.request::<Runnables>(
65 RunnablesParams { 68 RunnablesParams {
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs
index d1339f62f..004d7e8ad 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/support.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs
@@ -1,34 +1,33 @@
1use std::{ 1use std::{
2 fs,
3 cell::{Cell, RefCell}, 2 cell::{Cell, RefCell},
3 fs,
4 path::PathBuf, 4 path::PathBuf,
5 time::Duration,
6 sync::Once, 5 sync::Once,
6 time::Duration,
7}; 7};
8 8
9use tempdir::TempDir;
10use crossbeam_channel::{after, Receiver}; 9use crossbeam_channel::{after, Receiver};
11use flexi_logger::Logger; 10use flexi_logger::Logger;
11use gen_lsp_server::{RawMessage, RawNotification, RawRequest};
12use languageserver_types::{ 12use languageserver_types::{
13 Url,
14 TextDocumentIdentifier,
15 request::{Request, Shutdown},
16 notification::DidOpenTextDocument, 13 notification::DidOpenTextDocument,
17 DidOpenTextDocumentParams, 14 request::{Request, Shutdown},
18 TextDocumentItem, 15 DidOpenTextDocumentParams, TextDocumentIdentifier, TextDocumentItem, Url,
19}; 16};
20use serde::Serialize; 17use serde::Serialize;
21use serde_json::{Value, from_str, to_string_pretty}; 18use serde_json::{from_str, to_string_pretty, Value};
22use gen_lsp_server::{RawMessage, RawRequest, RawNotification}; 19use tempdir::TempDir;
23 20
24use ra_lsp_server::{main_loop, req, thread_watcher::{ThreadWatcher, Worker}}; 21use ra_lsp_server::{
22 main_loop, req,
23 thread_watcher::{ThreadWatcher, Worker},
24};
25 25
26pub fn project(fixture: &str) -> Server { 26pub fn project(fixture: &str) -> Server {
27 static INIT: Once = Once::new(); 27 static INIT: Once = Once::new();
28 INIT.call_once(|| Logger::with_env_or_str(crate::LOG).start().unwrap()); 28 INIT.call_once(|| Logger::with_env_or_str(crate::LOG).start().unwrap());
29 29
30 let tmp_dir = TempDir::new("test-project") 30 let tmp_dir = TempDir::new("test-project").unwrap();
31 .unwrap();
32 let mut buf = String::new(); 31 let mut buf = String::new();
33 let mut file_name = None; 32 let mut file_name = None;
34 let mut paths = vec![]; 33 let mut paths = vec![];
@@ -40,7 +39,7 @@ pub fn project(fixture: &str) -> Server {
40 fs::write(path.as_path(), buf.as_bytes()).unwrap(); 39 fs::write(path.as_path(), buf.as_bytes()).unwrap();
41 paths.push((path, buf.clone())); 40 paths.push((path, buf.clone()));
42 } 41 }
43 } 42 };
44 }; 43 };
45 for line in fixture.lines() { 44 for line in fixture.lines() {
46 if line.starts_with("//-") { 45 if line.starts_with("//-") {
@@ -71,9 +70,8 @@ impl Server {
71 "test server", 70 "test server",
72 128, 71 128,
73 move |mut msg_receiver, mut msg_sender| { 72 move |mut msg_receiver, mut msg_sender| {
74 main_loop(true, path, &mut msg_receiver, &mut msg_sender) 73 main_loop(true, path, &mut msg_receiver, &mut msg_sender).unwrap()
75 .unwrap() 74 },
76 }
77 ); 75 );
78 let res = Server { 76 let res = Server {
79 req_id: Cell::new(1), 77 req_id: Cell::new(1),
@@ -91,8 +89,8 @@ impl Server {
91 language_id: "rust".to_string(), 89 language_id: "rust".to_string(),
92 version: 0, 90 version: 0,
93 text, 91 text,
94 } 92 },
95 } 93 },
96 )) 94 ))
97 } 95 }
98 res 96 res
@@ -105,11 +103,7 @@ impl Server {
105 } 103 }
106 } 104 }
107 105
108 pub fn request<R>( 106 pub fn request<R>(&self, params: R::Params, expected_resp: &str)
109 &self,
110 params: R::Params,
111 expected_resp: &str,
112 )
113 where 107 where
114 R: Request, 108 R: Request,
115 R::Params: Serialize, 109 R::Params: Serialize,
@@ -119,7 +113,8 @@ impl Server {
119 let expected_resp: Value = from_str(expected_resp).unwrap(); 113 let expected_resp: Value = from_str(expected_resp).unwrap();
120 let actual = self.send_request::<R>(id, params); 114 let actual = self.send_request::<R>(id, params);
121 assert_eq!( 115 assert_eq!(
122 expected_resp, actual, 116 expected_resp,
117 actual,
123 "Expected:\n{}\n\ 118 "Expected:\n{}\n\
124 Actual:\n{}\n", 119 Actual:\n{}\n",
125 to_string_pretty(&expected_resp).unwrap(), 120 to_string_pretty(&expected_resp).unwrap(),
@@ -135,12 +130,9 @@ impl Server {
135 let r = RawRequest::new::<R>(id, &params); 130 let r = RawRequest::new::<R>(id, &params);
136 self.send_request_(r) 131 self.send_request_(r)
137 } 132 }
138 fn send_request_(&self, r: RawRequest) -> Value 133 fn send_request_(&self, r: RawRequest) -> Value {
139 {
140 let id = r.id; 134 let id = r.id;
141 self.worker.as_ref() 135 self.worker.as_ref().unwrap().send(RawMessage::Request(r));
142 .unwrap()
143 .send(RawMessage::Request(r));
144 while let Some(msg) = self.recv() { 136 while let Some(msg) = self.recv() {
145 match msg { 137 match msg {
146 RawMessage::Request(req) => panic!("unexpected request: {:?}", req), 138 RawMessage::Request(req) => panic!("unexpected request: {:?}", req),
@@ -161,11 +153,10 @@ impl Server {
161 } 153 }
162 pub fn wait_for_feedback_n(&self, feedback: &str, n: usize) { 154 pub fn wait_for_feedback_n(&self, feedback: &str, n: usize) {
163 let f = |msg: &RawMessage| match msg { 155 let f = |msg: &RawMessage| match msg {
164 RawMessage::Notification(n) if n.method == "internalFeedback" => { 156 RawMessage::Notification(n) if n.method == "internalFeedback" => {
165 return n.clone().cast::<req::InternalFeedback>() 157 return n.clone().cast::<req::InternalFeedback>().unwrap() == feedback
166 .unwrap() == feedback 158 }
167 } 159 _ => false,
168 _ => false,
169 }; 160 };
170 let mut total = 0; 161 let mut total = 0;
171 for msg in self.messages.borrow().iter() { 162 for msg in self.messages.borrow().iter() {
@@ -181,14 +172,14 @@ impl Server {
181 } 172 }
182 } 173 }
183 fn recv(&self) -> Option<RawMessage> { 174 fn recv(&self) -> Option<RawMessage> {
184 recv_timeout(&self.worker.as_ref().unwrap().out) 175 recv_timeout(&self.worker.as_ref().unwrap().out).map(|msg| {
185 .map(|msg| { 176 self.messages.borrow_mut().push(msg.clone());
186 self.messages.borrow_mut().push(msg.clone()); 177 msg
187 msg 178 })
188 })
189 } 179 }
190 fn send_notification(&self, not: RawNotification) { 180 fn send_notification(&self, not: RawNotification) {
191 self.worker.as_ref() 181 self.worker
182 .as_ref()
192 .unwrap() 183 .unwrap()
193 .send(RawMessage::Notification(not)); 184 .send(RawMessage::Notification(not));
194 } 185 }
@@ -201,10 +192,7 @@ impl Drop for Server {
201 while let Some(msg) = recv_timeout(&receiver) { 192 while let Some(msg) = recv_timeout(&receiver) {
202 drop(msg); 193 drop(msg);
203 } 194 }
204 self.watcher.take() 195 self.watcher.take().unwrap().stop().unwrap();
205 .unwrap()
206 .stop()
207 .unwrap();
208 } 196 }
209} 197}
210 198