@@ -8,16 +8,20 @@ use std::{
88 path:: { Path , PathBuf } ,
99} ;
1010
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" ) ) ;
1418 let tests = tests_from_dir ( & grammar_dir) ;
1519
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 ) ;
1822
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) ;
2125 if !tests_dir. is_dir ( ) {
2226 fs:: create_dir_all ( & tests_dir) . unwrap ( ) ;
2327 }
@@ -37,7 +41,7 @@ fn sourcegen_parser_tests() {
3741 tests_dir. join ( file_name)
3842 }
3943 } ;
40- sourcegen :: ensure_file_contents ( & path, & test. text ) ;
44+ ensure_file_contents ( crate :: flags :: CodegenType :: ParserTests , & path, & test. text , check ) ;
4145 }
4246 }
4347}
@@ -57,7 +61,7 @@ struct Tests {
5761
5862fn collect_tests ( s : & str ) -> Vec < Test > {
5963 let mut res = Vec :: new ( ) ;
60- for comment_block in sourcegen :: CommentBlock :: extract_untagged ( s) {
64+ for comment_block in CommentBlock :: extract_untagged ( s) {
6165 let first_line = & comment_block. contents [ 0 ] ;
6266 let ( name, ok) = if let Some ( name) = first_line. strip_prefix ( "test " ) {
6367 ( name. to_owned ( ) , true )
@@ -80,7 +84,7 @@ fn collect_tests(s: &str) -> Vec<Test> {
8084
8185fn tests_from_dir ( dir : & Path ) -> Tests {
8286 let mut res = Tests :: default ( ) ;
83- for entry in sourcegen :: list_rust_files ( dir) {
87+ for entry in list_rust_files ( dir) {
8488 process_file ( & mut res, entry. as_path ( ) ) ;
8589 }
8690 let grammar_rs = dir. parent ( ) . unwrap ( ) . join ( "grammar.rs" ) ;
0 commit comments