5312: Make slow test parallel r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-07-11 10:57:21 +00:00 committed by GitHub
commit 9e75b39115
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 18 deletions

1
Cargo.lock generated
View file

@ -1267,6 +1267,7 @@ dependencies = [
"once_cell", "once_cell",
"ra_parser", "ra_parser",
"ra_text_edit", "ra_text_edit",
"rayon",
"rowan", "rowan",
"rustc-ap-rustc_lexer", "rustc-ap-rustc_lexer",
"rustc-hash", "rustc-hash",

View file

@ -33,3 +33,4 @@ serde = { version = "1.0.106", features = ["derive"] }
test_utils = { path = "../test_utils" } test_utils = { path = "../test_utils" }
expect = { path = "../expect" } expect = { path = "../expect" }
walkdir = "2.3.1" walkdir = "2.3.1"
rayon = "1"

View file

@ -1,10 +1,11 @@
use std::{ use std::{
fmt::Write, fmt::Write,
fs, fs,
path::{Component, Path, PathBuf}, path::{Path, PathBuf},
}; };
use expect::expect_file; use expect::expect_file;
use rayon::prelude::*;
use test_utils::project_dir; use test_utils::project_dir;
use crate::{fuzz, tokenize, SourceFile, SyntaxError, TextRange, TextSize, Token}; use crate::{fuzz, tokenize, SourceFile, SyntaxError, TextRange, TextSize, Token};
@ -121,33 +122,43 @@ fn reparse_fuzz_tests() {
/// FIXME: Use this as a benchmark /// FIXME: Use this as a benchmark
#[test] #[test]
fn self_hosting_parsing() { fn self_hosting_parsing() {
use std::ffi::OsStr;
let dir = project_dir().join("crates"); let dir = project_dir().join("crates");
let mut count = 0; let files = walkdir::WalkDir::new(dir)
for entry in walkdir::WalkDir::new(dir)
.into_iter() .into_iter()
.filter_entry(|entry| { .filter_entry(|entry| {
!entry.path().components().any(|component| { // Get all files which are not in the crates/ra_syntax/test_data folder
// Get all files which are not in the crates/ra_syntax/test_data folder !entry.path().components().any(|component| component.as_os_str() == "test_data")
component == Component::Normal(OsStr::new("test_data"))
})
}) })
.map(|e| e.unwrap()) .map(|e| e.unwrap())
.filter(|entry| { .filter(|entry| {
// Get all `.rs ` files // Get all `.rs ` files
!entry.path().is_dir() && (entry.path().extension() == Some(OsStr::new("rs"))) !entry.path().is_dir() && (entry.path().extension().unwrap_or_default() == "rs")
}) })
{ .map(|entry| entry.into_path())
count += 1; .collect::<Vec<_>>();
let text = read_text(entry.path());
if let Err(errors) = SourceFile::parse(&text).ok() {
panic!("Parsing errors:\n{:?}\n{}\n", errors, entry.path().display());
}
}
assert!( assert!(
count > 30, files.len() > 100,
"self_hosting_parsing found too few files - is it running in the right directory?" "self_hosting_parsing found too few files - is it running in the right directory?"
) );
let errors = files
.into_par_iter()
.filter_map(|file| {
let text = read_text(&file);
match SourceFile::parse(&text).ok() {
Ok(_) => None,
Err(err) => Some((file, err)),
}
})
.collect::<Vec<_>>();
if !errors.is_empty() {
let errors = errors
.into_iter()
.map(|(path, err)| format!("{}: {:?}\n", path.display(), err))
.collect::<String>();
panic!("Parsing errors:\n{}\n", errors);
}
} }
fn test_data_dir() -> PathBuf { fn test_data_dir() -> PathBuf {