Skip to content

Commit bedac7f

Browse files
committed
feat: more verbose output when bless test failed
1 parent c26a269 commit bedac7f

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

bootstrap/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootstrap/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ color-print = "0.3.6"
1010
env_logger = "0.11.5"
1111
glob = "0.3.1"
1212
log = "0.4.22"
13+
similar = "2.6.0"
1314
which = "6.0.1"

bootstrap/src/test.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use anstream::{eprint as print, eprintln as println};
55
use clap::Args;
66
use color_print::{cprint, cprintln};
77
use glob::glob;
8+
use similar::{ChangeTag, TextDiff};
89
use which::which;
910

1011
use crate::manifest::Manifest;
@@ -211,8 +212,21 @@ fn bless(update: bool, case: &TestCase) {
211212
if update {
212213
std::fs::copy(output, blessed).unwrap();
213214
} else {
214-
let output = std::fs::read(output).unwrap();
215-
let blessed = std::fs::read(blessed).unwrap();
216-
assert_eq!(output, blessed, "output does not match blessed output");
215+
let output = std::fs::read_to_string(output).unwrap();
216+
let blessed = std::fs::read_to_string(blessed).unwrap();
217+
218+
let diff = TextDiff::from_lines(&blessed, &output);
219+
if diff.ratio() < 1.0 {
220+
cprintln!("<r,s>output does not match blessed output</r,s>");
221+
for change in diff.iter_all_changes() {
222+
let lineno = change.old_index().unwrap_or(change.new_index().unwrap_or(0));
223+
match change.tag() {
224+
ChangeTag::Equal => print!(" {:4}| {}", lineno, change),
225+
ChangeTag::Insert => cprint!("<g>+{:4}| {}</g>", lineno, change),
226+
ChangeTag::Delete => cprint!("<r>-{:4}| {}</r>", lineno, change),
227+
}
228+
}
229+
std::process::exit(1);
230+
}
217231
}
218232
}

0 commit comments

Comments
 (0)