mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-22 20:53:37 +00:00
Show diffs for failing tests
This commit is contained in:
parent
6b1494885c
commit
4ecde410c4
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -2,9 +2,15 @@
|
||||
name = "rustfmt"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"diff 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"strings 0.0.1 (git+https://github.com/nrc/strings.rs.git)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "diff"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "strings"
|
||||
version = "0.0.1"
|
||||
|
@ -11,3 +11,6 @@ license = "Apache-2.0/MIT"
|
||||
[dependencies.strings]
|
||||
strings = "0.0.1"
|
||||
git = "https://github.com/nrc/strings.rs.git"
|
||||
|
||||
[dev-dependencies]
|
||||
diff = "0.1.0"
|
||||
|
@ -11,6 +11,7 @@
|
||||
#![feature(catch_panic)]
|
||||
|
||||
extern crate rustfmt;
|
||||
extern crate diff;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
@ -89,6 +90,7 @@ fn handle_result(result: HashMap<String, String>) {
|
||||
// TODO: speedup by running through bytes iterator
|
||||
f.read_to_string(&mut text).unwrap();
|
||||
if fmt_text != text {
|
||||
show_diff(&file_name, &fmt_text, &text);
|
||||
failures.insert(file_name, fmt_text);
|
||||
}
|
||||
}
|
||||
@ -96,3 +98,33 @@ fn handle_result(result: HashMap<String, String>) {
|
||||
panic!(failures);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn show_diff(file_name: &str, expected: &str, actual: &str) {
|
||||
let mut line_number = 1;
|
||||
let mut prev_both = true;
|
||||
|
||||
for result in diff::lines(expected, actual) {
|
||||
match result {
|
||||
diff::Result::Left(str) => {
|
||||
if prev_both {
|
||||
println!("Mismatch @ {}:{}", file_name, line_number);
|
||||
}
|
||||
println!("-{}⏎", str);
|
||||
prev_both = false;
|
||||
}
|
||||
diff::Result::Right(str) => {
|
||||
if prev_both {
|
||||
println!("Mismatch @ {}:{}", file_name, line_number);
|
||||
}
|
||||
println!("+{}⏎", str);
|
||||
prev_both = false;
|
||||
line_number += 1;
|
||||
}
|
||||
diff::Result::Both(..) => {
|
||||
line_number += 1;
|
||||
prev_both = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user