diff options
Diffstat (limited to 'crates/libsyntax2/tests/test/main.rs')
-rw-r--r-- | crates/libsyntax2/tests/test/main.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/crates/libsyntax2/tests/test/main.rs b/crates/libsyntax2/tests/test/main.rs index 596f32216..014faa2c6 100644 --- a/crates/libsyntax2/tests/test/main.rs +++ b/crates/libsyntax2/tests/test/main.rs | |||
@@ -12,7 +12,7 @@ use std::{ | |||
12 | use test_utils::extract_range; | 12 | use test_utils::extract_range; |
13 | use libsyntax2::{ | 13 | use libsyntax2::{ |
14 | File, AtomEdit, | 14 | File, AtomEdit, |
15 | utils::dump_tree, | 15 | utils::{dump_tree, check_fuzz_invariants}, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | #[test] | 18 | #[test] |
@@ -32,6 +32,13 @@ fn parser_tests() { | |||
32 | } | 32 | } |
33 | 33 | ||
34 | #[test] | 34 | #[test] |
35 | fn parser_fuzz_tests() { | ||
36 | for (_, text) in collect_tests(&["parser/fuzz-failures"]) { | ||
37 | check_fuzz_invariants(&text) | ||
38 | } | ||
39 | } | ||
40 | |||
41 | #[test] | ||
35 | fn reparse_test() { | 42 | fn reparse_test() { |
36 | fn do_check(before: &str, replace_with: &str) { | 43 | fn do_check(before: &str, replace_with: &str) { |
37 | let (range, before) = extract_range(before); | 44 | let (range, before) = extract_range(before); |
@@ -88,8 +95,7 @@ pub fn dir_tests<F>(paths: &[&str], f: F) | |||
88 | where | 95 | where |
89 | F: Fn(&str) -> String, | 96 | F: Fn(&str) -> String, |
90 | { | 97 | { |
91 | for path in collect_tests(paths) { | 98 | for (path, input_code) in collect_tests(paths) { |
92 | let input_code = read_text(&path); | ||
93 | let parse_tree = f(&input_code); | 99 | let parse_tree = f(&input_code); |
94 | let path = path.with_extension("txt"); | 100 | let path = path.with_extension("txt"); |
95 | if !path.exists() { | 101 | if !path.exists() { |
@@ -128,13 +134,17 @@ fn assert_equal_text(expected: &str, actual: &str, path: &Path) { | |||
128 | assert_eq_text!(expected, actual, "file: {}", pretty_path.display()); | 134 | assert_eq_text!(expected, actual, "file: {}", pretty_path.display()); |
129 | } | 135 | } |
130 | 136 | ||
131 | fn collect_tests(paths: &[&str]) -> Vec<PathBuf> { | 137 | fn collect_tests(paths: &[&str]) -> Vec<(PathBuf, String)> { |
132 | paths | 138 | paths |
133 | .iter() | 139 | .iter() |
134 | .flat_map(|path| { | 140 | .flat_map(|path| { |
135 | let path = test_data_dir().join(path); | 141 | let path = test_data_dir().join(path); |
136 | test_from_dir(&path).into_iter() | 142 | test_from_dir(&path).into_iter() |
137 | }) | 143 | }) |
144 | .map(|path| { | ||
145 | let text = read_text(&path); | ||
146 | (path, text) | ||
147 | }) | ||
138 | .collect() | 148 | .collect() |
139 | } | 149 | } |
140 | 150 | ||