Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit fd8d701

Browse files
authored
Merge pull request #666 from Xanewok/int-tests-void-params
Properly handle void params in integration test harness
2 parents 55da9f9 + 7adf369 commit fd8d701

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

tests/support/mod.rs

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -168,33 +168,52 @@ impl RlsHandle {
168168
pub fn send(&mut self, j: serde_json::Value) -> io::Result<usize> {
169169
self.send_string(&j.to_string())
170170
}
171-
pub fn notify(&mut self, method: &str, params: serde_json::Value) -> io::Result<usize> {
172-
self.send(json!({
173-
"jsonrpc": "2.0",
174-
"method": method,
175-
"params": params,
176-
}))
171+
pub fn notify(&mut self, method: &str, params: Option<serde_json::Value>) -> io::Result<usize> {
172+
let message = if let Some(params) = params {
173+
json!({
174+
"jsonrpc": "2.0",
175+
"method": method,
176+
"params": params,
177+
})
178+
} else {
179+
json!({
180+
"jsonrpc": "2.0",
181+
"method": method,
182+
})
183+
};
184+
185+
self.send(message)
177186
}
178-
pub fn request(&mut self, id: u64, method: &str, params: serde_json::Value) -> io::Result<usize> {
179-
self.send(json!({
180-
"jsonrpc": "2.0",
181-
"id": id,
182-
"method": method,
183-
"params": params,
184-
}))
187+
pub fn request(&mut self, id: u64, method: &str, params: Option<serde_json::Value>) -> io::Result<usize> {
188+
let message = if let Some(params) = params {
189+
json!({
190+
"jsonrpc": "2.0",
191+
"id": id,
192+
"method": method,
193+
"params": params,
194+
})
195+
} else {
196+
json!({
197+
"jsonrpc": "2.0",
198+
"id": id,
199+
"method": method,
200+
})
201+
};
202+
203+
self.send(message)
185204
}
186205
pub fn shutdown_exit(&mut self) {
187-
self.request(99999, "shutdown", json!({})).unwrap();
206+
self.request(99999, "shutdown", None).unwrap();
188207

189208
self.expect_messages(&[
190209
&ExpectedMessage::new(Some(99999)),
191210
]);
192211

193-
self.notify("exit", json!({})).unwrap();
212+
self.notify("exit", None).unwrap();
194213

195214
let ecode = self.child.wait()
196215
.expect("failed to wait on child rls process");
197-
216+
198217
assert!(ecode.success());
199218
}
200219

tests/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ fn test_infer_bin() {
3737
let rls_child = p.rls().spawn().unwrap();
3838
let mut rls = RlsHandle::new(rls_child);
3939

40-
rls.request(0, "initialize", json!({
40+
rls.request(0, "initialize", Some(json!({
4141
"rootPath": root_path,
4242
"capabilities": {}
43-
})).unwrap();
43+
}))).unwrap();
4444

4545
rls.expect_messages(&[
4646
ExpectedMessage::new(Some(0)).expect_contains("capabilities"),
@@ -119,10 +119,10 @@ fn test_simple_workspace() {
119119
let rls_child = p.rls().spawn().unwrap();
120120
let mut rls = RlsHandle::new(rls_child);
121121

122-
rls.request(0, "initialize", json!({
122+
rls.request(0, "initialize", Some(json!({
123123
"rootPath": root_path,
124124
"capabilities": {}
125-
})).unwrap();
125+
}))).unwrap();
126126

127127
// This is the expected behavior is workspace_mode is on by default
128128
rls.expect_messages(&[

0 commit comments

Comments
 (0)