diff options
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | crates/ra_syntax/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_syntax/src/tests.rs | 47 |
3 files changed, 31 insertions, 18 deletions
diff --git a/Cargo.lock b/Cargo.lock index e6c7da51f..09909b60a 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1267,6 +1267,7 @@ dependencies = [ | |||
1267 | "once_cell", | 1267 | "once_cell", |
1268 | "ra_parser", | 1268 | "ra_parser", |
1269 | "ra_text_edit", | 1269 | "ra_text_edit", |
1270 | "rayon", | ||
1270 | "rowan", | 1271 | "rowan", |
1271 | "rustc-ap-rustc_lexer", | 1272 | "rustc-ap-rustc_lexer", |
1272 | "rustc-hash", | 1273 | "rustc-hash", |
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index cb21b8053..57cc09854 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml | |||
@@ -33,3 +33,4 @@ serde = { version = "1.0.106", features = ["derive"] } | |||
33 | test_utils = { path = "../test_utils" } | 33 | test_utils = { path = "../test_utils" } |
34 | expect = { path = "../expect" } | 34 | expect = { path = "../expect" } |
35 | walkdir = "2.3.1" | 35 | walkdir = "2.3.1" |
36 | rayon = "1" | ||
diff --git a/crates/ra_syntax/src/tests.rs b/crates/ra_syntax/src/tests.rs index aa78735da..8447dcad7 100644 --- a/crates/ra_syntax/src/tests.rs +++ b/crates/ra_syntax/src/tests.rs | |||
@@ -1,10 +1,11 @@ | |||
1 | use std::{ | 1 | use std::{ |
2 | fmt::Write, | 2 | fmt::Write, |
3 | fs, | 3 | fs, |
4 | path::{Component, Path, PathBuf}, | 4 | path::{Path, PathBuf}, |
5 | }; | 5 | }; |
6 | 6 | ||
7 | use expect::expect_file; | 7 | use expect::expect_file; |
8 | use rayon::prelude::*; | ||
8 | use test_utils::project_dir; | 9 | use test_utils::project_dir; |
9 | 10 | ||
10 | use crate::{fuzz, tokenize, SourceFile, SyntaxError, TextRange, TextSize, Token}; | 11 | use crate::{fuzz, tokenize, SourceFile, SyntaxError, TextRange, TextSize, Token}; |
@@ -121,33 +122,43 @@ fn reparse_fuzz_tests() { | |||
121 | /// FIXME: Use this as a benchmark | 122 | /// FIXME: Use this as a benchmark |
122 | #[test] | 123 | #[test] |
123 | fn self_hosting_parsing() { | 124 | fn self_hosting_parsing() { |
124 | use std::ffi::OsStr; | ||
125 | let dir = project_dir().join("crates"); | 125 | let dir = project_dir().join("crates"); |
126 | let mut count = 0; | 126 | let files = walkdir::WalkDir::new(dir) |
127 | for entry in walkdir::WalkDir::new(dir) | ||
128 | .into_iter() | 127 | .into_iter() |
129 | .filter_entry(|entry| { | 128 | .filter_entry(|entry| { |
130 | !entry.path().components().any(|component| { | 129 | // Get all files which are not in the crates/ra_syntax/test_data folder |
131 | // Get all files which are not in the crates/ra_syntax/test_data folder | 130 | !entry.path().components().any(|component| component.as_os_str() == "test_data") |
132 | component == Component::Normal(OsStr::new("test_data")) | ||
133 | }) | ||
134 | }) | 131 | }) |
135 | .map(|e| e.unwrap()) | 132 | .map(|e| e.unwrap()) |
136 | .filter(|entry| { | 133 | .filter(|entry| { |
137 | // Get all `.rs ` files | 134 | // Get all `.rs ` files |
138 | !entry.path().is_dir() && (entry.path().extension() == Some(OsStr::new("rs"))) | 135 | !entry.path().is_dir() && (entry.path().extension().unwrap_or_default() == "rs") |
139 | }) | 136 | }) |
140 | { | 137 | .map(|entry| entry.into_path()) |
141 | count += 1; | 138 | .collect::<Vec<_>>(); |
142 | let text = read_text(entry.path()); | ||
143 | if let Err(errors) = SourceFile::parse(&text).ok() { | ||
144 | panic!("Parsing errors:\n{:?}\n{}\n", errors, entry.path().display()); | ||
145 | } | ||
146 | } | ||
147 | assert!( | 139 | assert!( |
148 | count > 30, | 140 | files.len() > 100, |
149 | "self_hosting_parsing found too few files - is it running in the right directory?" | 141 | "self_hosting_parsing found too few files - is it running in the right directory?" |
150 | ) | 142 | ); |
143 | |||
144 | let errors = files | ||
145 | .into_par_iter() | ||
146 | .filter_map(|file| { | ||
147 | let text = read_text(&file); | ||
148 | match SourceFile::parse(&text).ok() { | ||
149 | Ok(_) => None, | ||
150 | Err(err) => Some((file, err)), | ||
151 | } | ||
152 | }) | ||
153 | .collect::<Vec<_>>(); | ||
154 | |||
155 | if !errors.is_empty() { | ||
156 | let errors = errors | ||
157 | .into_iter() | ||
158 | .map(|(path, err)| format!("{}: {:?}\n", path.display(), err)) | ||
159 | .collect::<String>(); | ||
160 | panic!("Parsing errors:\n{}\n", errors); | ||
161 | } | ||
151 | } | 162 | } |
152 | 163 | ||
153 | fn test_data_dir() -> PathBuf { | 164 | fn test_data_dir() -> PathBuf { |