From ae0cdb35875a1cdc7eaefe00e731e8dc38145f33 Mon Sep 17 00:00:00 2001 From: Alex Butler Date: Mon, 10 Dec 2018 12:18:29 +0000 Subject: [PATCH] Output expected/actual string diffs for tooltip test failures --- Cargo.lock | 7 +++++++ Cargo.toml | 3 +++ src/actions/hover.rs | 22 +++++++++++++++++++--- src/actions/notifications.rs | 1 - 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8403ac15b95..19618a80159 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -390,6 +390,11 @@ name = "diff" version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "difference" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "either" version = "1.5.0" @@ -1136,6 +1141,7 @@ dependencies = [ "cargo_metadata 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "clippy_lints 0.0.212 (git+https://github.com/rust-lang/rust-clippy?rev=a3c77f6ad1c1c185e561e9cd7fdec7db569169d1)", "crossbeam-channel 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1818,6 +1824,7 @@ dependencies = [ "checksum derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6ca414e896ae072546f4d789f452daaecf60ddee4c9df5dc6d5936d769e3d87c" "checksum derive_more 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3f57d78cf3bd45270dad4e70c21ec77a960b36c7a841ff9db76aaa775a8fb871" "checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a" +"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" "checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0" "checksum ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f56c93cc076508c549d9bb747f79aa9b4eb098be7b8cad8830c3137ef52d1e00" "checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38" diff --git a/Cargo.toml b/Cargo.toml index f603dca53b5..81344c9db99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,6 +49,9 @@ toml = "0.4" # for more information. rustc-workspace-hack = "1.0.0" +[dev-dependencies] +difference = "2" + [build-dependencies] rustc_tools_util = { git = "https://github.com/rust-lang/rust-clippy", rev = "a3c77f6ad1c1c185e561e9cd7fdec7db569169d1" } diff --git a/src/actions/hover.rs b/src/actions/hover.rs index c2a364dde95..ca2aa54061b 100644 --- a/src/actions/hover.rs +++ b/src/actions/hover.rs @@ -991,6 +991,7 @@ pub mod test { use std::path::PathBuf; use std::process; use std::sync::{Arc, Mutex}; + use std::fmt; #[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] pub struct Test { @@ -1106,7 +1107,7 @@ pub mod test { } } - #[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] + #[derive(PartialEq, Eq)] pub struct TestFailure { /// The test case, indicating file, line, and column pub test: Test, @@ -1123,6 +1124,21 @@ pub mod test { pub actual_data: Result, String>, ()>, } + impl fmt::Debug for TestFailure { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt.debug_struct("TestFailure") + .field("test", &self.test) + .field("expect_file", &self.expect_file) + .field("actual_file", &self.actual_file) + .finish()?; + + let expected = format!("{:#?}", self.expect_data); + let actual = format!("{:#?}", self.actual_data); + write!(fmt, "-diff: {}", difference::Changeset::new(&expected, &actual, "")) + } + } + + #[derive(Clone, Default)] pub struct LineOutput { req_id: Arc>, @@ -2117,7 +2133,7 @@ pub mod test { Ok(()) } else { eprintln!("{}\n\n", out.reset().join("\n")); - eprintln!("{:#?}\n\n", failures); + eprintln!("Failures (\x1b[91mexpected\x1b[92mactual\x1b[0m): {:#?}\n\n", failures); Err(format!("{} of {} tooltip tests failed", failures.len(), tests.len()).into()) } } @@ -2172,7 +2188,7 @@ pub mod test { Ok(()) } else { eprintln!("{}\n\n", out.reset().join("\n")); - eprintln!("{:#?}\n\n", failures); + eprintln!("Failures (\x1b[91mexpected\x1b[92mactual\x1b[0m): {:#?}\n\n", failures); Err(format!("{} of {} tooltip tests failed", failures.len(), tests.len()).into()) } } diff --git a/src/actions/notifications.rs b/src/actions/notifications.rs index 2b18c5095ea..2ac3a73134b 100644 --- a/src/actions/notifications.rs +++ b/src/actions/notifications.rs @@ -15,7 +15,6 @@ use crate::Span; use log::{debug, trace, warn}; use rls_vfs::{Change, VfsSpan}; use serde::Deserialize; -use serde_json; use std::sync::atomic::Ordering; use crate::build::*;