aboutsummaryrefslogtreecommitdiff
path: root/tests/testutils/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-02-10 11:06:47 +0000
committerAleksey Kladov <[email protected]>2018-02-10 11:07:02 +0000
commit1401f5af4a3f13984da1237b3ad896eb50eada73 (patch)
tree96c80606d06727e1e641e1f68a55da086356ae16 /tests/testutils/src
parent3c9d8ff42357711775c3aeb3af03f528ee779932 (diff)
Allow to update files en masse
Diffstat (limited to 'tests/testutils/src')
-rw-r--r--tests/testutils/src/lib.rs18
1 files changed, 13 insertions, 5 deletions
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 {
22} 22}
23 23
24pub fn dir_tests<F>(paths: &[&str], f: F) 24pub fn dir_tests<F>(paths: &[&str], f: F)
25where 25 where
26 F: Fn(&str) -> String, 26 F: Fn(&str) -> String,
27{ 27{
28 for path in collect_tests(paths) { 28 for path in collect_tests(paths) {
29 let actual = { 29 let actual = {
@@ -73,16 +73,24 @@ fn test_from_dir(dir: &Path) -> Vec<PathBuf> {
73 acc 73 acc
74} 74}
75 75
76const REWRITE: bool = false;
77
76fn print_difference(expected: &str, actual: &str, path: &Path) { 78fn print_difference(expected: &str, actual: &str, path: &Path) {
77 let dir = project_dir(); 79 let dir = project_dir();
78 let path = path.strip_prefix(&dir).unwrap_or_else(|_| path); 80 let path = path.strip_prefix(&dir).unwrap_or_else(|_| path);
79 if expected.trim() == actual.trim() { 81 if expected.trim() == actual.trim() {
80 println!("whitespace difference, rewriting"); 82 println!("whitespace difference, rewriting");
83 println!("file: {}\n", path.display());
84 file::put_text(path, actual).unwrap();
85 return;
86 }
87 if REWRITE {
88 println!("rewriting {}", path.display());
81 file::put_text(path, actual).unwrap(); 89 file::put_text(path, actual).unwrap();
82 } else { 90 return;
83 let changeset = Changeset::new(actual, expected, "\n");
84 print!("{}", changeset);
85 } 91 }
92 let changeset = Changeset::new(actual, expected, "\n");
93 print!("{}", changeset);
86 println!("file: {}\n", path.display()); 94 println!("file: {}\n", path.display());
87 panic!("Comparison failed") 95 panic!("Comparison failed")
88} 96}