@@ -22,7 +22,7 @@ use std::borrow::Cow;
2222use std:: collections:: { HashSet , VecDeque } ;
2323use std:: ffi:: OsString ;
2424use std:: num:: NonZeroUsize ;
25- use std:: path:: { Path , PathBuf } ;
25+ use std:: path:: { Component , Path , PathBuf , Prefix } ;
2626use std:: process:: { Command , ExitStatus } ;
2727use std:: thread;
2828
@@ -205,6 +205,8 @@ pub struct Errored {
205205 errors : Vec < Error > ,
206206 /// The full stderr of the test run.
207207 stderr : Vec < u8 > ,
208+ /// The full stdout of the test run.
209+ stdout : Vec < u8 > ,
208210}
209211
210212struct TestRun {
@@ -290,6 +292,7 @@ pub fn run_tests_generic(
290292 . unwrap( ) ,
291293 ) ] ,
292294 stderr : vec ! [ ] ,
295+ stdout : vec ! [ ] ,
293296 } ) ,
294297 status,
295298 } ) ?;
@@ -332,10 +335,11 @@ pub fn run_tests_generic(
332335 command,
333336 errors,
334337 stderr,
338+ stdout,
335339 } ,
336340 ) in & failures
337341 {
338- let _guard = status. failed_test ( command, stderr) ;
342+ let _guard = status. failed_test ( command, stderr, stdout ) ;
339343 failure_emitter. test_failure ( status, errors) ;
340344 }
341345
@@ -434,6 +438,7 @@ fn parse_comments(file_contents: &[u8]) -> Result<Comments, Errored> {
434438 command : Command :: new ( "parse comments" ) ,
435439 errors,
436440 stderr : vec ! [ ] ,
441+ stdout : vec ! [ ] ,
437442 } ) ,
438443 }
439444}
@@ -476,7 +481,12 @@ fn build_aux(
476481 config : & Config ,
477482 build_manager : & BuildManager < ' _ > ,
478483) -> std:: result:: Result < Vec < OsString > , Errored > {
479- let file_contents = std:: fs:: read ( aux_file) . unwrap ( ) ;
484+ let file_contents = std:: fs:: read ( aux_file) . map_err ( |err| Errored {
485+ command : Command :: new ( format ! ( "reading aux file `{}`" , aux_file. display( ) ) ) ,
486+ errors : vec ! [ ] ,
487+ stderr : err. to_string ( ) . into_bytes ( ) ,
488+ stdout : vec ! [ ] ,
489+ } ) ?;
480490 let comments = parse_comments ( & file_contents) ?;
481491 assert_eq ! (
482492 comments. revisions, None ,
@@ -509,7 +519,7 @@ fn build_aux(
509519
510520 // Put aux builds into a separate directory per path so that multiple aux files
511521 // from different directories (but with the same file name) don't collide.
512- let relative = config . strip_path_prefix ( aux_file. parent ( ) . unwrap ( ) ) ;
522+ let relative = strip_path_prefix ( aux_file. parent ( ) . unwrap ( ) , & config . out_dir ) ;
513523
514524 config. out_dir . extend ( relative) ;
515525
@@ -537,6 +547,7 @@ fn build_aux(
537547 command : aux_cmd,
538548 errors : vec ! [ error] ,
539549 stderr : rustc_stderr:: process ( aux_file, & output. stderr ) . rendered ,
550+ stdout : output. stdout ,
540551 } ) ;
541552 }
542553
@@ -601,14 +612,17 @@ impl dyn TestStatus {
601612 "test panicked: stderr:\n {stderr}\n stdout:\n {stdout}" ,
602613 ) ) ] ,
603614 stderr : vec ! [ ] ,
615+ stdout : vec ! [ ] ,
604616 } ) ;
605617 }
606618 }
607619 }
608620 check_test_result (
609- cmd, * mode, path, config, revision, comments, status, stdout, & stderr,
621+ cmd, * mode, path, config, revision, comments, status, & stdout, & stderr,
622+ ) ?;
623+ run_rustfix (
624+ & stderr, & stdout, path, comments, revision, config, * mode, extra_args,
610625 ) ?;
611- run_rustfix ( & stderr, path, comments, revision, config, * mode, extra_args) ?;
612626 Ok ( TestOk :: Ok )
613627 }
614628
@@ -647,9 +661,19 @@ fn build_aux_files(
647661 build_manager
648662 . build (
649663 Build :: Aux {
650- aux_file : config
651- . strip_path_prefix ( & aux_file. canonicalize ( ) . unwrap ( ) )
652- . collect ( ) ,
664+ aux_file : strip_path_prefix (
665+ & aux_file. canonicalize ( ) . map_err ( |err| Errored {
666+ command : Command :: new ( format ! (
667+ "canonicalizing path `{}`" ,
668+ aux_file. display( )
669+ ) ) ,
670+ errors : vec ! [ ] ,
671+ stderr : err. to_string ( ) . into_bytes ( ) ,
672+ stdout : vec ! [ ] ,
673+ } ) ?,
674+ & std:: env:: current_dir ( ) . unwrap ( ) ,
675+ )
676+ . collect ( ) ,
653677 } ,
654678 config,
655679 )
@@ -658,6 +682,7 @@ fn build_aux_files(
658682 command,
659683 errors,
660684 stderr,
685+ stdout,
661686 } | Errored {
662687 command,
663688 errors : vec ! [ Error :: Aux {
@@ -666,6 +691,7 @@ fn build_aux_files(
666691 line,
667692 } ] ,
668693 stderr,
694+ stdout,
669695 } ,
670696 ) ?,
671697 ) ;
@@ -714,12 +740,14 @@ fn run_test_binary(
714740 command : exe,
715741 errors,
716742 stderr : vec ! [ ] ,
743+ stdout : vec ! [ ] ,
717744 } )
718745 }
719746}
720747
721748fn run_rustfix (
722749 stderr : & [ u8 ] ,
750+ stdout : & [ u8 ] ,
723751 path : & Path ,
724752 comments : & Comments ,
725753 revision : & str ,
@@ -773,6 +801,7 @@ fn run_rustfix(
773801 command : Command :: new ( format ! ( "rustfix {}" , path. display( ) ) ) ,
774802 errors : vec ! [ Error :: Rustfix ( err) ] ,
775803 stderr : stderr. into ( ) ,
804+ stdout : stdout. into ( ) ,
776805 } ) ?;
777806
778807 let edition = comments. edition ( revision, config) ?;
@@ -836,6 +865,7 @@ fn run_rustfix(
836865 command : Command :: new ( format ! ( "checking {}" , path. display( ) ) ) ,
837866 errors,
838867 stderr : vec ! [ ] ,
868+ stdout : vec ! [ ] ,
839869 } ) ;
840870 }
841871
@@ -864,6 +894,7 @@ fn run_rustfix(
864894 status: output. status,
865895 } ] ,
866896 stderr : rustc_stderr:: process ( & rustfix_path, & output. stderr ) . rendered ,
897+ stdout : output. stdout ,
867898 } )
868899 }
869900}
@@ -884,7 +915,7 @@ fn check_test_result(
884915 revision : & str ,
885916 comments : & Comments ,
886917 status : ExitStatus ,
887- stdout : Vec < u8 > ,
918+ stdout : & [ u8 ] ,
888919 stderr : & [ u8 ] ,
889920) -> Result < ( ) , Errored > {
890921 let mut errors = vec ! [ ] ;
@@ -897,7 +928,7 @@ fn check_test_result(
897928 revision,
898929 config,
899930 comments,
900- & stdout,
931+ stdout,
901932 & diagnostics. rendered ,
902933 ) ;
903934 // Check error annotations in the source against output
@@ -917,6 +948,7 @@ fn check_test_result(
917948 command,
918949 errors,
919950 stderr : diagnostics. rendered ,
951+ stdout : stdout. into ( ) ,
920952 } )
921953 }
922954}
@@ -1202,3 +1234,24 @@ fn normalize(
12021234 }
12031235 text
12041236}
1237+ /// Remove the common prefix of this path and the `root_dir`.
1238+ fn strip_path_prefix < ' a > ( path : & ' a Path , prefix : & Path ) -> impl Iterator < Item = Component < ' a > > {
1239+ let mut components = path. components ( ) ;
1240+ for c in prefix. components ( ) {
1241+ // Windows has some funky paths. This is probably wrong, but works well in practice.
1242+ let deverbatimize = |c| match c {
1243+ Component :: Prefix ( prefix) => Err ( match prefix. kind ( ) {
1244+ Prefix :: VerbatimUNC ( a, b) => Prefix :: UNC ( a, b) ,
1245+ Prefix :: VerbatimDisk ( d) => Prefix :: Disk ( d) ,
1246+ other => other,
1247+ } ) ,
1248+ c => Ok ( c) ,
1249+ } ;
1250+ let c2 = components. next ( ) ;
1251+ if Some ( deverbatimize ( c) ) == c2. map ( deverbatimize) {
1252+ continue ;
1253+ }
1254+ return c2. into_iter ( ) . chain ( components) ;
1255+ }
1256+ None . into_iter ( ) . chain ( components)
1257+ }
0 commit comments