@@ -6,20 +6,21 @@ use std::fs::{File, create_dir_all, remove_dir_all};
66use std:: io:: { BufRead , Write } ;
77use std:: process:: Command ;
88
9- pub ( crate ) const RAW_OUTPUT_DIR : & str = "crates/squawk_parser/tests/data/raw_regression_suite" ;
109const PROCESSED_OUTPUT_DIR : & str = "crates/squawk_parser/tests/data/regression_suite" ;
1110
1211pub ( crate ) fn download_regression_tests ( ) -> Result < ( ) > {
13- // download_raw_regression_suite ()?;
14- transform_regression_suite ( ) ?;
12+ let temp_dir = download_regression_suite ( ) ?;
13+ transform_regression_suite ( & temp_dir ) ?;
1514 Ok ( ( ) )
1615}
1716
18- fn download_raw_regression_suite ( ) -> Result < ( ) > {
19- let target_dir = project_root ( ) . join ( RAW_OUTPUT_DIR ) ;
17+ fn download_regression_suite ( ) -> Result < Utf8PathBuf > {
18+ let target_dir = Utf8PathBuf :: from_path_buf ( std:: env:: temp_dir ( ) )
19+ . unwrap ( )
20+ . join ( "squawk_raw_regression_suite" ) ;
2021
2122 if target_dir. exists ( ) {
22- println ! ( "Cleaning target directory: {target_dir:?}" ) ;
23+ println ! ( "Cleaning temp directory: {target_dir:?}" ) ;
2324 remove_dir_all ( & target_dir) ?;
2425 }
2526
@@ -49,26 +50,14 @@ fn download_raw_regression_suite() -> Result<()> {
4950 let error_msg = String :: from_utf8_lossy ( & output. stderr ) ;
5051 bail ! ( "Failed to download '{}': {}" , url, error_msg) ;
5152 }
52-
53- // let mut processed_content = Vec::new();
54-
55- // let cursor = Cursor::new(&output.stdout);
56-
57- // if let Err(e) = preprocess_sql(cursor, &mut processed_content) {
58- // eprintln!("Error: Failed to process file: {e}");
59- // continue;
60- // }
61- let processed_content = output. stdout ;
62-
6353 let mut dest = File :: create ( & filepath) ?;
64- dest. write_all ( & processed_content ) ?
54+ dest. write_all ( & output . stdout ) ?
6555 }
6656
67- Ok ( ( ) )
57+ Ok ( target_dir )
6858}
6959
70- fn transform_regression_suite ( ) -> Result < ( ) > {
71- let input_dir = project_root ( ) . join ( RAW_OUTPUT_DIR ) ;
60+ fn transform_regression_suite ( input_dir : & Utf8PathBuf ) -> Result < ( ) > {
7261 let output_dir = project_root ( ) . join ( PROCESSED_OUTPUT_DIR ) ;
7362
7463 if output_dir. exists ( ) {
@@ -79,7 +68,7 @@ fn transform_regression_suite() -> Result<()> {
7968 create_dir_all ( & output_dir) ?;
8069
8170 let mut files: Vec < Utf8PathBuf > = vec ! [ ] ;
82- for entry in std:: fs:: read_dir ( & input_dir) ? {
71+ for entry in std:: fs:: read_dir ( input_dir) ? {
8372 let entry = entry?;
8473 let path = Utf8PathBuf :: try_from ( entry. path ( ) ) ?;
8574 if path. extension ( ) == Some ( "sql" ) {
@@ -113,7 +102,6 @@ fn transform_regression_suite() -> Result<()> {
113102}
114103
115104fn fetch_download_urls ( ) -> Result < Vec < String > > {
116- // Fetch list of SQL file URLs
117105 println ! ( "Fetching SQL file URLs..." ) ;
118106 let output = Command :: new ( "gh" )
119107 . args ( [
@@ -169,7 +157,7 @@ pub(crate) fn preprocess_sql<R: BufRead, W: Write>(source: R, mut dest: W) -> Re
169157
170158 let template_vars_regex = Regex :: new ( r"^:'([^']+)'|^:([a-zA-Z_][a-zA-Z0-9_]*)" ) . unwrap ( ) ;
171159
172- for ( idx , line) in source. lines ( ) . enumerate ( ) {
160+ for line in source. lines ( ) {
173161 let mut line = line?;
174162
175163 if line. contains ( "bogus cases" ) {
@@ -419,8 +407,6 @@ pub(crate) fn preprocess_sql<R: BufRead, W: Write>(source: R, mut dest: W) -> Re
419407 let m = caps. get ( 1 ) . or_else ( || caps. get ( 2 ) ) . unwrap ( ) ;
420408 let matched_var = & remaining[ m. start ( ) ..m. end ( ) ] ;
421409
422- println ! ( "#{idx} Replacing template variable {matched_var}" ) ;
423-
424410 result. push ( '\'' ) ;
425411 result. push_str ( matched_var) ;
426412 result. push ( '\'' ) ;
0 commit comments