11use std:: fs;
2+ use std:: path:: Path ;
23
34pub struct MiroptTestFiles {
45 pub expected_file : std:: path:: PathBuf ,
@@ -8,18 +9,52 @@ pub struct MiroptTestFiles {
89 pub passes : Vec < String > ,
910}
1011
11- pub fn files_for_miropt_test ( testfile : & std:: path:: Path , bit_width : u32 ) -> Vec < MiroptTestFiles > {
12+ pub enum PanicStrategy {
13+ Unwind ,
14+ Abort ,
15+ }
16+
17+ pub fn output_file_suffix (
18+ testfile : & Path ,
19+ bit_width : u32 ,
20+ panic_strategy : PanicStrategy ,
21+ ) -> String {
22+ let mut each_bit_width = false ;
23+ let mut each_panic_strategy = false ;
24+ for line in fs:: read_to_string ( testfile) . unwrap ( ) . lines ( ) {
25+ if line == "// EMIT_MIR_FOR_EACH_BIT_WIDTH" {
26+ each_bit_width = true ;
27+ }
28+ if line == "// EMIT_MIR_FOR_EACH_PANIC_STRATEGY" {
29+ each_panic_strategy = true ;
30+ }
31+ }
32+
33+ let mut suffix = String :: new ( ) ;
34+ if each_bit_width {
35+ suffix. push_str ( & format ! ( ".{}bit" , bit_width) ) ;
36+ }
37+ if each_panic_strategy {
38+ match panic_strategy {
39+ PanicStrategy :: Unwind => suffix. push_str ( ".panic-unwind" ) ,
40+ PanicStrategy :: Abort => suffix. push_str ( ".panic-abort" ) ,
41+ }
42+ }
43+ suffix
44+ }
45+
46+ pub fn files_for_miropt_test (
47+ testfile : & std:: path:: Path ,
48+ bit_width : u32 ,
49+ panic_strategy : PanicStrategy ,
50+ ) -> Vec < MiroptTestFiles > {
1251 let mut out = Vec :: new ( ) ;
1352 let test_file_contents = fs:: read_to_string ( & testfile) . unwrap ( ) ;
1453
1554 let test_dir = testfile. parent ( ) . unwrap ( ) ;
1655 let test_crate = testfile. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . replace ( '-' , "_" ) ;
1756
18- let bit_width = if test_file_contents. lines ( ) . any ( |l| l == "// EMIT_MIR_FOR_EACH_BIT_WIDTH" ) {
19- format ! ( ".{}bit" , bit_width)
20- } else {
21- String :: new ( )
22- } ;
57+ let suffix = output_file_suffix ( testfile, bit_width, panic_strategy) ;
2358
2459 for l in test_file_contents. lines ( ) {
2560 if l. starts_with ( "// EMIT_MIR " ) {
@@ -37,7 +72,7 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<
3772 passes. push ( trimmed. split ( '.' ) . last ( ) . unwrap ( ) . to_owned ( ) ) ;
3873 let test_against = format ! ( "{}.after.mir" , trimmed) ;
3974 from_file = format ! ( "{}.before.mir" , trimmed) ;
40- expected_file = format ! ( "{}{}.diff" , trimmed, bit_width ) ;
75+ expected_file = format ! ( "{}{}.diff" , trimmed, suffix ) ;
4176 assert ! ( test_names. next( ) . is_none( ) , "two mir pass names specified for MIR diff" ) ;
4277 to_file = Some ( test_against) ;
4378 } else if let Some ( first_pass) = test_names. next ( ) {
@@ -51,7 +86,7 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<
5186 assert ! ( test_names. next( ) . is_none( ) , "three mir pass names specified for MIR diff" ) ;
5287
5388 expected_file =
54- format ! ( "{}{}.{}-{}.diff" , test_name, bit_width , first_pass, second_pass) ;
89+ format ! ( "{}{}.{}-{}.diff" , test_name, suffix , first_pass, second_pass) ;
5590 let second_file = format ! ( "{}.{}.mir" , test_name, second_pass) ;
5691 from_file = format ! ( "{}.{}.mir" , test_name, first_pass) ;
5792 to_file = Some ( second_file) ;
@@ -64,7 +99,7 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<
6499 let extension = cap. get ( 1 ) . unwrap ( ) . as_str ( ) ;
65100
66101 expected_file =
67- format ! ( "{}{}{}" , test_name. trim_end_matches( extension) , bit_width , extension, ) ;
102+ format ! ( "{}{}{}" , test_name. trim_end_matches( extension) , suffix , extension, ) ;
68103 from_file = test_name. to_string ( ) ;
69104 assert ! ( test_names. next( ) . is_none( ) , "two mir pass names specified for MIR dump" ) ;
70105 to_file = None ;
0 commit comments