diff --git a/Cargo.lock b/Cargo.lock index de7337be136..3e6bd9bb30a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -351,6 +351,7 @@ dependencies = [ name = "expect" version = "0.1.0" dependencies = [ + "difference", "once_cell", "stdx", ] diff --git a/crates/expect/Cargo.toml b/crates/expect/Cargo.toml index 09eb57a4328..caee4310674 100644 --- a/crates/expect/Cargo.toml +++ b/crates/expect/Cargo.toml @@ -6,4 +6,5 @@ edition = "2018" [dependencies] once_cell = "1" +difference = "2" stdx = { path = "../stdx" } diff --git a/crates/expect/src/lib.rs b/crates/expect/src/lib.rs index dc4a4223e65..18f361ec2de 100644 --- a/crates/expect/src/lib.rs +++ b/crates/expect/src/lib.rs @@ -107,22 +107,30 @@ fn fail(expect: &Expect, expected: &str, actual: &str) { rt.help_printed = true; let help = if print_help { HELP } else { "" }; + + let diff = difference::Changeset::new(actual, expected, "\n"); + println!( "\n -error: expect test failed{} - --> {}:{}:{} +\x1b[1m\x1b[91merror\x1b[97m: expect test failed\x1b[0m{} + \x1b[1m\x1b[34m-->\x1b[0m {}:{}:{} {} -Expect: +\x1b[1mExpect\x1b[0m: ---- {} ---- -Actual: +\x1b[1mActual\x1b[0m: +---- +{} +---- + +\x1b[1mDiff\x1b[0m: ---- {} ---- ", - updated, expect.file, expect.line, expect.column, help, expected, actual + updated, expect.file, expect.line, expect.column, help, expected, actual, diff ); // Use resume_unwind instead of panic!() to prevent a backtrace, which is unnecessary noise. std::panic::resume_unwind(Box::new(()));