From 1401f5af4a3f13984da1237b3ad896eb50eada73 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 10 Feb 2018 14:06:47 +0300 Subject: Allow to update files en masse --- tests/testutils/src/lib.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'tests/testutils/src') diff --git a/tests/testutils/src/lib.rs b/tests/testutils/src/lib.rs index d181e455b..abd28f26d 100644 --- a/tests/testutils/src/lib.rs +++ b/tests/testutils/src/lib.rs @@ -22,8 +22,8 @@ fn read_text(path: &Path) -> String { } pub fn dir_tests(paths: &[&str], f: F) -where - F: Fn(&str) -> String, + where + F: Fn(&str) -> String, { for path in collect_tests(paths) { let actual = { @@ -73,16 +73,24 @@ fn test_from_dir(dir: &Path) -> Vec { acc } +const REWRITE: bool = false; + fn print_difference(expected: &str, actual: &str, path: &Path) { let dir = project_dir(); let path = path.strip_prefix(&dir).unwrap_or_else(|_| path); if expected.trim() == actual.trim() { println!("whitespace difference, rewriting"); + println!("file: {}\n", path.display()); + file::put_text(path, actual).unwrap(); + return; + } + if REWRITE { + println!("rewriting {}", path.display()); file::put_text(path, actual).unwrap(); - } else { - let changeset = Changeset::new(actual, expected, "\n"); - print!("{}", changeset); + return; } + let changeset = Changeset::new(actual, expected, "\n"); + print!("{}", changeset); println!("file: {}\n", path.display()); panic!("Comparison failed") } -- cgit v1.2.3