1
1
use regex:: bytes:: Regex ;
2
+ use spanned:: { Span , Spanned } ;
2
3
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
+ } ;
4
8
pub use color_eyre;
5
9
use color_eyre:: eyre:: Result ;
6
10
use std:: {
@@ -19,18 +23,8 @@ pub struct Config {
19
23
pub host : Option < String > ,
20
24
/// `None` to run on the host, otherwise a target triple
21
25
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 ,
30
26
/// The folder in which to start searching for .rs files
31
27
pub root_dir : PathBuf ,
32
- /// The mode in which to run the tests.
33
- pub mode : Mode ,
34
28
/// The binary to actually execute.
35
29
pub program : CommandBuilder ,
36
30
/// The command to run to obtain the cfgs that the output is supposed to
@@ -45,8 +39,6 @@ pub struct Config {
45
39
/// Where to dump files like the binaries compiled from tests.
46
40
/// Defaults to `target/ui` in the current directory.
47
41
pub out_dir : PathBuf ,
48
- /// The default edition to use on all tests.
49
- pub edition : Option < String > ,
50
42
/// Skip test files whose names contain any of these entries.
51
43
pub skip_files : Vec < String > ,
52
44
/// Only test files whose names contain any of these entries.
@@ -59,34 +51,37 @@ pub struct Config {
59
51
pub run_only_ignored : bool ,
60
52
/// Filters must match exactly instead of just checking for substrings.
61
53
pub filter_exact : bool ,
54
+ /// The default settings settable via `@` comments
55
+ pub comment_defaults : Comments ,
62
56
}
63
57
64
58
impl Config {
65
59
/// Create a configuration for testing the output of running
66
60
/// `rustc` on the test files.
67
61
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 ( ) ;
68
81
Self {
69
82
host : None ,
70
83
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
- ] ,
85
84
root_dir : root_dir. into ( ) ,
86
- mode : Mode :: Fail {
87
- require_patterns : true ,
88
- rustfix : RustfixMode :: MachineApplicable ,
89
- } ,
90
85
program : CommandBuilder :: rustc ( ) ,
91
86
cfgs : CommandBuilder :: cfgs ( ) ,
92
87
output_conflict_handling : OutputConflictHandling :: Bless ,
@@ -96,28 +91,30 @@ impl Config {
96
91
. map ( PathBuf :: from)
97
92
. unwrap_or_else ( || std:: env:: current_dir ( ) . unwrap ( ) . join ( "target" ) )
98
93
. join ( "ui" ) ,
99
- edition : Some ( "2021" . into ( ) ) ,
100
94
skip_files : Vec :: new ( ) ,
101
95
filter_files : Vec :: new ( ) ,
102
96
threads : None ,
103
97
list : false ,
104
98
run_only_ignored : false ,
105
99
filter_exact : false ,
100
+ comment_defaults,
106
101
}
107
102
}
108
103
109
104
/// Create a configuration for testing the output of running
110
105
/// `cargo` on the test `Cargo.toml` files.
111
106
pub fn cargo ( root_dir : impl Into < PathBuf > ) -> Self {
112
- Self {
107
+ let mut this = Self {
113
108
program : CommandBuilder :: cargo ( ) ,
114
- edition : None ,
115
- mode : Mode :: Fail {
116
- require_patterns : true ,
117
- rustfix : RustfixMode :: Disabled ,
118
- } ,
119
109
..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
121
118
}
122
119
123
120
/// Populate the config with the values from parsed command line arguments.
@@ -180,8 +177,10 @@ impl Config {
180
177
replacement : & ' static ( impl AsRef < [ u8 ] > + ?Sized ) ,
181
178
) {
182
179
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
+ ) ) ;
185
184
}
186
185
187
186
/// Replace all occurrences of a path in stdout with a byte string.
@@ -192,8 +191,10 @@ impl Config {
192
191
replacement : & ' static ( impl AsRef < [ u8 ] > + ?Sized ) ,
193
192
) {
194
193
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
+ ) ) ;
197
198
}
198
199
199
200
/// Replace all occurrences of a regex pattern in stderr/stdout with a byte string.
@@ -210,8 +211,10 @@ impl Config {
210
211
pattern : & str ,
211
212
replacement : & ' static ( impl AsRef < [ u8 ] > + ?Sized ) ,
212
213
) {
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
+ ) ) ;
215
218
}
216
219
217
220
/// Replace all occurrences of a regex pattern in stdout with a byte string.
@@ -221,8 +224,10 @@ impl Config {
221
224
pattern : & str ,
222
225
replacement : & ' static ( impl AsRef < [ u8 ] > + ?Sized ) ,
223
226
) {
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
+ ) ) ;
226
231
}
227
232
228
233
/// Compile dependencies and return the right flags
0 commit comments