@@ -15,6 +15,7 @@ mod tests {
15
15
use std:: fs;
16
16
use std:: io;
17
17
use std:: path:: Path ;
18
+ use std:: process:: Command ;
18
19
19
20
struct RangesEraser { }
20
21
@@ -38,14 +39,18 @@ mod tests {
38
39
}
39
40
}
40
41
41
- #[ test]
42
- fn test_predefined_files ( ) -> io:: Result < ( ) > {
43
- for entry in fs:: read_dir ( "./test_files" ) ? {
42
+ fn run_tests_on_folders ( source_folder : & str , results_folder : & str ) -> io:: Result < ( ) > {
43
+ for entry in fs:: read_dir ( source_folder) ? {
44
44
let entry = entry?;
45
45
46
46
let entry_path = entry. path ( ) ;
47
47
48
- if entry_path. is_file ( ) {
48
+ if entry_path. is_file ( )
49
+ && entry_path. file_name ( ) . is_some_and ( |name| {
50
+ name. to_str ( )
51
+ . is_some_and ( |inner_name| inner_name. ends_with ( ".py" ) )
52
+ } )
53
+ {
49
54
let file_content = fs:: read_to_string ( & entry_path) ?;
50
55
let entry_path_str = entry_path. to_str ( ) . unwrap ( ) ;
51
56
let mut unparser = Unparser :: new ( ) ;
@@ -56,7 +61,7 @@ mod tests {
56
61
let new_source = unparser. source ;
57
62
let old_file_name = entry_path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
58
63
let new_file_name = old_file_name. replace ( ".py" , "_unparsed.py" ) ;
59
- let new_entry_path_str = format ! ( "./test_files_unparsed/ {}" , new_file_name) ;
64
+ let new_entry_path_str = format ! ( "{}/ {}" , results_folder , new_file_name) ;
60
65
let new_entry_path = Path :: new ( & new_entry_path_str) ;
61
66
fs:: write ( & new_entry_path, & new_source) ?;
62
67
let new_stmts =
@@ -80,4 +85,30 @@ mod tests {
80
85
}
81
86
Ok ( ( ) )
82
87
}
88
+
89
+ #[ test]
90
+ fn test_predefined_files ( ) -> io:: Result < ( ) > {
91
+ run_tests_on_folders ( "./test_files" , "./test_files_unparsed" )
92
+ }
93
+ #[ test]
94
+ #[ ignore = "Fuzzy tests are unstable and should only be used to explore new test cases" ]
95
+ fn test_fuzzy_files ( ) -> io:: Result < ( ) > {
96
+ let seed = rand:: random :: < usize > ( ) ;
97
+
98
+ for i in 0 ..10 {
99
+ let file_name = format ! ( "./fuzzy_test_files/fuzzy_test{}.py" , i) ;
100
+
101
+ let file_content = Command :: new ( ".venv/bin/python" )
102
+ . arg ( "-m" )
103
+ . arg ( "pysource_codegen" )
104
+ . arg ( "--seed" )
105
+ . arg ( & seed. to_string ( ) )
106
+ . output ( )
107
+ . expect ( "failed to execute process" ) ;
108
+ fs:: write ( & file_name, & file_content. stdout ) ?;
109
+ }
110
+
111
+ run_tests_on_folders ( "./fuzzy_test_files" , "./fuzzy_test_files_unparsed" ) ?;
112
+ Ok ( ( ) )
113
+ }
83
114
}
0 commit comments