Skip to content

Commit

Permalink
Properly handle void params in integration test harness
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Jan 18, 2018
1 parent 5479c16 commit 7adf369
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
51 changes: 35 additions & 16 deletions tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,33 +168,52 @@ impl RlsHandle {
pub fn send(&mut self, j: serde_json::Value) -> io::Result<usize> {
self.send_string(&j.to_string())
}
pub fn notify(&mut self, method: &str, params: serde_json::Value) -> io::Result<usize> {
self.send(json!({
"jsonrpc": "2.0",
"method": method,
"params": params,
}))
pub fn notify(&mut self, method: &str, params: Option<serde_json::Value>) -> io::Result<usize> {
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<usize> {
self.send(json!({
"jsonrpc": "2.0",
"id": id,
"method": method,
"params": params,
}))
pub fn request(&mut self, id: u64, method: &str, params: Option<serde_json::Value>) -> io::Result<usize> {
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());
}

Expand Down
8 changes: 4 additions & 4 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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(&[
Expand Down

0 comments on commit 7adf369

Please # to comment.