@@ -8,16 +8,20 @@ use std::{
8
8
path:: { Path , PathBuf } ,
9
9
} ;
10
10
11
- #[ test]
12
- fn sourcegen_parser_tests ( ) {
13
- let grammar_dir = sourcegen:: project_root ( ) . join ( Path :: new ( "crates/parser/src/grammar" ) ) ;
11
+ use crate :: {
12
+ codegen:: { ensure_file_contents, list_rust_files, CommentBlock } ,
13
+ project_root,
14
+ } ;
15
+
16
+ pub ( crate ) fn generate ( check : bool ) {
17
+ let grammar_dir = project_root ( ) . join ( Path :: new ( "crates/parser/src/grammar" ) ) ;
14
18
let tests = tests_from_dir ( & grammar_dir) ;
15
19
16
- install_tests ( & tests. ok , "crates/parser/test_data/parser/inline/ok" ) ;
17
- install_tests ( & tests. err , "crates/parser/test_data/parser/inline/err" ) ;
20
+ install_tests ( & tests. ok , "crates/parser/test_data/parser/inline/ok" , check ) ;
21
+ install_tests ( & tests. err , "crates/parser/test_data/parser/inline/err" , check ) ;
18
22
19
- fn install_tests ( tests : & HashMap < String , Test > , into : & str ) {
20
- let tests_dir = sourcegen :: project_root ( ) . join ( into) ;
23
+ fn install_tests ( tests : & HashMap < String , Test > , into : & str , check : bool ) {
24
+ let tests_dir = project_root ( ) . join ( into) ;
21
25
if !tests_dir. is_dir ( ) {
22
26
fs:: create_dir_all ( & tests_dir) . unwrap ( ) ;
23
27
}
@@ -37,7 +41,7 @@ fn sourcegen_parser_tests() {
37
41
tests_dir. join ( file_name)
38
42
}
39
43
} ;
40
- sourcegen :: ensure_file_contents ( & path, & test. text ) ;
44
+ ensure_file_contents ( crate :: flags :: CodegenType :: ParserTests , & path, & test. text , check ) ;
41
45
}
42
46
}
43
47
}
@@ -57,7 +61,7 @@ struct Tests {
57
61
58
62
fn collect_tests ( s : & str ) -> Vec < Test > {
59
63
let mut res = Vec :: new ( ) ;
60
- for comment_block in sourcegen :: CommentBlock :: extract_untagged ( s) {
64
+ for comment_block in CommentBlock :: extract_untagged ( s) {
61
65
let first_line = & comment_block. contents [ 0 ] ;
62
66
let ( name, ok) = if let Some ( name) = first_line. strip_prefix ( "test " ) {
63
67
( name. to_owned ( ) , true )
@@ -80,7 +84,7 @@ fn collect_tests(s: &str) -> Vec<Test> {
80
84
81
85
fn tests_from_dir ( dir : & Path ) -> Tests {
82
86
let mut res = Tests :: default ( ) ;
83
- for entry in sourcegen :: list_rust_files ( dir) {
87
+ for entry in list_rust_files ( dir) {
84
88
process_file ( & mut res, entry. as_path ( ) ) ;
85
89
}
86
90
let grammar_rs = dir. parent ( ) . unwrap ( ) . join ( "grammar.rs" ) ;
0 commit comments