Skip to content

Commit c3d9da3

Browse files
committed
Add sanity test
An integration sanity test is added to ensure that all RBS included in the repo can be correctly parsed.
1 parent 74ef58e commit c3d9da3

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

rust/ruby-rbs/tests/sanity.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use std::path::Path;
2+
3+
use ruby_rbs::node::parse;
4+
5+
fn collect_rbs_files(dir: &Path) -> Vec<std::path::PathBuf> {
6+
let mut files = Vec::new();
7+
8+
for entry in std::fs::read_dir(dir).unwrap() {
9+
let entry = entry.unwrap();
10+
let path = entry.path();
11+
12+
if path.is_dir() {
13+
files.extend(collect_rbs_files(&path));
14+
} else if path.extension().is_some_and(|ext| ext == "rbs") {
15+
files.push(path);
16+
}
17+
}
18+
19+
files
20+
}
21+
22+
#[test]
23+
fn all_included_rbs_can_be_parsed() {
24+
let repo_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
25+
let dirs = [repo_root.join("core"), repo_root.join("stdlib")];
26+
27+
let mut files: Vec<_> = dirs.iter().flat_map(|d| collect_rbs_files(d)).collect();
28+
files.sort();
29+
assert!(!files.is_empty());
30+
31+
let mut failures = Vec::new();
32+
33+
for file in &files {
34+
let content = std::fs::read_to_string(file).unwrap();
35+
36+
if let Err(e) = parse(content.as_bytes()) {
37+
failures.push(format!("{}: {}", file.display(), e));
38+
}
39+
}
40+
41+
assert!(
42+
failures.is_empty(),
43+
"Failed to parse {} RBS file(s):\n{}",
44+
failures.len(),
45+
failures.join("\n")
46+
);
47+
}

0 commit comments

Comments
 (0)