4
4
#![ warn( rust_2018_idioms, unused_lifetimes) ]
5
5
#![ allow( unused_extern_crates) ]
6
6
7
- use compiletest:: { status_emitter, Args , CommandBuilder , OutputConflictHandling } ;
8
- use ui_test as compiletest;
9
- use ui_test:: Mode as TestMode ;
7
+ use ui_test:: { status_emitter, Args , CommandBuilder , Config , Match , Mode , OutputConflictHandling } ;
10
8
11
9
use std:: collections:: BTreeMap ;
12
- use std:: env:: { self , remove_var , set_var, var_os} ;
10
+ use std:: env:: { self , set_var, var_os} ;
13
11
use std:: ffi:: { OsStr , OsString } ;
14
12
use std:: fs;
15
13
use std:: path:: { Path , PathBuf } ;
@@ -29,6 +27,8 @@ extern crate quote;
29
27
extern crate syn;
30
28
extern crate tokio;
31
29
30
+ mod test_utils;
31
+
32
32
/// All crates used in UI tests are listed here
33
33
static TEST_DEPENDENCIES : & [ & str ] = & [
34
34
"clippy_lints" ,
@@ -104,8 +104,6 @@ static EXTERN_FLAGS: LazyLock<Vec<String>> = LazyLock::new(|| {
104
104
. collect ( )
105
105
} ) ;
106
106
107
- mod test_utils;
108
-
109
107
// whether to run internal tests or not
110
108
const RUN_INTERNAL_TESTS : bool = cfg ! ( feature = "internal" ) ;
111
109
@@ -115,7 +113,7 @@ fn canonicalize(path: impl AsRef<Path>) -> PathBuf {
115
113
fs:: canonicalize ( path) . unwrap_or_else ( |err| panic ! ( "{} cannot be canonicalized: {err}" , path. display( ) ) )
116
114
}
117
115
118
- fn base_config ( test_dir : & str ) -> ( compiletest :: Config , Args ) {
116
+ fn base_config ( test_dir : & str ) -> ( Config , Args ) {
119
117
let bless = var_os ( "RUSTC_BLESS" ) . is_some_and ( |v| v != "0" ) || env:: args ( ) . any ( |arg| arg == "--bless" ) ;
120
118
121
119
let args = Args {
@@ -131,18 +129,18 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) {
131
129
skip : Vec :: new ( ) ,
132
130
} ;
133
131
134
- let mut config = compiletest :: Config {
135
- mode : TestMode :: Yolo { rustfix : true } ,
136
- stderr_filters : vec ! [ ] ,
132
+ let mut config = Config {
133
+ mode : Mode :: Yolo { rustfix : true } ,
134
+ stderr_filters : vec ! [ ( Match :: PathBackslash , b"/" ) ] ,
137
135
stdout_filters : vec ! [ ] ,
138
136
output_conflict_handling : if bless {
139
137
OutputConflictHandling :: Bless
140
138
} else {
141
139
OutputConflictHandling :: Error ( "cargo uibless" . into ( ) )
142
140
} ,
143
141
target : None ,
144
- out_dir : canonicalize ( std :: env :: var_os ( "CARGO_TARGET_DIR" ) . unwrap_or_else ( || "target" . into ( ) ) ) . join ( "ui_test" ) ,
145
- ..compiletest :: Config :: rustc ( Path :: new ( "tests" ) . join ( test_dir) )
142
+ out_dir : canonicalize ( var_os ( "CARGO_TARGET_DIR" ) . unwrap_or_else ( || "target" . into ( ) ) ) . join ( "ui_test" ) ,
143
+ ..Config :: rustc ( Path :: new ( "tests" ) . join ( test_dir) )
146
144
} ;
147
145
let current_exe_path = env:: current_exe ( ) . unwrap ( ) ;
148
146
let deps_path = current_exe_path. parent ( ) . unwrap ( ) ;
@@ -167,10 +165,6 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) {
167
165
config. program . args . push ( dep. into ( ) ) ;
168
166
}
169
167
170
- // Normalize away slashes in windows paths.
171
- config. stderr_filter ( r"\\" , "/" ) ;
172
-
173
- //config.build_base = profile_path.join("test").join(test_dir);
174
168
config. program . program = profile_path. join ( if cfg ! ( windows) {
175
169
"clippy-driver.exe"
176
170
} else {
@@ -180,18 +174,19 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) {
180
174
}
181
175
182
176
fn run_ui ( ) {
183
- let ( config, args) = base_config ( "ui" ) ;
184
- // use tests/clippy.toml
185
- let _g = VarGuard :: set ( "CARGO_MANIFEST_DIR" , canonicalize ( "tests" ) ) ;
186
- let _threads = VarGuard :: set ( "RUST_TEST_THREADS" , args. threads . to_string ( ) ) ;
177
+ let ( mut config, args) = base_config ( "ui" ) ;
178
+ config
179
+ . program
180
+ . envs
181
+ . push ( ( "CLIPPY_CONF_DIR" . into ( ) , Some ( canonicalize ( "tests" ) . into ( ) ) ) ) ;
187
182
188
183
let quiet = args. quiet ;
189
184
190
- compiletest :: run_tests_generic (
185
+ ui_test :: run_tests_generic (
191
186
vec ! [ config] ,
192
187
args,
193
- compiletest :: default_file_filter,
194
- compiletest :: default_per_file_config,
188
+ ui_test :: default_file_filter,
189
+ ui_test :: default_per_file_config,
195
190
if quiet {
196
191
status_emitter:: Text :: quiet ( )
197
192
} else {
@@ -212,11 +207,11 @@ fn run_internal_tests() {
212
207
}
213
208
let quiet = args. quiet ;
214
209
215
- compiletest :: run_tests_generic (
210
+ ui_test :: run_tests_generic (
216
211
vec ! [ config] ,
217
212
args,
218
- compiletest :: default_file_filter,
219
- compiletest :: default_per_file_config,
213
+ ui_test :: default_file_filter,
214
+ ui_test :: default_per_file_config,
220
215
if quiet {
221
216
status_emitter:: Text :: quiet ( )
222
217
} else {
@@ -229,24 +224,27 @@ fn run_internal_tests() {
229
224
fn run_ui_toml ( ) {
230
225
let ( mut config, args) = base_config ( "ui-toml" ) ;
231
226
232
- config. stderr_filter (
233
- & regex:: escape (
234
- & canonicalize ( "tests" )
235
- . parent ( )
236
- . unwrap ( )
237
- . display ( )
238
- . to_string ( )
239
- . replace ( '\\' , "/" ) ,
227
+ config. stderr_filters = vec ! [
228
+ (
229
+ Match :: Exact (
230
+ canonicalize( "tests" )
231
+ . parent( )
232
+ . unwrap( )
233
+ . to_string_lossy( )
234
+ . as_bytes( )
235
+ . to_vec( ) ,
236
+ ) ,
237
+ b"$DIR" ,
240
238
) ,
241
- "$$DIR" ,
242
- ) ;
239
+ ( Match :: Exact ( b" \\ " . to_vec ( ) ) , b"/" ) ,
240
+ ] ;
243
241
244
242
let quiet = args. quiet ;
245
243
246
244
ui_test:: run_tests_generic (
247
245
vec ! [ config] ,
248
246
args,
249
- compiletest :: default_file_filter,
247
+ ui_test :: default_file_filter,
250
248
|config, path, _file_contents| {
251
249
config
252
250
. program
@@ -285,17 +283,20 @@ fn run_ui_cargo() {
285
283
} ) ;
286
284
config. edition = None ;
287
285
288
- config. stderr_filter (
289
- & regex:: escape (
290
- & canonicalize ( "tests" )
291
- . parent ( )
292
- . unwrap ( )
293
- . display ( )
294
- . to_string ( )
295
- . replace ( '\\' , "/" ) ,
286
+ config. stderr_filters = vec ! [
287
+ (
288
+ Match :: Exact (
289
+ canonicalize( "tests" )
290
+ . parent( )
291
+ . unwrap( )
292
+ . to_string_lossy( )
293
+ . as_bytes( )
294
+ . to_vec( ) ,
295
+ ) ,
296
+ b"$DIR" ,
296
297
) ,
297
- "$$DIR" ,
298
- ) ;
298
+ ( Match :: Exact ( b" \\ " . to_vec ( ) ) , b"/" ) ,
299
+ ] ;
299
300
300
301
let quiet = args. quiet ;
301
302
@@ -410,27 +411,3 @@ fn ui_cargo_toml_metadata() {
410
411
) ;
411
412
}
412
413
}
413
-
414
- /// Restores an env var on drop
415
- #[ must_use]
416
- struct VarGuard {
417
- key : & ' static str ,
418
- value : Option < OsString > ,
419
- }
420
-
421
- impl VarGuard {
422
- fn set ( key : & ' static str , val : impl AsRef < OsStr > ) -> Self {
423
- let value = var_os ( key) ;
424
- set_var ( key, val) ;
425
- Self { key, value }
426
- }
427
- }
428
-
429
- impl Drop for VarGuard {
430
- fn drop ( & mut self ) {
431
- match self . value . as_deref ( ) {
432
- None => remove_var ( self . key ) ,
433
- Some ( value) => set_var ( self . key , value) ,
434
- }
435
- }
436
- }
0 commit comments