1
1
// ignore-tidy-filelength
2
2
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 ;
3
15
use std:: collections:: { HashMap , HashSet } ;
4
16
use std:: ffi:: { OsStr , OsString } ;
5
17
use std:: fs:: { self , create_dir_all, File , OpenOptions } ;
@@ -723,7 +735,7 @@ impl<'test> TestCx<'test> {
723
735
self . maybe_add_external_args ( & mut rustc, & self . config . target_rustcflags ) ;
724
736
rustc. args ( & self . props . compile_flags ) ;
725
737
726
- self . compose_and_run_compiler ( rustc, Some ( src) )
738
+ self . compose_and_run_compiler ( rustc, Some ( src) , self . testpaths )
727
739
}
728
740
729
741
fn run_debuginfo_test ( & self ) {
@@ -1579,13 +1591,15 @@ impl<'test> TestCx<'test> {
1579
1591
passes,
1580
1592
) ;
1581
1593
1582
- self . compose_and_run_compiler ( rustc, None )
1594
+ self . compose_and_run_compiler ( rustc, None , self . testpaths )
1583
1595
}
1584
1596
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 {
1586
1600
if self . props . build_aux_docs {
1587
1601
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) ;
1589
1603
let aux_props =
1590
1604
self . props . from_aux_file ( & aux_testpaths. file , self . revision , self . config ) ;
1591
1605
let aux_cx = TestCx {
@@ -1596,7 +1610,7 @@ impl<'test> TestCx<'test> {
1596
1610
} ;
1597
1611
// Create the directory for the stdout/stderr files.
1598
1612
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 ) ;
1600
1614
if !auxres. status . success ( ) {
1601
1615
return auxres;
1602
1616
}
@@ -1606,21 +1620,47 @@ impl<'test> TestCx<'test> {
1606
1620
let aux_dir = self . aux_output_dir_name ( ) ;
1607
1621
1608
1622
let rustdoc_path = self . config . rustdoc_path . as_ref ( ) . expect ( "--rustdoc-path not passed" ) ;
1609
- let mut rustdoc = Command :: new ( rustdoc_path) ;
1610
1623
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) ;
1611
1650
rustdoc
1612
1651
. arg ( "-L" )
1613
1652
. arg ( self . config . run_lib_path . to_str ( ) . unwrap ( ) )
1614
1653
. arg ( "-L" )
1615
1654
. arg ( aux_dir)
1616
1655
. arg ( "-o" )
1617
- . arg ( out_dir)
1656
+ . arg ( out_dir. as_ref ( ) )
1618
1657
. arg ( "--deny" )
1619
1658
. arg ( "warnings" )
1620
1659
. arg ( & self . testpaths . file )
1621
1660
. arg ( "-A" )
1622
1661
. arg ( "internal_features" )
1623
- . args ( & self . props . compile_flags ) ;
1662
+ . args ( & self . props . compile_flags )
1663
+ . args ( & self . props . doc_flags ) ;
1624
1664
1625
1665
if self . config . mode == RustdocJson {
1626
1666
rustdoc. arg ( "--output-format" ) . arg ( "json" ) . arg ( "-Zunstable-options" ) ;
@@ -1630,7 +1670,7 @@ impl<'test> TestCx<'test> {
1630
1670
rustdoc. arg ( format ! ( "-Clinker={}" , linker) ) ;
1631
1671
}
1632
1672
1633
- self . compose_and_run_compiler ( rustdoc, None )
1673
+ self . compose_and_run_compiler ( rustdoc, None , root_testpaths )
1634
1674
}
1635
1675
1636
1676
fn exec_compiled_test ( & self ) -> ProcRes {
@@ -1828,9 +1868,16 @@ impl<'test> TestCx<'test> {
1828
1868
}
1829
1869
}
1830
1870
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 {
1832
1879
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) ;
1834
1881
1835
1882
rustc. envs ( self . props . rustc_env . clone ( ) ) ;
1836
1883
self . props . unset_rustc_env . iter ( ) . fold ( & mut rustc, Command :: env_remove) ;
@@ -2545,7 +2592,7 @@ impl<'test> TestCx<'test> {
2545
2592
Vec :: new ( ) ,
2546
2593
) ;
2547
2594
2548
- let proc_res = self . compose_and_run_compiler ( rustc, None ) ;
2595
+ let proc_res = self . compose_and_run_compiler ( rustc, None , self . testpaths ) ;
2549
2596
let output_path = self . get_filecheck_file ( "ll" ) ;
2550
2597
( proc_res, output_path)
2551
2598
}
@@ -2581,7 +2628,7 @@ impl<'test> TestCx<'test> {
2581
2628
Vec :: new ( ) ,
2582
2629
) ;
2583
2630
2584
- let proc_res = self . compose_and_run_compiler ( rustc, None ) ;
2631
+ let proc_res = self . compose_and_run_compiler ( rustc, None , self . testpaths ) ;
2585
2632
let output_path = self . get_filecheck_file ( "s" ) ;
2586
2633
( proc_res, output_path)
2587
2634
}
@@ -2664,7 +2711,7 @@ impl<'test> TestCx<'test> {
2664
2711
let out_dir = self . output_base_dir ( ) ;
2665
2712
remove_and_create_dir_all ( & out_dir) ;
2666
2713
2667
- let proc_res = self . document ( & out_dir) ;
2714
+ let proc_res = self . document ( & out_dir, & self . testpaths ) ;
2668
2715
if !proc_res. status . success ( ) {
2669
2716
self . fatal_proc_rec ( "rustdoc failed!" , & proc_res) ;
2670
2717
}
@@ -2723,7 +2770,7 @@ impl<'test> TestCx<'test> {
2723
2770
let aux_dir = new_rustdoc. aux_output_dir ( ) ;
2724
2771
new_rustdoc. build_all_auxiliary ( & new_rustdoc. testpaths , & aux_dir, & mut rustc) ;
2725
2772
2726
- let proc_res = new_rustdoc. document ( & compare_dir) ;
2773
+ let proc_res = new_rustdoc. document ( & compare_dir, & new_rustdoc . testpaths ) ;
2727
2774
if !proc_res. status . success ( ) {
2728
2775
eprintln ! ( "failed to run nightly rustdoc" ) ;
2729
2776
return ;
@@ -2846,7 +2893,7 @@ impl<'test> TestCx<'test> {
2846
2893
let out_dir = self . output_base_dir ( ) ;
2847
2894
remove_and_create_dir_all ( & out_dir) ;
2848
2895
2849
- let proc_res = self . document ( & out_dir) ;
2896
+ let proc_res = self . document ( & out_dir, & self . testpaths ) ;
2850
2897
if !proc_res. status . success ( ) {
2851
2898
self . fatal_proc_rec ( "rustdoc failed!" , & proc_res) ;
2852
2899
}
@@ -2922,24 +2969,15 @@ impl<'test> TestCx<'test> {
2922
2969
fn check_rustdoc_test_option ( & self , res : ProcRes ) {
2923
2970
let mut other_files = Vec :: new ( ) ;
2924
2971
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) ) ) ;
2936
2975
for other_file in other_files {
2937
2976
let mut path = self . testpaths . file . clone ( ) ;
2938
2977
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 ) ) ;
2943
2981
}
2944
2982
2945
2983
let mut tested = 0 ;
@@ -3778,7 +3816,7 @@ impl<'test> TestCx<'test> {
3778
3816
if let Some ( nodejs) = & self . config . nodejs {
3779
3817
let out_dir = self . output_base_dir ( ) ;
3780
3818
3781
- self . document ( & out_dir) ;
3819
+ self . document ( & out_dir, & self . testpaths ) ;
3782
3820
3783
3821
let root = self . config . find_rust_src_root ( ) . unwrap ( ) ;
3784
3822
let file_stem =
@@ -4094,7 +4132,7 @@ impl<'test> TestCx<'test> {
4094
4132
rustc. arg ( crate_name) ;
4095
4133
}
4096
4134
4097
- let res = self . compose_and_run_compiler ( rustc, None ) ;
4135
+ let res = self . compose_and_run_compiler ( rustc, None , self . testpaths ) ;
4098
4136
if !res. status . success ( ) {
4099
4137
self . fatal_proc_rec ( "failed to compile fixed code" , & res) ;
4100
4138
}
0 commit comments