mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Make slow test parallel
This commit is contained in:
parent
8c4919c9fd
commit
9a3c22bbfd
3 changed files with 31 additions and 18 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -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",
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -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
|
||||||
component == Component::Normal(OsStr::new("test_data"))
|
!entry.path().components().any(|component| component.as_os_str() == "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 {
|
||||||
|
|
Loading…
Reference in a new issue