diff options
Diffstat (limited to 'crates/server/tests')
-rw-r--r-- | crates/server/tests/heavy_tests/main.rs | 33 | ||||
-rw-r--r-- | crates/server/tests/heavy_tests/support.rs | 45 |
2 files changed, 14 insertions, 64 deletions
diff --git a/crates/server/tests/heavy_tests/main.rs b/crates/server/tests/heavy_tests/main.rs index 78842e44f..d6e89bdf2 100644 --- a/crates/server/tests/heavy_tests/main.rs +++ b/crates/server/tests/heavy_tests/main.rs | |||
@@ -10,7 +10,7 @@ extern crate m; | |||
10 | 10 | ||
11 | mod support; | 11 | mod support; |
12 | 12 | ||
13 | use m::req::{Runnables, RunnablesParams, DidReloadWorkspace}; | 13 | use m::req::{Runnables, RunnablesParams}; |
14 | 14 | ||
15 | use support::project; | 15 | use support::project; |
16 | 16 | ||
@@ -59,7 +59,7 @@ pub fn foo() {} | |||
59 | #[test] | 59 | #[test] |
60 | fn test_eggs() {} | 60 | fn test_eggs() {} |
61 | "#); | 61 | "#); |
62 | server.wait_for_notification::<DidReloadWorkspace>(); | 62 | server.wait_for_feedback("workspace loaded"); |
63 | server.request::<Runnables>( | 63 | server.request::<Runnables>( |
64 | RunnablesParams { | 64 | RunnablesParams { |
65 | text_document: server.doc_id("tests/spam.rs"), | 65 | text_document: server.doc_id("tests/spam.rs"), |
@@ -79,32 +79,3 @@ fn test_eggs() {} | |||
79 | ]"# | 79 | ]"# |
80 | ); | 80 | ); |
81 | } | 81 | } |
82 | |||
83 | #[test] | ||
84 | fn test_project_model() { | ||
85 | let server = project(r#" | ||
86 | //- Cargo.toml | ||
87 | [package] | ||
88 | name = "foo" | ||
89 | version = "0.0.0" | ||
90 | |||
91 | //- src/lib.rs | ||
92 | pub fn foo() {} | ||
93 | "#); | ||
94 | server.notification::<DidReloadWorkspace>(r#"[ | ||
95 | { | ||
96 | "packages": [ | ||
97 | { | ||
98 | "is_member": true, | ||
99 | "manifest": "$PROJECT_ROOT$/Cargo.toml", | ||
100 | "name": "foo", | ||
101 | "targets": [ 0 ] | ||
102 | } | ||
103 | ], | ||
104 | "targets": [ | ||
105 | { "kind": "Lib", "name": "foo", "pkg": 0, "root": "$PROJECT_ROOT$/src/lib.rs" } | ||
106 | ] | ||
107 | } | ||
108 | ]"# | ||
109 | ); | ||
110 | } | ||
diff --git a/crates/server/tests/heavy_tests/support.rs b/crates/server/tests/heavy_tests/support.rs index 38a9e6c76..99a784e8d 100644 --- a/crates/server/tests/heavy_tests/support.rs +++ b/crates/server/tests/heavy_tests/support.rs | |||
@@ -14,7 +14,7 @@ use languageserver_types::{ | |||
14 | Url, | 14 | Url, |
15 | TextDocumentIdentifier, | 15 | TextDocumentIdentifier, |
16 | request::{Request, Shutdown}, | 16 | request::{Request, Shutdown}, |
17 | notification::{Notification, DidOpenTextDocument}, | 17 | notification::DidOpenTextDocument, |
18 | DidOpenTextDocumentParams, | 18 | DidOpenTextDocumentParams, |
19 | TextDocumentItem, | 19 | TextDocumentItem, |
20 | }; | 20 | }; |
@@ -22,7 +22,7 @@ use serde::Serialize; | |||
22 | use serde_json::{Value, from_str, to_string_pretty}; | 22 | use serde_json::{Value, from_str, to_string_pretty}; |
23 | use gen_lsp_server::{RawMessage, RawRequest, RawNotification}; | 23 | use gen_lsp_server::{RawMessage, RawRequest, RawNotification}; |
24 | 24 | ||
25 | use m::{Result, main_loop}; | 25 | use m::{Result, main_loop, req}; |
26 | 26 | ||
27 | pub fn project(fixture: &str) -> Server { | 27 | pub fn project(fixture: &str) -> Server { |
28 | static INIT: Once = Once::new(); | 28 | static INIT: Once = Once::new(); |
@@ -72,7 +72,7 @@ impl Server { | |||
72 | let path = dir.path().to_path_buf(); | 72 | let path = dir.path().to_path_buf(); |
73 | let (client_sender, mut server_receiver) = bounded(1); | 73 | let (client_sender, mut server_receiver) = bounded(1); |
74 | let (mut server_sender, client_receiver) = bounded(1); | 74 | let (mut server_sender, client_receiver) = bounded(1); |
75 | let server = thread::spawn(move || main_loop(path, &mut server_receiver, &mut server_sender)); | 75 | let server = thread::spawn(move || main_loop(true, path, &mut server_receiver, &mut server_sender)); |
76 | let res = Server { | 76 | let res = Server { |
77 | req_id: Cell::new(1), | 77 | req_id: Cell::new(1), |
78 | dir, | 78 | dir, |
@@ -125,25 +125,6 @@ impl Server { | |||
125 | ); | 125 | ); |
126 | } | 126 | } |
127 | 127 | ||
128 | pub fn notification<N>( | ||
129 | &self, | ||
130 | expected: &str, | ||
131 | ) | ||
132 | where | ||
133 | N: Notification, | ||
134 | { | ||
135 | let expected = expected.replace("$PROJECT_ROOT$", &self.dir.path().display().to_string()); | ||
136 | let expected: Value = from_str(&expected).unwrap(); | ||
137 | let actual = self.wait_for_notification::<N>(); | ||
138 | assert_eq!( | ||
139 | expected, actual, | ||
140 | "Expected:\n{}\n\ | ||
141 | Actual:\n{}\n", | ||
142 | to_string_pretty(&expected).unwrap(), | ||
143 | to_string_pretty(&actual).unwrap(), | ||
144 | ); | ||
145 | } | ||
146 | |||
147 | fn send_request<R>(&self, id: u64, params: R::Params) -> Value | 128 | fn send_request<R>(&self, id: u64, params: R::Params) -> Value |
148 | where | 129 | where |
149 | R: Request, | 130 | R: Request, |
@@ -173,25 +154,23 @@ impl Server { | |||
173 | } | 154 | } |
174 | panic!("no response"); | 155 | panic!("no response"); |
175 | } | 156 | } |
176 | pub fn wait_for_notification<N: Notification>(&self) -> Value { | 157 | pub fn wait_for_feedback(&self, feedback: &str) { |
177 | self.wait_for_notification_(N::METHOD) | ||
178 | } | ||
179 | fn wait_for_notification_(&self, method: &str) -> Value { | ||
180 | let f = |msg: &RawMessage| match msg { | 158 | let f = |msg: &RawMessage| match msg { |
181 | RawMessage::Notification(n) if n.method == method => { | 159 | RawMessage::Notification(n) if n.method == "internalFeedback" => { |
182 | Some(n.params.clone()) | 160 | return n.clone().cast::<req::InternalFeedback>() |
161 | .unwrap() == feedback | ||
183 | } | 162 | } |
184 | _ => None, | 163 | _ => false, |
185 | }; | 164 | }; |
186 | 165 | ||
187 | for msg in self.messages.borrow().iter() { | 166 | for msg in self.messages.borrow().iter() { |
188 | if let Some(res) = f(msg) { | 167 | if f(msg) { |
189 | return res; | 168 | return; |
190 | } | 169 | } |
191 | } | 170 | } |
192 | while let Some(msg) = self.recv() { | 171 | while let Some(msg) = self.recv() { |
193 | if let Some(res) = f(&msg) { | 172 | if f(&msg) { |
194 | return res; | 173 | return; |
195 | } | 174 | } |
196 | } | 175 | } |
197 | panic!("no response") | 176 | panic!("no response") |