From 1dfd06fc8aadd5d621112716fe0e59aed5dfc767 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 6 Dec 2018 21:07:31 +0100 Subject: Use json comparison code from cargo for heavy tests --- crates/ra_lsp_server/tests/heavy_tests/main.rs | 10 +++++---- crates/ra_lsp_server/tests/heavy_tests/support.rs | 27 ++++++++++++----------- 2 files changed, 20 insertions(+), 17 deletions(-) (limited to 'crates/ra_lsp_server/tests') 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 @@ mod support; +use serde_json::json; + use ra_lsp_server::req::{Runnables, RunnablesParams}; use crate::support::project; @@ -21,7 +23,7 @@ fn foo() { text_document: server.doc_id("lib.rs"), position: None, }, - r#"[ + json!([ { "args": [ "test", "--", "foo", "--nocapture" ], "bin": "cargo", @@ -51,7 +53,7 @@ fn foo() { } } } - ]"#, + ]), ); } @@ -78,7 +80,7 @@ fn test_eggs() {} text_document: server.doc_id("tests/spam.rs"), position: None, }, - r#"[ + json!([ { "args": [ "test", "--package", "foo", "--test", "spam", "--", "test_eggs", "--nocapture" ], "bin": "cargo", @@ -111,6 +113,6 @@ fn test_eggs() {} } } } - ]"# + ]) ); } 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::{ DidOpenTextDocumentParams, TextDocumentIdentifier, TextDocumentItem, Url, }; use serde::Serialize; -use serde_json::{from_str, to_string_pretty, Value}; +use serde_json::{to_string_pretty, Value}; use tempdir::TempDir; -use test_utils::parse_fixture; +use test_utils::{parse_fixture, find_mismatch}; use ra_lsp_server::{ main_loop, req, @@ -88,23 +88,24 @@ impl Server { } } - pub fn request(&self, params: R::Params, expected_resp: &str) + pub fn request(&self, params: R::Params, expected_resp: Value) where R: Request, R::Params: Serialize, { let id = self.req_id.get(); self.req_id.set(id + 1); - let expected_resp: Value = from_str(expected_resp).unwrap(); let actual = self.send_request::(id, params); - assert_eq!( - expected_resp, - actual, - "Expected:\n{}\n\ - Actual:\n{}\n", - to_string_pretty(&expected_resp).unwrap(), - to_string_pretty(&actual).unwrap(), - ); + match find_mismatch(&expected_resp, &actual) { + Some((expected_part, actual_part)) => panic!( + "JSON mismatch\nExpected:\n{}\nWas:\n{}\nExpected part:\n{}\nActual part:\n{}\n", + to_string_pretty(&expected_resp).unwrap(), + to_string_pretty(&actual).unwrap(), + to_string_pretty(expected_part).unwrap(), + to_string_pretty(actual_part).unwrap(), + ), + None => {} + } } fn send_request(&self, id: u64, params: R::Params) -> Value @@ -139,7 +140,7 @@ impl Server { pub fn wait_for_feedback_n(&self, feedback: &str, n: usize) { let f = |msg: &RawMessage| match msg { RawMessage::Notification(n) if n.method == "internalFeedback" => { - return n.clone().cast::().unwrap() == feedback + return n.clone().cast::().unwrap() == feedback; } _ => false, }; -- cgit v1.2.3