@@ -21,6 +21,7 @@ use colored::Colorize;
21
21
use miropt_test_tools:: { files_for_miropt_test, MiroptTest , MiroptTestFile } ;
22
22
use regex:: { Captures , Regex } ;
23
23
use rustfix:: { apply_suggestions, get_suggestions_from_json, Filter } ;
24
+ use std:: borrow:: Cow ;
24
25
use std:: collections:: { HashMap , HashSet } ;
25
26
use std:: env;
26
27
use std:: ffi:: { OsStr , OsString } ;
@@ -731,7 +732,7 @@ impl<'test> TestCx<'test> {
731
732
self . maybe_add_external_args ( & mut rustc, & self . config . target_rustcflags ) ;
732
733
rustc. args ( & self . props . compile_flags ) ;
733
734
734
- self . compose_and_run_compiler ( rustc, Some ( src) )
735
+ self . compose_and_run_compiler ( rustc, Some ( src) , self . testpaths )
735
736
}
736
737
737
738
fn run_debuginfo_test ( & self ) {
@@ -1587,13 +1588,15 @@ impl<'test> TestCx<'test> {
1587
1588
passes,
1588
1589
) ;
1589
1590
1590
- self . compose_and_run_compiler ( rustc, None )
1591
+ self . compose_and_run_compiler ( rustc, None , self . testpaths )
1591
1592
}
1592
1593
1593
- fn document ( & self , out_dir : & Path ) -> ProcRes {
1594
+ /// `root_out_dir` and `root_testpaths` refer to the parameters of the actual test being run.
1595
+ /// Auxiliaries, no matter how deep, have the same root_out_dir and root_testpaths.
1596
+ fn document ( & self , root_out_dir : & Path , root_testpaths : & TestPaths ) -> ProcRes {
1594
1597
if self . props . build_aux_docs {
1595
1598
for rel_ab in & self . props . aux_builds {
1596
- let aux_testpaths = self . compute_aux_test_paths ( & self . testpaths , rel_ab) ;
1599
+ let aux_testpaths = self . compute_aux_test_paths ( root_testpaths , rel_ab) ;
1597
1600
let aux_props =
1598
1601
self . props . from_aux_file ( & aux_testpaths. file , self . revision , self . config ) ;
1599
1602
let aux_cx = TestCx {
@@ -1604,7 +1607,7 @@ impl<'test> TestCx<'test> {
1604
1607
} ;
1605
1608
// Create the directory for the stdout/stderr files.
1606
1609
create_dir_all ( aux_cx. output_base_dir ( ) ) . unwrap ( ) ;
1607
- let auxres = aux_cx. document ( out_dir ) ;
1610
+ let auxres = aux_cx. document ( & root_out_dir , root_testpaths ) ;
1608
1611
if !auxres. status . success ( ) {
1609
1612
return auxres;
1610
1613
}
@@ -1614,21 +1617,47 @@ impl<'test> TestCx<'test> {
1614
1617
let aux_dir = self . aux_output_dir_name ( ) ;
1615
1618
1616
1619
let rustdoc_path = self . config . rustdoc_path . as_ref ( ) . expect ( "--rustdoc-path not passed" ) ;
1617
- let mut rustdoc = Command :: new ( rustdoc_path) ;
1618
1620
1621
+ // actual --out-dir given to the auxiliary or test, as opposed to the root out dir for the entire
1622
+ // test
1623
+ let out_dir: Cow < ' _ , Path > = if self . props . unique_doc_out_dir {
1624
+ let file_name = self
1625
+ . testpaths
1626
+ . file
1627
+ . file_name ( )
1628
+ . expect ( "file name should not be empty" )
1629
+ . to_str ( )
1630
+ . expect ( "file name utf8" )
1631
+ . trim_end_matches ( ".rs" ) ;
1632
+ let out_dir = PathBuf :: from_iter ( [
1633
+ root_out_dir,
1634
+ Path :: new ( "docs" ) ,
1635
+ Path :: new ( file_name) ,
1636
+ Path :: new ( "doc" ) ,
1637
+ ] ) ;
1638
+ create_dir_all ( & out_dir) . unwrap ( ) ;
1639
+ Cow :: Owned ( out_dir)
1640
+ } else {
1641
+ Cow :: Borrowed ( root_out_dir)
1642
+ } ;
1643
+
1644
+ let mut rustdoc = Command :: new ( rustdoc_path) ;
1645
+ let current_dir = output_base_dir ( self . config , root_testpaths, self . safe_revision ( ) ) ;
1646
+ rustdoc. current_dir ( current_dir) ;
1619
1647
rustdoc
1620
1648
. arg ( "-L" )
1621
1649
. arg ( self . config . run_lib_path . to_str ( ) . unwrap ( ) )
1622
1650
. arg ( "-L" )
1623
1651
. arg ( aux_dir)
1624
1652
. arg ( "-o" )
1625
- . arg ( out_dir)
1653
+ . arg ( out_dir. as_ref ( ) )
1626
1654
. arg ( "--deny" )
1627
1655
. arg ( "warnings" )
1628
1656
. arg ( & self . testpaths . file )
1629
1657
. arg ( "-A" )
1630
1658
. arg ( "internal_features" )
1631
- . args ( & self . props . compile_flags ) ;
1659
+ . args ( & self . props . compile_flags )
1660
+ . args ( & self . props . doc_flags ) ;
1632
1661
1633
1662
if self . config . mode == RustdocJson {
1634
1663
rustdoc. arg ( "--output-format" ) . arg ( "json" ) . arg ( "-Zunstable-options" ) ;
@@ -1638,7 +1667,7 @@ impl<'test> TestCx<'test> {
1638
1667
rustdoc. arg ( format ! ( "-Clinker={}" , linker) ) ;
1639
1668
}
1640
1669
1641
- self . compose_and_run_compiler ( rustdoc, None )
1670
+ self . compose_and_run_compiler ( rustdoc, None , root_testpaths )
1642
1671
}
1643
1672
1644
1673
fn exec_compiled_test ( & self ) -> ProcRes {
@@ -1836,9 +1865,16 @@ impl<'test> TestCx<'test> {
1836
1865
}
1837
1866
}
1838
1867
1839
- fn compose_and_run_compiler ( & self , mut rustc : Command , input : Option < String > ) -> ProcRes {
1868
+ /// `root_testpaths` refers to the path of the original test.
1869
+ /// the auxiliary and the test with an aux-build have the same `root_testpaths`.
1870
+ fn compose_and_run_compiler (
1871
+ & self ,
1872
+ mut rustc : Command ,
1873
+ input : Option < String > ,
1874
+ root_testpaths : & TestPaths ,
1875
+ ) -> ProcRes {
1840
1876
let aux_dir = self . aux_output_dir ( ) ;
1841
- self . build_all_auxiliary ( & self . testpaths , & aux_dir, & mut rustc) ;
1877
+ self . build_all_auxiliary ( root_testpaths , & aux_dir, & mut rustc) ;
1842
1878
1843
1879
rustc. envs ( self . props . rustc_env . clone ( ) ) ;
1844
1880
self . props . unset_rustc_env . iter ( ) . fold ( & mut rustc, Command :: env_remove) ;
@@ -2553,7 +2589,7 @@ impl<'test> TestCx<'test> {
2553
2589
Vec :: new ( ) ,
2554
2590
) ;
2555
2591
2556
- let proc_res = self . compose_and_run_compiler ( rustc, None ) ;
2592
+ let proc_res = self . compose_and_run_compiler ( rustc, None , self . testpaths ) ;
2557
2593
let output_path = self . get_filecheck_file ( "ll" ) ;
2558
2594
( proc_res, output_path)
2559
2595
}
@@ -2589,7 +2625,7 @@ impl<'test> TestCx<'test> {
2589
2625
Vec :: new ( ) ,
2590
2626
) ;
2591
2627
2592
- let proc_res = self . compose_and_run_compiler ( rustc, None ) ;
2628
+ let proc_res = self . compose_and_run_compiler ( rustc, None , self . testpaths ) ;
2593
2629
let output_path = self . get_filecheck_file ( "s" ) ;
2594
2630
( proc_res, output_path)
2595
2631
}
@@ -2672,7 +2708,7 @@ impl<'test> TestCx<'test> {
2672
2708
let out_dir = self . output_base_dir ( ) ;
2673
2709
remove_and_create_dir_all ( & out_dir) ;
2674
2710
2675
- let proc_res = self . document ( & out_dir) ;
2711
+ let proc_res = self . document ( & out_dir, & self . testpaths ) ;
2676
2712
if !proc_res. status . success ( ) {
2677
2713
self . fatal_proc_rec ( "rustdoc failed!" , & proc_res) ;
2678
2714
}
@@ -2731,7 +2767,7 @@ impl<'test> TestCx<'test> {
2731
2767
let aux_dir = new_rustdoc. aux_output_dir ( ) ;
2732
2768
new_rustdoc. build_all_auxiliary ( & new_rustdoc. testpaths , & aux_dir, & mut rustc) ;
2733
2769
2734
- let proc_res = new_rustdoc. document ( & compare_dir) ;
2770
+ let proc_res = new_rustdoc. document ( & compare_dir, & new_rustdoc . testpaths ) ;
2735
2771
if !proc_res. status . success ( ) {
2736
2772
eprintln ! ( "failed to run nightly rustdoc" ) ;
2737
2773
return ;
@@ -2854,7 +2890,7 @@ impl<'test> TestCx<'test> {
2854
2890
let out_dir = self . output_base_dir ( ) ;
2855
2891
remove_and_create_dir_all ( & out_dir) ;
2856
2892
2857
- let proc_res = self . document ( & out_dir) ;
2893
+ let proc_res = self . document ( & out_dir, & self . testpaths ) ;
2858
2894
if !proc_res. status . success ( ) {
2859
2895
self . fatal_proc_rec ( "rustdoc failed!" , & proc_res) ;
2860
2896
}
@@ -2930,24 +2966,15 @@ impl<'test> TestCx<'test> {
2930
2966
fn check_rustdoc_test_option ( & self , res : ProcRes ) {
2931
2967
let mut other_files = Vec :: new ( ) ;
2932
2968
let mut files: HashMap < String , Vec < usize > > = HashMap :: new ( ) ;
2933
- let cwd = env:: current_dir ( ) . unwrap ( ) ;
2934
- files. insert (
2935
- self . testpaths
2936
- . file
2937
- . strip_prefix ( & cwd)
2938
- . unwrap_or ( & self . testpaths . file )
2939
- . to_str ( )
2940
- . unwrap ( )
2941
- . replace ( '\\' , "/" ) ,
2942
- self . get_lines ( & self . testpaths . file , Some ( & mut other_files) ) ,
2943
- ) ;
2969
+ let normalized = fs:: canonicalize ( & self . testpaths . file ) . expect ( "failed to canonicalize" ) ;
2970
+ let normalized = normalized. to_str ( ) . unwrap ( ) . replace ( '\\' , "/" ) ;
2971
+ files. insert ( normalized, self . get_lines ( & self . testpaths . file , Some ( & mut other_files) ) ) ;
2944
2972
for other_file in other_files {
2945
2973
let mut path = self . testpaths . file . clone ( ) ;
2946
2974
path. set_file_name ( & format ! ( "{}.rs" , other_file) ) ;
2947
- files. insert (
2948
- path. strip_prefix ( & cwd) . unwrap_or ( & path) . to_str ( ) . unwrap ( ) . replace ( '\\' , "/" ) ,
2949
- self . get_lines ( & path, None ) ,
2950
- ) ;
2975
+ let path = fs:: canonicalize ( path) . expect ( "failed to canonicalize" ) ;
2976
+ let normalized = path. to_str ( ) . unwrap ( ) . replace ( '\\' , "/" ) ;
2977
+ files. insert ( normalized, self . get_lines ( & path, None ) ) ;
2951
2978
}
2952
2979
2953
2980
let mut tested = 0 ;
@@ -3786,7 +3813,7 @@ impl<'test> TestCx<'test> {
3786
3813
if let Some ( nodejs) = & self . config . nodejs {
3787
3814
let out_dir = self . output_base_dir ( ) ;
3788
3815
3789
- self . document ( & out_dir) ;
3816
+ self . document ( & out_dir, & self . testpaths ) ;
3790
3817
3791
3818
let root = self . config . find_rust_src_root ( ) . unwrap ( ) ;
3792
3819
let file_stem =
@@ -4102,7 +4129,7 @@ impl<'test> TestCx<'test> {
4102
4129
rustc. arg ( crate_name) ;
4103
4130
}
4104
4131
4105
- let res = self . compose_and_run_compiler ( rustc, None ) ;
4132
+ let res = self . compose_and_run_compiler ( rustc, None , self . testpaths ) ;
4106
4133
if !res. status . success ( ) {
4107
4134
self . fatal_proc_rec ( "failed to compile fixed code" , & res) ;
4108
4135
}
0 commit comments