aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/tests.rs47
1 files changed, 29 insertions, 18 deletions
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 @@
1use std::{ 1use std::{
2 fmt::Write, 2 fmt::Write,
3 fs, 3 fs,
4 path::{Component, Path, PathBuf}, 4 path::{Path, PathBuf},
5}; 5};
6 6
7use expect::expect_file; 7use expect::expect_file;
8use rayon::prelude::*;
8use test_utils::project_dir; 9use test_utils::project_dir;
9 10
10use crate::{fuzz, tokenize, SourceFile, SyntaxError, TextRange, TextSize, Token}; 11use 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]
123fn self_hosting_parsing() { 124fn 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
153fn test_data_dir() -> PathBuf { 164fn test_data_dir() -> PathBuf {