@@ -6,6 +6,7 @@ use mamba::pipeline::transpile_directory;
66use crate :: common:: { delete_dir, python_src_to_stmts, resource_content, resource_content_path,
77 resource_content_randomize, resource_path} ;
88use crate :: output:: common:: PYTHON ;
9+ use python_parser:: ast:: Statement ;
910
1011mod common;
1112
@@ -17,21 +18,32 @@ fn test_directory(
1718 _output : & [ & str ] ,
1819 file_name : & str
1920) -> Result < ( ) , Vec < String > > {
20- let current_dir_string = resource_path ( valid, input, "" ) ;
21- let current_dir = Path :: new ( & current_dir_string) ;
2221 let ( output_path, output_file) =
2322 resource_content_randomize ( true , input, & format ! ( "{}.py" , file_name) ) ;
2423
24+ let res = fallable ( valid, input, & output_path, & output_file, file_name) ;
25+ delete_dir ( & output_path) . map_err ( |_| vec ! [ ] ) ?;
26+ let ( check_ast, out_ast) = res?;
27+ assert_eq ! ( check_ast, out_ast) ;
28+ Ok ( ( ) )
29+ }
30+
31+ fn fallable (
32+ valid : bool ,
33+ input : & [ & str ] ,
34+ output_path : & str ,
35+ output_file : & str ,
36+ file_name : & str
37+ ) -> Result < ( Vec < Statement > , Vec < Statement > ) , Vec < String > > {
38+ let current_dir_string = resource_path ( valid, input, "" ) ;
39+ let current_dir = Path :: new ( & current_dir_string) ;
40+
2541 let map_err = |( ty, msg) : & ( String , String ) | {
2642 eprintln ! ( "[error | {}] {}" , ty, msg) ;
2743 format ! ( "[error | {}] {}" , ty, msg)
2844 } ;
29- transpile_directory (
30- & current_dir,
31- Some ( & format ! ( "{}.mamba" , file_name) ) ,
32- Some ( output_path. as_str ( ) )
33- )
34- . map_err ( |errs| errs. iter ( ) . map ( & map_err) . collect :: < Vec < String > > ( ) ) ?;
45+ transpile_directory ( & current_dir, Some ( & format ! ( "{}.mamba" , file_name) ) , Some ( output_path) )
46+ . map_err ( |errs| errs. iter ( ) . map ( & map_err) . collect :: < Vec < String > > ( ) ) ?;
3547
3648 let cmd = Command :: new ( PYTHON ) . arg ( "-m" ) . arg ( "py_compile" ) . arg ( & output_file) . output ( ) . unwrap ( ) ;
3749 if cmd. status . code ( ) . unwrap ( ) != 0 {
@@ -40,8 +52,7 @@ fn test_directory(
4052
4153 let check_src = resource_content ( true , input, & format ! ( "{}_check.py" , file_name) ) ;
4254 let check_ast = python_src_to_stmts ( & check_src) ;
43- let out_ast = python_src_to_stmts ( & resource_content_path ( & output_file) ) ;
55+ let out_ast = python_src_to_stmts ( & resource_content_path ( output_file) ) ;
4456
45- assert_eq ! ( out_ast, check_ast) ;
46- delete_dir ( & output_path) . map_err ( |_| vec ! [ ] )
57+ Ok ( ( check_ast, out_ast) )
4758}
0 commit comments