diff options
author | DJMcNab <[email protected]> | 2018-12-09 19:19:23 +0000 |
---|---|---|
committer | DJMcNab <[email protected]> | 2018-12-19 20:12:18 +0000 |
commit | 0b77eec922441e3252803f3fbf20fb5ca0b8c6ef (patch) | |
tree | 1a83ac45527aa95220820ec86b0f12f9595f3df3 /crates/ra_syntax/tests | |
parent | fd22dbde20179192776a32e40b4f73f2df02c99e (diff) |
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
Diffstat (limited to 'crates/ra_syntax/tests')
-rw-r--r-- | crates/ra_syntax/tests/test.rs | 45 |
1 files changed, 43 insertions, 2 deletions
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; | |||
6 | use std::{ | 6 | use std::{ |
7 | fmt::Write, | 7 | fmt::Write, |
8 | fs, | 8 | fs, |
9 | path::{Path, PathBuf}, | 9 | path::{Path, PathBuf, Component}, |
10 | }; | 10 | }; |
11 | 11 | ||
12 | use ra_syntax::{ | 12 | use ra_syntax::{ |
@@ -37,6 +37,45 @@ fn parser_fuzz_tests() { | |||
37 | } | 37 | } |
38 | } | 38 | } |
39 | 39 | ||
40 | /// Test that Rust-analyzer can parse and validate the rust-analyser | ||
41 | /// TODO: Use this as a benchmark | ||
42 | #[test] | ||
43 | fn self_hosting_parsing() { | ||
44 | let empty_vec = vec![]; | ||
45 | let dir = project_dir(); | ||
46 | let mut count = 0u32; | ||
47 | for entry in walkdir::WalkDir::new(dir) | ||
48 | .into_iter() | ||
49 | .filter_entry(|entry| { | ||
50 | !entry | ||
51 | .path() | ||
52 | .components() | ||
53 | // TODO: this more neatly | ||
54 | .any(|component| { | ||
55 | // Get all files which are not in the crates/ra_syntax/tests/data folder | ||
56 | (component == Component::Normal(std::ffi::OsStr::new("data")) | ||
57 | // or the .git folder | ||
58 | || component == Component::Normal(std::ffi::OsStr::new(".git"))) | ||
59 | }) | ||
60 | }) | ||
61 | .map(|e| e.unwrap()) | ||
62 | .filter(|entry| { | ||
63 | // Get all `.rs ` files | ||
64 | !entry.path().is_dir() && (entry.path().extension() == Some(std::ffi::OsStr::new("rs"))) | ||
65 | }) | ||
66 | { | ||
67 | count += 1; | ||
68 | let text = read_text(entry.path()); | ||
69 | let node = SourceFileNode::parse(&text); | ||
70 | let errors = node.errors(); | ||
71 | assert_eq!( | ||
72 | errors, empty_vec, | ||
73 | "There should be no errors in the file {:?}", | ||
74 | entry | ||
75 | ); | ||
76 | } | ||
77 | panic!("{}", count) | ||
78 | } | ||
40 | /// Read file and normalize newlines. | 79 | /// Read file and normalize newlines. |
41 | /// | 80 | /// |
42 | /// `rustc` seems to always normalize `\r\n` newlines to `\n`: | 81 | /// `rustc` seems to always normalize `\r\n` newlines to `\n`: |
@@ -49,7 +88,9 @@ fn parser_fuzz_tests() { | |||
49 | /// | 88 | /// |
50 | /// so this should always be correct. | 89 | /// so this should always be correct. |
51 | fn read_text(path: &Path) -> String { | 90 | fn read_text(path: &Path) -> String { |
52 | fs::read_to_string(path).unwrap().replace("\r\n", "\n") | 91 | fs::read_to_string(path) |
92 | .expect(&format!("File at {:?} should be valid", path)) | ||
93 | .replace("\r\n", "\n") | ||
53 | } | 94 | } |
54 | 95 | ||
55 | pub fn dir_tests<F>(paths: &[&str], f: F) | 96 | pub fn dir_tests<F>(paths: &[&str], f: F) |