diff options
author | Florian Diebold <[email protected]> | 2018-12-06 20:07:31 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2018-12-06 20:32:15 +0000 |
commit | 1dfd06fc8aadd5d621112716fe0e59aed5dfc767 (patch) | |
tree | ed92a2a5c5f3666cd68b04abc653fe455f83d49e /crates/ra_lsp_server/tests/heavy_tests | |
parent | 8e60e751cbcfa47c7bed788dfe2ab5cebfcb78b3 (diff) |
Use json comparison code from cargo for heavy tests
Diffstat (limited to 'crates/ra_lsp_server/tests/heavy_tests')
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/main.rs | 10 | ||||
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/support.rs | 27 |
2 files changed, 20 insertions, 17 deletions
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index cbc0c8844..63d53fb01 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs | |||
@@ -1,5 +1,7 @@ | |||
1 | mod support; | 1 | mod support; |
2 | 2 | ||
3 | use serde_json::json; | ||
4 | |||
3 | use ra_lsp_server::req::{Runnables, RunnablesParams}; | 5 | use ra_lsp_server::req::{Runnables, RunnablesParams}; |
4 | 6 | ||
5 | use crate::support::project; | 7 | use crate::support::project; |
@@ -21,7 +23,7 @@ fn foo() { | |||
21 | text_document: server.doc_id("lib.rs"), | 23 | text_document: server.doc_id("lib.rs"), |
22 | position: None, | 24 | position: None, |
23 | }, | 25 | }, |
24 | r#"[ | 26 | json!([ |
25 | { | 27 | { |
26 | "args": [ "test", "--", "foo", "--nocapture" ], | 28 | "args": [ "test", "--", "foo", "--nocapture" ], |
27 | "bin": "cargo", | 29 | "bin": "cargo", |
@@ -51,7 +53,7 @@ fn foo() { | |||
51 | } | 53 | } |
52 | } | 54 | } |
53 | } | 55 | } |
54 | ]"#, | 56 | ]), |
55 | ); | 57 | ); |
56 | } | 58 | } |
57 | 59 | ||
@@ -78,7 +80,7 @@ fn test_eggs() {} | |||
78 | text_document: server.doc_id("tests/spam.rs"), | 80 | text_document: server.doc_id("tests/spam.rs"), |
79 | position: None, | 81 | position: None, |
80 | }, | 82 | }, |
81 | r#"[ | 83 | json!([ |
82 | { | 84 | { |
83 | "args": [ "test", "--package", "foo", "--test", "spam", "--", "test_eggs", "--nocapture" ], | 85 | "args": [ "test", "--package", "foo", "--test", "spam", "--", "test_eggs", "--nocapture" ], |
84 | "bin": "cargo", | 86 | "bin": "cargo", |
@@ -111,6 +113,6 @@ fn test_eggs() {} | |||
111 | } | 113 | } |
112 | } | 114 | } |
113 | } | 115 | } |
114 | ]"# | 116 | ]) |
115 | ); | 117 | ); |
116 | } | 118 | } |
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs index 019048a3a..4b75be3ee 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/support.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs | |||
@@ -15,9 +15,9 @@ use languageserver_types::{ | |||
15 | DidOpenTextDocumentParams, TextDocumentIdentifier, TextDocumentItem, Url, | 15 | DidOpenTextDocumentParams, TextDocumentIdentifier, TextDocumentItem, Url, |
16 | }; | 16 | }; |
17 | use serde::Serialize; | 17 | use serde::Serialize; |
18 | use serde_json::{from_str, to_string_pretty, Value}; | 18 | use serde_json::{to_string_pretty, Value}; |
19 | use tempdir::TempDir; | 19 | use tempdir::TempDir; |
20 | use test_utils::parse_fixture; | 20 | use test_utils::{parse_fixture, find_mismatch}; |
21 | 21 | ||
22 | use ra_lsp_server::{ | 22 | use ra_lsp_server::{ |
23 | main_loop, req, | 23 | main_loop, req, |
@@ -88,23 +88,24 @@ impl Server { | |||
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | pub fn request<R>(&self, params: R::Params, expected_resp: &str) | 91 | pub fn request<R>(&self, params: R::Params, expected_resp: Value) |
92 | where | 92 | where |
93 | R: Request, | 93 | R: Request, |
94 | R::Params: Serialize, | 94 | R::Params: Serialize, |
95 | { | 95 | { |
96 | let id = self.req_id.get(); | 96 | let id = self.req_id.get(); |
97 | self.req_id.set(id + 1); | 97 | self.req_id.set(id + 1); |
98 | let expected_resp: Value = from_str(expected_resp).unwrap(); | ||
99 | let actual = self.send_request::<R>(id, params); | 98 | let actual = self.send_request::<R>(id, params); |
100 | assert_eq!( | 99 | match find_mismatch(&expected_resp, &actual) { |
101 | expected_resp, | 100 | Some((expected_part, actual_part)) => panic!( |
102 | actual, | 101 | "JSON mismatch\nExpected:\n{}\nWas:\n{}\nExpected part:\n{}\nActual part:\n{}\n", |
103 | "Expected:\n{}\n\ | 102 | to_string_pretty(&expected_resp).unwrap(), |
104 | Actual:\n{}\n", | 103 | to_string_pretty(&actual).unwrap(), |
105 | to_string_pretty(&expected_resp).unwrap(), | 104 | to_string_pretty(expected_part).unwrap(), |
106 | to_string_pretty(&actual).unwrap(), | 105 | to_string_pretty(actual_part).unwrap(), |
107 | ); | 106 | ), |
107 | None => {} | ||
108 | } | ||
108 | } | 109 | } |
109 | 110 | ||
110 | fn send_request<R>(&self, id: u64, params: R::Params) -> Value | 111 | fn send_request<R>(&self, id: u64, params: R::Params) -> Value |
@@ -139,7 +140,7 @@ impl Server { | |||
139 | pub fn wait_for_feedback_n(&self, feedback: &str, n: usize) { | 140 | pub fn wait_for_feedback_n(&self, feedback: &str, n: usize) { |
140 | let f = |msg: &RawMessage| match msg { | 141 | let f = |msg: &RawMessage| match msg { |
141 | RawMessage::Notification(n) if n.method == "internalFeedback" => { | 142 | RawMessage::Notification(n) if n.method == "internalFeedback" => { |
142 | return n.clone().cast::<req::InternalFeedback>().unwrap() == feedback | 143 | return n.clone().cast::<req::InternalFeedback>().unwrap() == feedback; |
143 | } | 144 | } |
144 | _ => false, | 145 | _ => false, |
145 | }; | 146 | }; |