diff options
Diffstat (limited to 'crates/libsyntax2/tests')
-rw-r--r-- | crates/libsyntax2/tests/test/main.rs | 48 |
1 files changed, 20 insertions, 28 deletions
diff --git a/crates/libsyntax2/tests/test/main.rs b/crates/libsyntax2/tests/test/main.rs index 18e5bc4d4..64d080dfd 100644 --- a/crates/libsyntax2/tests/test/main.rs +++ b/crates/libsyntax2/tests/test/main.rs | |||
@@ -1,5 +1,6 @@ | |||
1 | extern crate libsyntax2; | 1 | extern crate libsyntax2; |
2 | extern crate difference; | 2 | #[macro_use] |
3 | extern crate assert_eq_text; | ||
3 | 4 | ||
4 | use std::{ | 5 | use std::{ |
5 | fs, | 6 | fs, |
@@ -7,8 +8,6 @@ use std::{ | |||
7 | fmt::Write, | 8 | fmt::Write, |
8 | }; | 9 | }; |
9 | 10 | ||
10 | use difference::Changeset; | ||
11 | |||
12 | #[test] | 11 | #[test] |
13 | fn lexer_tests() { | 12 | fn lexer_tests() { |
14 | dir_tests(&["lexer"], |text| { | 13 | dir_tests(&["lexer"], |text| { |
@@ -63,10 +62,26 @@ pub fn dir_tests<F>(paths: &[&str], f: F) | |||
63 | } | 62 | } |
64 | } | 63 | } |
65 | 64 | ||
65 | const REWRITE: bool = false; | ||
66 | |||
66 | fn assert_equal_text(expected: &str, actual: &str, path: &Path) { | 67 | fn assert_equal_text(expected: &str, actual: &str, path: &Path) { |
67 | if expected != actual { | 68 | if expected == actual { |
68 | print_difference(expected, actual, path) | 69 | return; |
70 | } | ||
71 | let dir = project_dir(); | ||
72 | let path = path.strip_prefix(&dir).unwrap_or_else(|_| path); | ||
73 | if expected.trim() == actual.trim() { | ||
74 | println!("whitespace difference, rewriting"); | ||
75 | println!("file: {}\n", path.display()); | ||
76 | fs::write(path, actual).unwrap(); | ||
77 | return; | ||
78 | } | ||
79 | if REWRITE { | ||
80 | println!("rewriting {}", path.display()); | ||
81 | fs::write(path, actual).unwrap(); | ||
82 | return; | ||
69 | } | 83 | } |
84 | assert_eq_text!(expected, actual, "file: {}", path.display()); | ||
70 | } | 85 | } |
71 | 86 | ||
72 | fn collect_tests(paths: &[&str]) -> Vec<PathBuf> { | 87 | fn collect_tests(paths: &[&str]) -> Vec<PathBuf> { |
@@ -92,29 +107,6 @@ fn test_from_dir(dir: &Path) -> Vec<PathBuf> { | |||
92 | acc | 107 | acc |
93 | } | 108 | } |
94 | 109 | ||
95 | const REWRITE: bool = false; | ||
96 | |||
97 | fn print_difference(expected: &str, actual: &str, path: &Path) { | ||
98 | let dir = project_dir(); | ||
99 | let path = path.strip_prefix(&dir).unwrap_or_else(|_| path); | ||
100 | if expected.trim() == actual.trim() { | ||
101 | println!("whitespace difference, rewriting"); | ||
102 | println!("file: {}\n", path.display()); | ||
103 | fs::write(path, actual).unwrap(); | ||
104 | return; | ||
105 | } | ||
106 | if REWRITE { | ||
107 | println!("rewriting {}", path.display()); | ||
108 | fs::write(path, actual).unwrap(); | ||
109 | return; | ||
110 | } | ||
111 | let changeset = Changeset::new(actual, expected, "\n"); | ||
112 | println!("Expected:\n{}\n\nActual:\n{}\n", expected, actual); | ||
113 | print!("{}", changeset); | ||
114 | println!("file: {}\n", path.display()); | ||
115 | panic!("Comparison failed") | ||
116 | } | ||
117 | |||
118 | fn project_dir() -> PathBuf { | 110 | fn project_dir() -> PathBuf { |
119 | let dir = env!("CARGO_MANIFEST_DIR"); | 111 | let dir = env!("CARGO_MANIFEST_DIR"); |
120 | PathBuf::from(dir) | 112 | PathBuf::from(dir) |