File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments