11use regex:: bytes:: Regex ;
2+ use spanned:: { Span , Spanned } ;
23
3- use crate :: { dependencies:: build_dependencies, CommandBuilder , Filter , Match , Mode , RustfixMode } ;
4+ use crate :: {
5+ dependencies:: build_dependencies, per_test_config:: Comments , CommandBuilder , Match , Mode ,
6+ RustfixMode ,
7+ } ;
48pub use color_eyre;
59use color_eyre:: eyre:: Result ;
610use std:: {
@@ -19,18 +23,8 @@ pub struct Config {
1923 pub host : Option < String > ,
2024 /// `None` to run on the host, otherwise a target triple
2125 pub target : Option < String > ,
22- /// Filters applied to stderr output before processing it.
23- /// By default contains a filter for replacing backslashes in paths with
24- /// regular slashes.
25- /// On windows, contains a filter to remove `\r`.
26- pub stderr_filters : Filter ,
27- /// Filters applied to stdout output before processing it.
28- /// On windows, contains a filter to remove `\r`.
29- pub stdout_filters : Filter ,
3026 /// The folder in which to start searching for .rs files
3127 pub root_dir : PathBuf ,
32- /// The mode in which to run the tests.
33- pub mode : Mode ,
3428 /// The binary to actually execute.
3529 pub program : CommandBuilder ,
3630 /// The command to run to obtain the cfgs that the output is supposed to
@@ -45,8 +39,6 @@ pub struct Config {
4539 /// Where to dump files like the binaries compiled from tests.
4640 /// Defaults to `target/ui` in the current directory.
4741 pub out_dir : PathBuf ,
48- /// The default edition to use on all tests.
49- pub edition : Option < String > ,
5042 /// Skip test files whose names contain any of these entries.
5143 pub skip_files : Vec < String > ,
5244 /// Only test files whose names contain any of these entries.
@@ -59,34 +51,37 @@ pub struct Config {
5951 pub run_only_ignored : bool ,
6052 /// Filters must match exactly instead of just checking for substrings.
6153 pub filter_exact : bool ,
54+ /// The default settings settable via `@` comments
55+ pub comment_defaults : Comments ,
6256}
6357
6458impl Config {
6559 /// Create a configuration for testing the output of running
6660 /// `rustc` on the test files.
6761 pub fn rustc ( root_dir : impl Into < PathBuf > ) -> Self {
62+ let mut comment_defaults = Comments :: default ( ) ;
63+ let _ = comment_defaults
64+ . base ( )
65+ . edition
66+ . set ( "2021" . into ( ) , Span :: default ( ) ) ;
67+ let filters = vec ! [
68+ ( Match :: PathBackslash , b"/" . to_vec( ) ) ,
69+ #[ cfg( windows) ]
70+ ( Match :: Exact ( vec![ b'\r' ] ) , b"" . to_vec( ) ) ,
71+ #[ cfg( windows) ]
72+ ( Match :: Exact ( br"\\?\" . to_vec( ) ) , b"" . to_vec( ) ) ,
73+ ] ;
74+ comment_defaults. base ( ) . normalize_stderr = filters. clone ( ) ;
75+ comment_defaults. base ( ) . normalize_stdout = filters;
76+ comment_defaults. base ( ) . mode = Spanned :: dummy ( Mode :: Fail {
77+ require_patterns : true ,
78+ rustfix : RustfixMode :: MachineApplicable ,
79+ } )
80+ . into ( ) ;
6881 Self {
6982 host : None ,
7083 target : None ,
71- stderr_filters : vec ! [
72- ( Match :: PathBackslash , b"/" ) ,
73- #[ cfg( windows) ]
74- ( Match :: Exact ( vec![ b'\r' ] ) , b"" ) ,
75- #[ cfg( windows) ]
76- ( Match :: Exact ( br"\\?\" . to_vec( ) ) , b"" ) ,
77- ] ,
78- stdout_filters : vec ! [
79- ( Match :: PathBackslash , b"/" ) ,
80- #[ cfg( windows) ]
81- ( Match :: Exact ( vec![ b'\r' ] ) , b"" ) ,
82- #[ cfg( windows) ]
83- ( Match :: Exact ( br"\\?\" . to_vec( ) ) , b"" ) ,
84- ] ,
8584 root_dir : root_dir. into ( ) ,
86- mode : Mode :: Fail {
87- require_patterns : true ,
88- rustfix : RustfixMode :: MachineApplicable ,
89- } ,
9085 program : CommandBuilder :: rustc ( ) ,
9186 cfgs : CommandBuilder :: cfgs ( ) ,
9287 output_conflict_handling : OutputConflictHandling :: Bless ,
@@ -96,28 +91,30 @@ impl Config {
9691 . map ( PathBuf :: from)
9792 . unwrap_or_else ( || std:: env:: current_dir ( ) . unwrap ( ) . join ( "target" ) )
9893 . join ( "ui" ) ,
99- edition : Some ( "2021" . into ( ) ) ,
10094 skip_files : Vec :: new ( ) ,
10195 filter_files : Vec :: new ( ) ,
10296 threads : None ,
10397 list : false ,
10498 run_only_ignored : false ,
10599 filter_exact : false ,
100+ comment_defaults,
106101 }
107102 }
108103
109104 /// Create a configuration for testing the output of running
110105 /// `cargo` on the test `Cargo.toml` files.
111106 pub fn cargo ( root_dir : impl Into < PathBuf > ) -> Self {
112- Self {
107+ let mut this = Self {
113108 program : CommandBuilder :: cargo ( ) ,
114- edition : None ,
115- mode : Mode :: Fail {
116- require_patterns : true ,
117- rustfix : RustfixMode :: Disabled ,
118- } ,
119109 ..Self :: rustc ( root_dir)
120- }
110+ } ;
111+ this. comment_defaults . base ( ) . edition = Default :: default ( ) ;
112+ this. comment_defaults . base ( ) . mode = Spanned :: dummy ( Mode :: Fail {
113+ require_patterns : true ,
114+ rustfix : RustfixMode :: Disabled ,
115+ } )
116+ . into ( ) ;
117+ this
121118 }
122119
123120 /// Populate the config with the values from parsed command line arguments.
@@ -180,8 +177,10 @@ impl Config {
180177 replacement : & ' static ( impl AsRef < [ u8 ] > + ?Sized ) ,
181178 ) {
182179 let pattern = path. canonicalize ( ) . unwrap ( ) ;
183- self . stderr_filters
184- . push ( ( pattern. parent ( ) . unwrap ( ) . into ( ) , replacement. as_ref ( ) ) ) ;
180+ self . comment_defaults . base ( ) . normalize_stderr . push ( (
181+ pattern. parent ( ) . unwrap ( ) . into ( ) ,
182+ replacement. as_ref ( ) . to_owned ( ) ,
183+ ) ) ;
185184 }
186185
187186 /// Replace all occurrences of a path in stdout with a byte string.
@@ -192,8 +191,10 @@ impl Config {
192191 replacement : & ' static ( impl AsRef < [ u8 ] > + ?Sized ) ,
193192 ) {
194193 let pattern = path. canonicalize ( ) . unwrap ( ) ;
195- self . stdout_filters
196- . push ( ( pattern. parent ( ) . unwrap ( ) . into ( ) , replacement. as_ref ( ) ) ) ;
194+ self . comment_defaults . base ( ) . normalize_stdout . push ( (
195+ pattern. parent ( ) . unwrap ( ) . into ( ) ,
196+ replacement. as_ref ( ) . to_owned ( ) ,
197+ ) ) ;
197198 }
198199
199200 /// Replace all occurrences of a regex pattern in stderr/stdout with a byte string.
@@ -210,8 +211,10 @@ impl Config {
210211 pattern : & str ,
211212 replacement : & ' static ( impl AsRef < [ u8 ] > + ?Sized ) ,
212213 ) {
213- self . stderr_filters
214- . push ( ( Regex :: new ( pattern) . unwrap ( ) . into ( ) , replacement. as_ref ( ) ) ) ;
214+ self . comment_defaults . base ( ) . normalize_stderr . push ( (
215+ Regex :: new ( pattern) . unwrap ( ) . into ( ) ,
216+ replacement. as_ref ( ) . to_owned ( ) ,
217+ ) ) ;
215218 }
216219
217220 /// Replace all occurrences of a regex pattern in stdout with a byte string.
@@ -221,8 +224,10 @@ impl Config {
221224 pattern : & str ,
222225 replacement : & ' static ( impl AsRef < [ u8 ] > + ?Sized ) ,
223226 ) {
224- self . stdout_filters
225- . push ( ( Regex :: new ( pattern) . unwrap ( ) . into ( ) , replacement. as_ref ( ) ) ) ;
227+ self . comment_defaults . base ( ) . normalize_stdout . push ( (
228+ Regex :: new ( pattern) . unwrap ( ) . into ( ) ,
229+ replacement. as_ref ( ) . to_owned ( ) ,
230+ ) ) ;
226231 }
227232
228233 /// Compile dependencies and return the right flags
0 commit comments