Add colors

This commit is contained in:
Aleksey Kladov 2020-06-27 21:13:49 +02:00
parent 175e48e5be
commit a9b4fb034b
3 changed files with 15 additions and 5 deletions

1
Cargo.lock generated
View file

@ -351,6 +351,7 @@ dependencies = [
name = "expect" name = "expect"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"difference",
"once_cell", "once_cell",
"stdx", "stdx",
] ]

View file

@ -6,4 +6,5 @@ edition = "2018"
[dependencies] [dependencies]
once_cell = "1" once_cell = "1"
difference = "2"
stdx = { path = "../stdx" } stdx = { path = "../stdx" }

View file

@ -107,22 +107,30 @@ impl Runtime {
rt.help_printed = true; rt.help_printed = true;
let help = if print_help { HELP } else { "" }; let help = if print_help { HELP } else { "" };
let diff = difference::Changeset::new(actual, expected, "\n");
println!( println!(
"\n "\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. // Use resume_unwind instead of panic!() to prevent a backtrace, which is unnecessary noise.
std::panic::resume_unwind(Box::new(())); std::panic::resume_unwind(Box::new(()));