Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Output expected/actual string diffs for tooltip test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
alexheretic committed Dec 13, 2018
1 parent 6b68471 commit dede5d5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
24 changes: 21 additions & 3 deletions src/actions/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -1123,6 +1124,23 @@ pub mod test {
pub actual_data: Result<Result<Vec<MarkedString>, 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)
.field("expect_data", &self.expect_data)
.field("actual_data", &self.actual_data)
.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<Mutex<u64>>,
Expand Down Expand Up @@ -2117,7 +2135,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())
}
}
Expand Down Expand Up @@ -2172,7 +2190,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())
}
}
Expand Down

0 comments on commit dede5d5

Please sign in to comment.