diff options
| author | Henrik Tjäder <henrik@tjaders.com> | 2023-02-06 13:03:15 +0100 |
|---|---|---|
| committer | Henrik Tjäder <henrik@tjaders.com> | 2023-03-01 00:35:15 +0100 |
| commit | d5471f2da4f9f650a42a745238fe8a5f85eed920 (patch) | |
| tree | 8efd75c19ff7ce0c87133baef1499732df8f707f | |
| parent | 6ed64610c982f4e3648b73604ac4ba190476bf3d (diff) | |
xtask: Add proper diff printing in case of incorrect results
| -rw-r--r-- | xtask/Cargo.toml | 1 | ||||
| -rw-r--r-- | xtask/src/main.rs | 15 |
2 files changed, 11 insertions, 5 deletions
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 807741a..7341215 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -11,3 +11,4 @@ clap = { version = "4", features = ["derive"] } env_logger = "0.10.0" log = "0.4.17" rayon = "1.6.1" +diffy = "0.3.0" diff --git a/xtask/src/main.rs b/xtask/src/main.rs index d05e981..342d654 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -130,19 +130,23 @@ pub enum TestRunError { CommandError(RunResult), IncompatibleCommand, } +use diffy::{create_patch, PatchFormatter}; impl fmt::Display for TestRunError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { TestRunError::FileCmpError { expected, got } => { + let patch = create_patch(expected, got); writeln!(f, "Differing output in files.\n")?; - writeln!(f, "Expected:")?; - writeln!(f, "{expected}\n")?; - writeln!(f, "Got:")?; - write!(f, "{got}") + let pf = PatchFormatter::new().with_color(); + writeln!(f, "{}", pf.fmt_patch(&patch))?; + write!( + f, + "See flag --overwrite-expected to create/update expected output." + ) } TestRunError::FileError { file } => { - write!(f, "File error on: {file}\nSee flag overwrite.") + write!(f, "File error on: {file}\nSee flag --overwrite-expected to create/update expected output.") } TestRunError::CommandError(e) => { write!( @@ -403,6 +407,7 @@ fn arm_example(command: &CargoCommand, overwrite: bool) -> anyhow::Result<()> { file: expected_output_file.clone(), } })?; + info!("Flag --overwrite-expected enabled"); info!("Creating/updating file: {expected_output_file}"); file_handle.write_all(cargo_run_result.output.as_bytes())?; }; |
