mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Add a test to ensure that we can parse each file
Note that this has a non-spurious failure in ra_analysis/src/mock_analysis
This commit is contained in:
parent
fd22dbde20
commit
0b77eec922
1 changed files with 43 additions and 2 deletions
|
@ -6,7 +6,7 @@ extern crate walkdir;
|
|||
use std::{
|
||||
fmt::Write,
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
path::{Path, PathBuf, Component},
|
||||
};
|
||||
|
||||
use ra_syntax::{
|
||||
|
@ -37,6 +37,45 @@ fn parser_fuzz_tests() {
|
|||
}
|
||||
}
|
||||
|
||||
/// Test that Rust-analyzer can parse and validate the rust-analyser
|
||||
/// TODO: Use this as a benchmark
|
||||
#[test]
|
||||
fn self_hosting_parsing() {
|
||||
let empty_vec = vec![];
|
||||
let dir = project_dir();
|
||||
let mut count = 0u32;
|
||||
for entry in walkdir::WalkDir::new(dir)
|
||||
.into_iter()
|
||||
.filter_entry(|entry| {
|
||||
!entry
|
||||
.path()
|
||||
.components()
|
||||
// TODO: this more neatly
|
||||
.any(|component| {
|
||||
// Get all files which are not in the crates/ra_syntax/tests/data folder
|
||||
(component == Component::Normal(std::ffi::OsStr::new("data"))
|
||||
// or the .git folder
|
||||
|| component == Component::Normal(std::ffi::OsStr::new(".git")))
|
||||
})
|
||||
})
|
||||
.map(|e| e.unwrap())
|
||||
.filter(|entry| {
|
||||
// Get all `.rs ` files
|
||||
!entry.path().is_dir() && (entry.path().extension() == Some(std::ffi::OsStr::new("rs")))
|
||||
})
|
||||
{
|
||||
count += 1;
|
||||
let text = read_text(entry.path());
|
||||
let node = SourceFileNode::parse(&text);
|
||||
let errors = node.errors();
|
||||
assert_eq!(
|
||||
errors, empty_vec,
|
||||
"There should be no errors in the file {:?}",
|
||||
entry
|
||||
);
|
||||
}
|
||||
panic!("{}", count)
|
||||
}
|
||||
/// Read file and normalize newlines.
|
||||
///
|
||||
/// `rustc` seems to always normalize `\r\n` newlines to `\n`:
|
||||
|
@ -49,7 +88,9 @@ fn parser_fuzz_tests() {
|
|||
///
|
||||
/// so this should always be correct.
|
||||
fn read_text(path: &Path) -> String {
|
||||
fs::read_to_string(path).unwrap().replace("\r\n", "\n")
|
||||
fs::read_to_string(path)
|
||||
.expect(&format!("File at {:?} should be valid", path))
|
||||
.replace("\r\n", "\n")
|
||||
}
|
||||
|
||||
pub fn dir_tests<F>(paths: &[&str], f: F)
|
||||
|
|
Loading…
Reference in a new issue