11// ignore-tidy-filelength
22
3+ use crate :: compute_diff:: { write_diff, write_filtered_diff} ;
4+ use crate :: errors:: { self , Error , ErrorKind } ;
5+ use crate :: header:: TestProps ;
6+ use crate :: json;
7+ use crate :: read2:: { read2_abbreviated, Truncated } ;
8+ use crate :: util:: { add_dylib_path, copy_dir_all, dylib_env_var, logv, static_regex, PathBufExt } ;
9+ use crate :: ColorConfig ;
10+ use colored:: Colorize ;
11+ use miropt_test_tools:: { files_for_miropt_test, MiroptTest , MiroptTestFile } ;
12+ use regex:: { Captures , Regex } ;
13+ use rustfix:: { apply_suggestions, get_suggestions_from_json, Filter } ;
14+ use std:: borrow:: Cow ;
315use std:: collections:: { HashMap , HashSet } ;
416use std:: ffi:: { OsStr , OsString } ;
517use std:: fs:: { self , create_dir_all, File , OpenOptions } ;
@@ -723,7 +735,7 @@ impl<'test> TestCx<'test> {
723735 self . maybe_add_external_args ( & mut rustc, & self . config . target_rustcflags ) ;
724736 rustc. args ( & self . props . compile_flags ) ;
725737
726- self . compose_and_run_compiler ( rustc, Some ( src) )
738+ self . compose_and_run_compiler ( rustc, Some ( src) , self . testpaths )
727739 }
728740
729741 fn run_debuginfo_test ( & self ) {
@@ -1579,13 +1591,15 @@ impl<'test> TestCx<'test> {
15791591 passes,
15801592 ) ;
15811593
1582- self . compose_and_run_compiler ( rustc, None )
1594+ self . compose_and_run_compiler ( rustc, None , self . testpaths )
15831595 }
15841596
1585- fn document ( & self , out_dir : & Path ) -> ProcRes {
1597+ /// `root_out_dir` and `root_testpaths` refer to the parameters of the actual test being run.
1598+ /// Auxiliaries, no matter how deep, have the same root_out_dir and root_testpaths.
1599+ fn document ( & self , root_out_dir : & Path , root_testpaths : & TestPaths ) -> ProcRes {
15861600 if self . props . build_aux_docs {
15871601 for rel_ab in & self . props . aux_builds {
1588- let aux_testpaths = self . compute_aux_test_paths ( & self . testpaths , rel_ab) ;
1602+ let aux_testpaths = self . compute_aux_test_paths ( root_testpaths , rel_ab) ;
15891603 let aux_props =
15901604 self . props . from_aux_file ( & aux_testpaths. file , self . revision , self . config ) ;
15911605 let aux_cx = TestCx {
@@ -1596,7 +1610,7 @@ impl<'test> TestCx<'test> {
15961610 } ;
15971611 // Create the directory for the stdout/stderr files.
15981612 create_dir_all ( aux_cx. output_base_dir ( ) ) . unwrap ( ) ;
1599- let auxres = aux_cx. document ( out_dir ) ;
1613+ let auxres = aux_cx. document ( & root_out_dir , root_testpaths ) ;
16001614 if !auxres. status . success ( ) {
16011615 return auxres;
16021616 }
@@ -1606,21 +1620,47 @@ impl<'test> TestCx<'test> {
16061620 let aux_dir = self . aux_output_dir_name ( ) ;
16071621
16081622 let rustdoc_path = self . config . rustdoc_path . as_ref ( ) . expect ( "--rustdoc-path not passed" ) ;
1609- let mut rustdoc = Command :: new ( rustdoc_path) ;
16101623
1624+ // actual --out-dir given to the auxiliary or test, as opposed to the root out dir for the entire
1625+ // test
1626+ let out_dir: Cow < ' _ , Path > = if self . props . unique_doc_out_dir {
1627+ let file_name = self
1628+ . testpaths
1629+ . file
1630+ . file_name ( )
1631+ . expect ( "file name should not be empty" )
1632+ . to_str ( )
1633+ . expect ( "file name utf8" )
1634+ . trim_end_matches ( ".rs" ) ;
1635+ let out_dir = PathBuf :: from_iter ( [
1636+ root_out_dir,
1637+ Path :: new ( "docs" ) ,
1638+ Path :: new ( file_name) ,
1639+ Path :: new ( "doc" ) ,
1640+ ] ) ;
1641+ create_dir_all ( & out_dir) . unwrap ( ) ;
1642+ Cow :: Owned ( out_dir)
1643+ } else {
1644+ Cow :: Borrowed ( root_out_dir)
1645+ } ;
1646+
1647+ let mut rustdoc = Command :: new ( rustdoc_path) ;
1648+ let current_dir = output_base_dir ( self . config , root_testpaths, self . safe_revision ( ) ) ;
1649+ rustdoc. current_dir ( current_dir) ;
16111650 rustdoc
16121651 . arg ( "-L" )
16131652 . arg ( self . config . run_lib_path . to_str ( ) . unwrap ( ) )
16141653 . arg ( "-L" )
16151654 . arg ( aux_dir)
16161655 . arg ( "-o" )
1617- . arg ( out_dir)
1656+ . arg ( out_dir. as_ref ( ) )
16181657 . arg ( "--deny" )
16191658 . arg ( "warnings" )
16201659 . arg ( & self . testpaths . file )
16211660 . arg ( "-A" )
16221661 . arg ( "internal_features" )
1623- . args ( & self . props . compile_flags ) ;
1662+ . args ( & self . props . compile_flags )
1663+ . args ( & self . props . doc_flags ) ;
16241664
16251665 if self . config . mode == RustdocJson {
16261666 rustdoc. arg ( "--output-format" ) . arg ( "json" ) . arg ( "-Zunstable-options" ) ;
@@ -1630,7 +1670,7 @@ impl<'test> TestCx<'test> {
16301670 rustdoc. arg ( format ! ( "-Clinker={}" , linker) ) ;
16311671 }
16321672
1633- self . compose_and_run_compiler ( rustdoc, None )
1673+ self . compose_and_run_compiler ( rustdoc, None , root_testpaths )
16341674 }
16351675
16361676 fn exec_compiled_test ( & self ) -> ProcRes {
@@ -1828,9 +1868,16 @@ impl<'test> TestCx<'test> {
18281868 }
18291869 }
18301870
1831- fn compose_and_run_compiler ( & self , mut rustc : Command , input : Option < String > ) -> ProcRes {
1871+ /// `root_testpaths` refers to the path of the original test.
1872+ /// the auxiliary and the test with an aux-build have the same `root_testpaths`.
1873+ fn compose_and_run_compiler (
1874+ & self ,
1875+ mut rustc : Command ,
1876+ input : Option < String > ,
1877+ root_testpaths : & TestPaths ,
1878+ ) -> ProcRes {
18321879 let aux_dir = self . aux_output_dir ( ) ;
1833- self . build_all_auxiliary ( & self . testpaths , & aux_dir, & mut rustc) ;
1880+ self . build_all_auxiliary ( root_testpaths , & aux_dir, & mut rustc) ;
18341881
18351882 rustc. envs ( self . props . rustc_env . clone ( ) ) ;
18361883 self . props . unset_rustc_env . iter ( ) . fold ( & mut rustc, Command :: env_remove) ;
@@ -2545,7 +2592,7 @@ impl<'test> TestCx<'test> {
25452592 Vec :: new ( ) ,
25462593 ) ;
25472594
2548- let proc_res = self . compose_and_run_compiler ( rustc, None ) ;
2595+ let proc_res = self . compose_and_run_compiler ( rustc, None , self . testpaths ) ;
25492596 let output_path = self . get_filecheck_file ( "ll" ) ;
25502597 ( proc_res, output_path)
25512598 }
@@ -2581,7 +2628,7 @@ impl<'test> TestCx<'test> {
25812628 Vec :: new ( ) ,
25822629 ) ;
25832630
2584- let proc_res = self . compose_and_run_compiler ( rustc, None ) ;
2631+ let proc_res = self . compose_and_run_compiler ( rustc, None , self . testpaths ) ;
25852632 let output_path = self . get_filecheck_file ( "s" ) ;
25862633 ( proc_res, output_path)
25872634 }
@@ -2664,7 +2711,7 @@ impl<'test> TestCx<'test> {
26642711 let out_dir = self . output_base_dir ( ) ;
26652712 remove_and_create_dir_all ( & out_dir) ;
26662713
2667- let proc_res = self . document ( & out_dir) ;
2714+ let proc_res = self . document ( & out_dir, & self . testpaths ) ;
26682715 if !proc_res. status . success ( ) {
26692716 self . fatal_proc_rec ( "rustdoc failed!" , & proc_res) ;
26702717 }
@@ -2723,7 +2770,7 @@ impl<'test> TestCx<'test> {
27232770 let aux_dir = new_rustdoc. aux_output_dir ( ) ;
27242771 new_rustdoc. build_all_auxiliary ( & new_rustdoc. testpaths , & aux_dir, & mut rustc) ;
27252772
2726- let proc_res = new_rustdoc. document ( & compare_dir) ;
2773+ let proc_res = new_rustdoc. document ( & compare_dir, & new_rustdoc . testpaths ) ;
27272774 if !proc_res. status . success ( ) {
27282775 eprintln ! ( "failed to run nightly rustdoc" ) ;
27292776 return ;
@@ -2846,7 +2893,7 @@ impl<'test> TestCx<'test> {
28462893 let out_dir = self . output_base_dir ( ) ;
28472894 remove_and_create_dir_all ( & out_dir) ;
28482895
2849- let proc_res = self . document ( & out_dir) ;
2896+ let proc_res = self . document ( & out_dir, & self . testpaths ) ;
28502897 if !proc_res. status . success ( ) {
28512898 self . fatal_proc_rec ( "rustdoc failed!" , & proc_res) ;
28522899 }
@@ -2922,24 +2969,15 @@ impl<'test> TestCx<'test> {
29222969 fn check_rustdoc_test_option ( & self , res : ProcRes ) {
29232970 let mut other_files = Vec :: new ( ) ;
29242971 let mut files: HashMap < String , Vec < usize > > = HashMap :: new ( ) ;
2925- let cwd = env:: current_dir ( ) . unwrap ( ) ;
2926- files. insert (
2927- self . testpaths
2928- . file
2929- . strip_prefix ( & cwd)
2930- . unwrap_or ( & self . testpaths . file )
2931- . to_str ( )
2932- . unwrap ( )
2933- . replace ( '\\' , "/" ) ,
2934- self . get_lines ( & self . testpaths . file , Some ( & mut other_files) ) ,
2935- ) ;
2972+ let normalized = fs:: canonicalize ( & self . testpaths . file ) . expect ( "failed to canonicalize" ) ;
2973+ let normalized = normalized. to_str ( ) . unwrap ( ) . replace ( '\\' , "/" ) ;
2974+ files. insert ( normalized, self . get_lines ( & self . testpaths . file , Some ( & mut other_files) ) ) ;
29362975 for other_file in other_files {
29372976 let mut path = self . testpaths . file . clone ( ) ;
29382977 path. set_file_name ( & format ! ( "{}.rs" , other_file) ) ;
2939- files. insert (
2940- path. strip_prefix ( & cwd) . unwrap_or ( & path) . to_str ( ) . unwrap ( ) . replace ( '\\' , "/" ) ,
2941- self . get_lines ( & path, None ) ,
2942- ) ;
2978+ let path = fs:: canonicalize ( path) . expect ( "failed to canonicalize" ) ;
2979+ let normalized = path. to_str ( ) . unwrap ( ) . replace ( '\\' , "/" ) ;
2980+ files. insert ( normalized, self . get_lines ( & path, None ) ) ;
29432981 }
29442982
29452983 let mut tested = 0 ;
@@ -3778,7 +3816,7 @@ impl<'test> TestCx<'test> {
37783816 if let Some ( nodejs) = & self . config . nodejs {
37793817 let out_dir = self . output_base_dir ( ) ;
37803818
3781- self . document ( & out_dir) ;
3819+ self . document ( & out_dir, & self . testpaths ) ;
37823820
37833821 let root = self . config . find_rust_src_root ( ) . unwrap ( ) ;
37843822 let file_stem =
@@ -4094,7 +4132,7 @@ impl<'test> TestCx<'test> {
40944132 rustc. arg ( crate_name) ;
40954133 }
40964134
4097- let res = self . compose_and_run_compiler ( rustc, None ) ;
4135+ let res = self . compose_and_run_compiler ( rustc, None , self . testpaths ) ;
40984136 if !res. status . success ( ) {
40994137 self . fatal_proc_rec ( "failed to compile fixed code" , & res) ;
41004138 }
0 commit comments