@@ -26,7 +26,7 @@ use std::collections::VecDeque;
26
26
use std:: collections:: HashMap ;
27
27
use std:: collections:: HashSet ;
28
28
use std:: env;
29
- use std:: ffi:: OsString ;
29
+ use std:: ffi:: { OsStr , OsString } ;
30
30
use std:: fs:: { self , create_dir_all, File } ;
31
31
use std:: fmt;
32
32
use std:: io:: prelude:: * ;
@@ -72,6 +72,26 @@ impl Mismatch {
72
72
}
73
73
}
74
74
75
+ trait PathBufExt {
76
+ /// Append an extension to the path, even if it already has one.
77
+ fn with_extra_extension < S : AsRef < OsStr > > ( & self , extension : S ) -> PathBuf ;
78
+ }
79
+
80
+ impl PathBufExt for PathBuf {
81
+ fn with_extra_extension < S : AsRef < OsStr > > ( & self , extension : S ) -> PathBuf {
82
+ if extension. as_ref ( ) . len ( ) == 0 {
83
+ self . clone ( )
84
+ } else {
85
+ let mut fname = self . file_name ( ) . unwrap ( ) . to_os_string ( ) ;
86
+ if !extension. as_ref ( ) . to_str ( ) . unwrap ( ) . starts_with ( "." ) {
87
+ fname. push ( "." ) ;
88
+ }
89
+ fname. push ( extension) ;
90
+ self . with_file_name ( fname)
91
+ }
92
+ }
93
+ }
94
+
75
95
// Produces a diff between the expected output and actual output.
76
96
pub fn make_diff ( expected : & str , actual : & str , context_size : usize ) -> Vec < Mismatch > {
77
97
let mut line_number = 1 ;
@@ -1725,20 +1745,14 @@ impl<'test> TestCx<'test> {
1725
1745
}
1726
1746
1727
1747
fn make_exe_name ( & self ) -> PathBuf {
1728
- let mut f = self . output_base_name ( ) ;
1748
+ let mut f = self . output_base_name_stage ( ) ;
1729
1749
// FIXME: This is using the host architecture exe suffix, not target!
1730
1750
if self . config . target . contains ( "emscripten" ) {
1731
- let mut fname = f. file_name ( ) . unwrap ( ) . to_os_string ( ) ;
1732
- fname. push ( ".js" ) ;
1733
- f. set_file_name ( & fname) ;
1751
+ f = f. with_extra_extension ( "js" ) ;
1734
1752
} else if self . config . target . contains ( "wasm32" ) {
1735
- let mut fname = f. file_name ( ) . unwrap ( ) . to_os_string ( ) ;
1736
- fname. push ( ".wasm" ) ;
1737
- f. set_file_name ( & fname) ;
1753
+ f = f. with_extra_extension ( "wasm" ) ;
1738
1754
} else if !env:: consts:: EXE_SUFFIX . is_empty ( ) {
1739
- let mut fname = f. file_name ( ) . unwrap ( ) . to_os_string ( ) ;
1740
- fname. push ( env:: consts:: EXE_SUFFIX ) ;
1741
- f. set_file_name ( & fname) ;
1755
+ f = f. with_extra_extension ( env:: consts:: EXE_SUFFIX ) ;
1742
1756
}
1743
1757
f
1744
1758
}
@@ -1846,25 +1860,28 @@ impl<'test> TestCx<'test> {
1846
1860
}
1847
1861
1848
1862
fn aux_output_dir_name ( & self ) -> PathBuf {
1849
- let f = self . output_base_name ( ) ;
1850
- let mut fname = f. file_name ( ) . unwrap ( ) . to_os_string ( ) ;
1851
- fname. push ( & format ! ( "{}.aux" , self . config. mode. disambiguator( ) ) ) ;
1852
- f. with_file_name ( & fname)
1863
+ self . output_base_name_stage ( )
1864
+ . with_extra_extension ( self . config . mode . disambiguator ( ) )
1865
+ . with_extra_extension ( ".aux" )
1853
1866
}
1854
1867
1855
1868
fn output_testname ( & self , filepath : & Path ) -> PathBuf {
1856
1869
PathBuf :: from ( filepath. file_stem ( ) . unwrap ( ) )
1857
1870
}
1858
1871
1859
- /// Given a test path like `compile-fail/foo/bar.rs` Returns a name like
1860
- ///
1861
- /// <output>/foo/bar-stage1
1872
+ /// Given a test path like `compile-fail/foo/bar.rs` returns a name like
1873
+ /// `/path/to/build/<triple>/test/compile-fail/foo/bar`.
1862
1874
fn output_base_name ( & self ) -> PathBuf {
1863
1875
let dir = self . config . build_base . join ( & self . testpaths . relative_dir ) ;
1864
1876
1865
1877
// Note: The directory `dir` is created during `collect_tests_from_dir`
1866
1878
dir. join ( & self . output_testname ( & self . testpaths . file ) )
1867
- . with_extension ( & self . config . stage_id )
1879
+ }
1880
+
1881
+ /// Same as `output_base_name`, but includes the stage ID as an extension,
1882
+ /// such as: `.../compile-fail/foo/bar.stage1-<triple>`
1883
+ fn output_base_name_stage ( & self ) -> PathBuf {
1884
+ self . output_base_name ( ) . with_extension ( & self . config . stage_id )
1868
1885
}
1869
1886
1870
1887
fn maybe_dump_to_stdout ( & self , out : & str , err : & str ) {
@@ -1989,7 +2006,7 @@ impl<'test> TestCx<'test> {
1989
2006
fn run_rustdoc_test ( & self ) {
1990
2007
assert ! ( self . revision. is_none( ) , "revisions not relevant here" ) ;
1991
2008
1992
- let out_dir = self . output_base_name ( ) ;
2009
+ let out_dir = self . output_base_name_stage ( ) ;
1993
2010
let _ = fs:: remove_dir_all ( & out_dir) ;
1994
2011
create_dir_all ( & out_dir) . unwrap ( ) ;
1995
2012
@@ -2391,7 +2408,7 @@ impl<'test> TestCx<'test> {
2391
2408
. unwrap ( ) ;
2392
2409
let src_root = cwd. join ( & src_root) ;
2393
2410
2394
- let tmpdir = cwd. join ( self . output_base_name ( ) ) ;
2411
+ let tmpdir = cwd. join ( self . output_base_name_stage ( ) ) ;
2395
2412
if tmpdir. exists ( ) {
2396
2413
self . aggressive_rm_rf ( & tmpdir) . unwrap ( ) ;
2397
2414
}
@@ -2816,7 +2833,6 @@ impl<'test> TestCx<'test> {
2816
2833
self . revision ,
2817
2834
& self . config . compare_mode ,
2818
2835
kind) ;
2819
-
2820
2836
if !path. exists ( ) && self . config . compare_mode . is_some ( ) {
2821
2837
// fallback!
2822
2838
path = expected_output_path ( & self . testpaths , self . revision , & None , kind) ;
@@ -2880,10 +2896,12 @@ impl<'test> TestCx<'test> {
2880
2896
}
2881
2897
}
2882
2898
2883
- let expected_output = self . expected_output_path ( kind) ;
2884
- // #50113: output is abspath; only want filename component.
2885
- let expected_output = expected_output. file_name ( ) . expect ( "output path requires file name" ) ;
2886
- let output_file = self . output_base_name ( ) . with_file_name ( & expected_output) ;
2899
+ let mode = self . config . compare_mode . as_ref ( ) . map_or ( "" , |m| m. to_str ( ) ) ;
2900
+ let output_file = self . output_base_name ( )
2901
+ . with_extra_extension ( self . revision . unwrap_or ( "" ) )
2902
+ . with_extra_extension ( mode)
2903
+ . with_extra_extension ( kind) ;
2904
+
2887
2905
match File :: create ( & output_file) . and_then ( |mut f| f. write_all ( actual. as_bytes ( ) ) ) {
2888
2906
Ok ( ( ) ) => { }
2889
2907
Err ( e) => self . fatal ( & format ! (
0 commit comments