From 7adf369a0b4ad985f14cccff667c30fb8d0748b6 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Wed, 17 Jan 2018 15:17:24 +0100 Subject: [PATCH] Properly handle void params in integration test harness --- tests/support/mod.rs | 51 ++++++++++++++++++++++++++++++-------------- tests/tests.rs | 8 +++---- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/tests/support/mod.rs b/tests/support/mod.rs index 7a027f9f5ee..a32b0fd009b 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -168,33 +168,52 @@ impl RlsHandle { pub fn send(&mut self, j: serde_json::Value) -> io::Result { self.send_string(&j.to_string()) } - pub fn notify(&mut self, method: &str, params: serde_json::Value) -> io::Result { - self.send(json!({ - "jsonrpc": "2.0", - "method": method, - "params": params, - })) + pub fn notify(&mut self, method: &str, params: Option) -> io::Result { + let message = if let Some(params) = params { + json!({ + "jsonrpc": "2.0", + "method": method, + "params": params, + }) + } else { + json!({ + "jsonrpc": "2.0", + "method": method, + }) + }; + + self.send(message) } - pub fn request(&mut self, id: u64, method: &str, params: serde_json::Value) -> io::Result { - self.send(json!({ - "jsonrpc": "2.0", - "id": id, - "method": method, - "params": params, - })) + pub fn request(&mut self, id: u64, method: &str, params: Option) -> io::Result { + let message = if let Some(params) = params { + json!({ + "jsonrpc": "2.0", + "id": id, + "method": method, + "params": params, + }) + } else { + json!({ + "jsonrpc": "2.0", + "id": id, + "method": method, + }) + }; + + self.send(message) } pub fn shutdown_exit(&mut self) { - self.request(99999, "shutdown", json!({})).unwrap(); + self.request(99999, "shutdown", None).unwrap(); self.expect_messages(&[ &ExpectedMessage::new(Some(99999)), ]); - self.notify("exit", json!({})).unwrap(); + self.notify("exit", None).unwrap(); let ecode = self.child.wait() .expect("failed to wait on child rls process"); - + assert!(ecode.success()); } diff --git a/tests/tests.rs b/tests/tests.rs index 3ffe1e27775..14d9db9126a 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -37,10 +37,10 @@ fn test_infer_bin() { let rls_child = p.rls().spawn().unwrap(); let mut rls = RlsHandle::new(rls_child); - rls.request(0, "initialize", json!({ + rls.request(0, "initialize", Some(json!({ "rootPath": root_path, "capabilities": {} - })).unwrap(); + }))).unwrap(); rls.expect_messages(&[ ExpectedMessage::new(Some(0)).expect_contains("capabilities"), @@ -119,10 +119,10 @@ fn test_simple_workspace() { let rls_child = p.rls().spawn().unwrap(); let mut rls = RlsHandle::new(rls_child); - rls.request(0, "initialize", json!({ + rls.request(0, "initialize", Some(json!({ "rootPath": root_path, "capabilities": {} - })).unwrap(); + }))).unwrap(); // This is the expected behavior is workspace_mode is on by default rls.expect_messages(&[