From 0b77eec922441e3252803f3fbf20fb5ca0b8c6ef Mon Sep 17 00:00:00 2001 From: DJMcNab <36049421+DJMcNab@users.noreply.github.com> Date: Sun, 9 Dec 2018 19:19:23 +0000 Subject: 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 --- crates/ra_syntax/tests/test.rs | 45 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/tests/test.rs') diff --git a/crates/ra_syntax/tests/test.rs b/crates/ra_syntax/tests/test.rs index 67acc9020..7f385f86f 100644 --- a/crates/ra_syntax/tests/test.rs +++ b/crates/ra_syntax/tests/test.rs @@ -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(paths: &[&str], f: F) -- cgit v1.2.3