diff --git a/Cargo.lock b/Cargo.lock index ad7a5e3264..f69f4b57eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -561,6 +561,7 @@ dependencies = [ "log", "memmap2", "num_cpus", + "similar", "target-lexicon", "thiserror", ] @@ -2599,6 +2600,12 @@ dependencies = [ "rand_core 0.6.3", ] +[[package]] +name = "similar" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e24979f63a11545f5f2c60141afe249d4f19f84581ea2138065e400941d83d3" + [[package]] name = "slice-group-by" version = "0.3.0" diff --git a/cranelift/filetests/Cargo.toml b/cranelift/filetests/Cargo.toml index 6545b5b719..cf659222cb 100644 --- a/cranelift/filetests/Cargo.toml +++ b/cranelift/filetests/Cargo.toml @@ -25,3 +25,4 @@ num_cpus = "1.8.0" target-lexicon = "0.12" thiserror = "1.0.15" anyhow = "1.0.32" +similar = "2.1.0" diff --git a/cranelift/filetests/src/test_compile.rs b/cranelift/filetests/src/test_compile.rs index 265d6c02be..205b4d7e75 100644 --- a/cranelift/filetests/src/test_compile.rs +++ b/cranelift/filetests/src/test_compile.rs @@ -8,6 +8,7 @@ use cranelift_codegen::binemit::CodeInfo; use cranelift_codegen::ir; use cranelift_reader::{TestCommand, TestOption}; use log::info; +use similar::TextDiff; use std::borrow::Cow; use std::env; @@ -102,17 +103,15 @@ fn check_precise_output(text: &str, context: &Context) -> Result<()> { "compilation of function on line {} does not match\n\ the text expectation\n\ \n\ - expected:\n\ - {:#?}\n\ - actual:\n\ - {:#?}\n\ + {}\n\ \n\ This test assertion can be automatically updated by setting the\n\ CRANELIFT_TEST_BLESS=1 environment variable when running this test. ", context.details.location.line_number, - expected, - actual, + TextDiff::from_slices(&expected, &actual) + .unified_diff() + .header("expected", "actual") ) }