@@ -22,7 +22,7 @@ use std::borrow::Cow;
22
22
use std:: collections:: { HashSet , VecDeque } ;
23
23
use std:: ffi:: OsString ;
24
24
use std:: num:: NonZeroUsize ;
25
- use std:: path:: { Path , PathBuf } ;
25
+ use std:: path:: { Component , Path , PathBuf , Prefix } ;
26
26
use std:: process:: { Command , ExitStatus } ;
27
27
use std:: thread;
28
28
@@ -205,6 +205,8 @@ pub struct Errored {
205
205
errors : Vec < Error > ,
206
206
/// The full stderr of the test run.
207
207
stderr : Vec < u8 > ,
208
+ /// The full stdout of the test run.
209
+ stdout : Vec < u8 > ,
208
210
}
209
211
210
212
struct TestRun {
@@ -290,6 +292,7 @@ pub fn run_tests_generic(
290
292
. unwrap( ) ,
291
293
) ] ,
292
294
stderr : vec ! [ ] ,
295
+ stdout : vec ! [ ] ,
293
296
} ) ,
294
297
status,
295
298
} ) ?;
@@ -332,10 +335,11 @@ pub fn run_tests_generic(
332
335
command,
333
336
errors,
334
337
stderr,
338
+ stdout,
335
339
} ,
336
340
) in & failures
337
341
{
338
- let _guard = status. failed_test ( command, stderr) ;
342
+ let _guard = status. failed_test ( command, stderr, stdout ) ;
339
343
failure_emitter. test_failure ( status, errors) ;
340
344
}
341
345
@@ -434,6 +438,7 @@ fn parse_comments(file_contents: &[u8]) -> Result<Comments, Errored> {
434
438
command : Command :: new ( "parse comments" ) ,
435
439
errors,
436
440
stderr : vec ! [ ] ,
441
+ stdout : vec ! [ ] ,
437
442
} ) ,
438
443
}
439
444
}
@@ -476,7 +481,12 @@ fn build_aux(
476
481
config : & Config ,
477
482
build_manager : & BuildManager < ' _ > ,
478
483
) -> 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
+ } ) ?;
480
490
let comments = parse_comments ( & file_contents) ?;
481
491
assert_eq ! (
482
492
comments. revisions, None ,
@@ -509,7 +519,7 @@ fn build_aux(
509
519
510
520
// Put aux builds into a separate directory per path so that multiple aux files
511
521
// 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 ) ;
513
523
514
524
config. out_dir . extend ( relative) ;
515
525
@@ -537,6 +547,7 @@ fn build_aux(
537
547
command : aux_cmd,
538
548
errors : vec ! [ error] ,
539
549
stderr : rustc_stderr:: process ( aux_file, & output. stderr ) . rendered ,
550
+ stdout : output. stdout ,
540
551
} ) ;
541
552
}
542
553
@@ -601,14 +612,17 @@ impl dyn TestStatus {
601
612
"test panicked: stderr:\n {stderr}\n stdout:\n {stdout}" ,
602
613
) ) ] ,
603
614
stderr : vec ! [ ] ,
615
+ stdout : vec ! [ ] ,
604
616
} ) ;
605
617
}
606
618
}
607
619
}
608
620
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,
610
625
) ?;
611
- run_rustfix ( & stderr, path, comments, revision, config, * mode, extra_args) ?;
612
626
Ok ( TestOk :: Ok )
613
627
}
614
628
@@ -647,9 +661,19 @@ fn build_aux_files(
647
661
build_manager
648
662
. build (
649
663
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 ( ) ,
653
677
} ,
654
678
config,
655
679
)
@@ -658,6 +682,7 @@ fn build_aux_files(
658
682
command,
659
683
errors,
660
684
stderr,
685
+ stdout,
661
686
} | Errored {
662
687
command,
663
688
errors : vec ! [ Error :: Aux {
@@ -666,6 +691,7 @@ fn build_aux_files(
666
691
line,
667
692
} ] ,
668
693
stderr,
694
+ stdout,
669
695
} ,
670
696
) ?,
671
697
) ;
@@ -714,12 +740,14 @@ fn run_test_binary(
714
740
command : exe,
715
741
errors,
716
742
stderr : vec ! [ ] ,
743
+ stdout : vec ! [ ] ,
717
744
} )
718
745
}
719
746
}
720
747
721
748
fn run_rustfix (
722
749
stderr : & [ u8 ] ,
750
+ stdout : & [ u8 ] ,
723
751
path : & Path ,
724
752
comments : & Comments ,
725
753
revision : & str ,
@@ -773,6 +801,7 @@ fn run_rustfix(
773
801
command : Command :: new ( format ! ( "rustfix {}" , path. display( ) ) ) ,
774
802
errors : vec ! [ Error :: Rustfix ( err) ] ,
775
803
stderr : stderr. into ( ) ,
804
+ stdout : stdout. into ( ) ,
776
805
} ) ?;
777
806
778
807
let edition = comments. edition ( revision, config) ?;
@@ -836,6 +865,7 @@ fn run_rustfix(
836
865
command : Command :: new ( format ! ( "checking {}" , path. display( ) ) ) ,
837
866
errors,
838
867
stderr : vec ! [ ] ,
868
+ stdout : vec ! [ ] ,
839
869
} ) ;
840
870
}
841
871
@@ -864,6 +894,7 @@ fn run_rustfix(
864
894
status: output. status,
865
895
} ] ,
866
896
stderr : rustc_stderr:: process ( & rustfix_path, & output. stderr ) . rendered ,
897
+ stdout : output. stdout ,
867
898
} )
868
899
}
869
900
}
@@ -884,7 +915,7 @@ fn check_test_result(
884
915
revision : & str ,
885
916
comments : & Comments ,
886
917
status : ExitStatus ,
887
- stdout : Vec < u8 > ,
918
+ stdout : & [ u8 ] ,
888
919
stderr : & [ u8 ] ,
889
920
) -> Result < ( ) , Errored > {
890
921
let mut errors = vec ! [ ] ;
@@ -897,7 +928,7 @@ fn check_test_result(
897
928
revision,
898
929
config,
899
930
comments,
900
- & stdout,
931
+ stdout,
901
932
& diagnostics. rendered ,
902
933
) ;
903
934
// Check error annotations in the source against output
@@ -917,6 +948,7 @@ fn check_test_result(
917
948
command,
918
949
errors,
919
950
stderr : diagnostics. rendered ,
951
+ stdout : stdout. into ( ) ,
920
952
} )
921
953
}
922
954
}
@@ -1202,3 +1234,24 @@ fn normalize(
1202
1234
}
1203
1235
text
1204
1236
}
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