@@ -21,7 +21,6 @@ use std::collections::hash_map::DefaultHasher;
2121use std:: collections:: { HashMap , HashSet , VecDeque } ;
2222use std:: env;
2323use std:: ffi:: { OsStr , OsString } ;
24- use std:: fmt;
2524use std:: fs:: { self , create_dir_all, File , OpenOptions } ;
2625use std:: hash:: { Hash , Hasher } ;
2726use std:: io:: prelude:: * ;
@@ -3156,36 +3155,6 @@ impl<'test> TestCx<'test> {
31563155 }
31573156 }
31583157 }
3159-
3160- if let Some ( idx) = test_file_contents. find ( "// END RUST SOURCE" ) {
3161- let ( _, tests_text) = test_file_contents. split_at ( idx + "// END_RUST SOURCE" . len ( ) ) ;
3162- let tests_text_str = String :: from ( tests_text) ;
3163- let mut curr_test: Option < & str > = None ;
3164- let mut curr_test_contents = vec ! [ ExpectedLine :: Elision ] ;
3165- for l in tests_text_str. lines ( ) {
3166- debug ! ( "line: {:?}" , l) ;
3167- if l. starts_with ( "// START " ) {
3168- let ( _, t) = l. split_at ( "// START " . len ( ) ) ;
3169- curr_test = Some ( t) ;
3170- } else if l. starts_with ( "// END" ) {
3171- let ( _, t) = l. split_at ( "// END " . len ( ) ) ;
3172- if Some ( t) != curr_test {
3173- panic ! ( "mismatched START END test name" ) ;
3174- }
3175- self . compare_mir_test_output ( curr_test. unwrap ( ) , & curr_test_contents) ;
3176- curr_test = None ;
3177- curr_test_contents. clear ( ) ;
3178- curr_test_contents. push ( ExpectedLine :: Elision ) ;
3179- } else if l. is_empty ( ) {
3180- // ignore
3181- } else if l. starts_with ( "//" ) && l. split_at ( "//" . len ( ) ) . 1 . trim ( ) == "..." {
3182- curr_test_contents. push ( ExpectedLine :: Elision )
3183- } else if l. starts_with ( "// " ) {
3184- let ( _, test_content) = l. split_at ( "// " . len ( ) ) ;
3185- curr_test_contents. push ( ExpectedLine :: Text ( test_content) ) ;
3186- }
3187- }
3188- }
31893158 }
31903159
31913160 fn check_mir_test_timestamp ( & self , test_name : & str , output_file : & Path ) {
@@ -3203,107 +3172,6 @@ impl<'test> TestCx<'test> {
32033172 }
32043173 }
32053174
3206- fn compare_mir_test_output ( & self , test_name : & str , expected_content : & [ ExpectedLine < & str > ] ) {
3207- let mut output_file = PathBuf :: new ( ) ;
3208- output_file. push ( self . get_mir_dump_dir ( ) ) ;
3209- output_file. push ( test_name) ;
3210- debug ! ( "comparing the contents of: {:?}" , output_file) ;
3211- debug ! ( "with: {:?}" , expected_content) ;
3212- if !output_file. exists ( ) {
3213- panic ! ( "Output file `{}` from test does not exist" , output_file. display( ) ) ;
3214- }
3215- self . check_mir_test_timestamp ( test_name, & output_file) ;
3216-
3217- let dumped_string = fs:: read_to_string ( & output_file) . unwrap ( ) ;
3218- let mut dumped_lines =
3219- dumped_string. lines ( ) . map ( |l| nocomment_mir_line ( l) ) . filter ( |l| !l. is_empty ( ) ) ;
3220- let mut expected_lines = expected_content
3221- . iter ( )
3222- . filter ( |& l| if let & ExpectedLine :: Text ( l) = l { !l. is_empty ( ) } else { true } )
3223- . peekable ( ) ;
3224-
3225- let compare = |expected_line, dumped_line| {
3226- let e_norm = normalize_mir_line ( expected_line) ;
3227- let d_norm = normalize_mir_line ( dumped_line) ;
3228- debug ! ( "found: {:?}" , d_norm) ;
3229- debug ! ( "expected: {:?}" , e_norm) ;
3230- e_norm == d_norm
3231- } ;
3232-
3233- let error = |expected_line, extra_msg| {
3234- let normalize_all = dumped_string
3235- . lines ( )
3236- . map ( nocomment_mir_line)
3237- . filter ( |l| !l. is_empty ( ) )
3238- . collect :: < Vec < _ > > ( )
3239- . join ( "\n " ) ;
3240- let f = |l : & ExpectedLine < _ > | match l {
3241- & ExpectedLine :: Elision => "... (elided)" . into ( ) ,
3242- & ExpectedLine :: Text ( t) => t,
3243- } ;
3244- let expected_content =
3245- expected_content. iter ( ) . map ( |l| f ( l) ) . collect :: < Vec < _ > > ( ) . join ( "\n " ) ;
3246- panic ! (
3247- "Did not find expected line, error: {}\n \
3248- Expected Line: {:?}\n \
3249- Test Name: {}\n \
3250- Expected:\n {}\n \
3251- Actual:\n {}",
3252- extra_msg, expected_line, test_name, expected_content, normalize_all
3253- ) ;
3254- } ;
3255-
3256- // We expect each non-empty line to appear consecutively, non-consecutive lines
3257- // must be separated by at least one Elision
3258- let mut start_block_line = None ;
3259- while let Some ( dumped_line) = dumped_lines. next ( ) {
3260- match expected_lines. next ( ) {
3261- Some ( & ExpectedLine :: Text ( expected_line) ) => {
3262- let normalized_expected_line = normalize_mir_line ( expected_line) ;
3263- if normalized_expected_line. contains ( ":{" ) {
3264- start_block_line = Some ( expected_line) ;
3265- }
3266-
3267- if !compare ( expected_line, dumped_line) {
3268- error ! ( "{:?}" , start_block_line) ;
3269- error (
3270- expected_line,
3271- format ! (
3272- "Mismatch in lines\n \
3273- Current block: {}\n \
3274- Actual Line: {:?}",
3275- start_block_line. unwrap_or( "None" ) ,
3276- dumped_line
3277- ) ,
3278- ) ;
3279- }
3280- }
3281- Some ( & ExpectedLine :: Elision ) => {
3282- // skip any number of elisions in a row.
3283- while let Some ( & & ExpectedLine :: Elision ) = expected_lines. peek ( ) {
3284- expected_lines. next ( ) ;
3285- }
3286- if let Some ( & ExpectedLine :: Text ( expected_line) ) = expected_lines. next ( ) {
3287- let mut found = compare ( expected_line, dumped_line) ;
3288- if found {
3289- continue ;
3290- }
3291- while let Some ( dumped_line) = dumped_lines. next ( ) {
3292- found = compare ( expected_line, dumped_line) ;
3293- if found {
3294- break ;
3295- }
3296- }
3297- if !found {
3298- error ( expected_line, "ran out of mir dump to match against" . into ( ) ) ;
3299- }
3300- }
3301- }
3302- None => { }
3303- }
3304- }
3305- }
3306-
33073175 fn get_mir_dump_dir ( & self ) -> PathBuf {
33083176 let mut mir_dump_dir = PathBuf :: from ( self . config . build_base . as_path ( ) ) ;
33093177 debug ! ( "input_file: {:?}" , self . testpaths. file) ;
@@ -3589,43 +3457,11 @@ enum TargetLocation {
35893457 ThisDirectory ( PathBuf ) ,
35903458}
35913459
3592- #[ derive( Clone , PartialEq , Eq ) ]
3593- enum ExpectedLine < T : AsRef < str > > {
3594- Elision ,
3595- Text ( T ) ,
3596- }
3597-
35983460enum AllowUnused {
35993461 Yes ,
36003462 No ,
36013463}
36023464
3603- impl < T > fmt:: Debug for ExpectedLine < T >
3604- where
3605- T : AsRef < str > + fmt:: Debug ,
3606- {
3607- fn fmt ( & self , formatter : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
3608- if let & ExpectedLine :: Text ( ref t) = self {
3609- write ! ( formatter, "{:?}" , t)
3610- } else {
3611- write ! ( formatter, "\" ...\" (Elision)" )
3612- }
3613- }
3614- }
3615-
3616- fn normalize_mir_line ( line : & str ) -> String {
3617- nocomment_mir_line ( line) . replace ( char:: is_whitespace, "" )
3618- }
3619-
3620- fn nocomment_mir_line ( line : & str ) -> & str {
3621- if let Some ( idx) = line. find ( "//" ) {
3622- let ( l, _) = line. split_at ( idx) ;
3623- l. trim_end ( )
3624- } else {
3625- line
3626- }
3627- }
3628-
36293465fn read2_abbreviated ( mut child : Child ) -> io:: Result < Output > {
36303466 use crate :: read2:: read2;
36313467 use std:: mem:: replace;
0 commit comments