1- #![ feature( test) ] // compiletest_rs requires this attribute
21#![ feature( lazy_cell) ]
32#![ feature( is_sorted) ]
43#![ cfg_attr( feature = "deny-warnings" , deny( warnings) ) ]
@@ -117,24 +116,32 @@ fn canonicalize(path: impl AsRef<Path>) -> PathBuf {
117116}
118117
119118fn base_config ( test_dir : & str ) -> ( compiletest:: Config , Args ) {
120- let args = Args :: test ( ) . unwrap ( ) ;
119+ let bless = var_os ( "RUSTC_BLESS" ) . is_some_and ( |v| v != "0" ) || env:: args ( ) . any ( |arg| arg == "--bless" ) ;
120+
121+ let args = Args {
122+ filters : env:: var ( "TESTNAME" )
123+ . map ( |filters| filters. split ( ',' ) . map ( str:: to_string) . collect ( ) )
124+ . unwrap_or_default ( ) ,
125+ quiet : false ,
126+ check : !bless,
127+ threads : match std:: env:: var_os ( "RUST_TEST_THREADS" ) {
128+ Some ( n) => n. to_str ( ) . unwrap ( ) . parse ( ) . unwrap ( ) ,
129+ None => std:: thread:: available_parallelism ( ) . unwrap ( ) ,
130+ } ,
131+ skip : Vec :: new ( ) ,
132+ } ;
133+
121134 let mut config = compiletest:: Config {
122135 mode : TestMode :: Yolo { rustfix : true } ,
123136 stderr_filters : vec ! [ ] ,
124137 stdout_filters : vec ! [ ] ,
125- output_conflict_handling : if var_os ( "GITHUB_ACTION" ) . is_none ( )
126- && ( var_os ( "RUSTC_BLESS" ) . is_some_and ( |v| v != "0" ) || !args. check )
127- {
138+ output_conflict_handling : if bless {
128139 OutputConflictHandling :: Bless
129140 } else {
130141 OutputConflictHandling :: Error ( "cargo uibless" . into ( ) )
131142 } ,
132143 target : None ,
133- out_dir : canonicalize (
134- std:: env:: var_os ( "CARGO_TARGET_DIR" )
135- . map_or_else ( || std:: env:: current_dir ( ) . unwrap ( ) . join ( "target" ) , PathBuf :: from) ,
136- )
137- . join ( "ui_test" ) ,
144+ out_dir : canonicalize ( std:: env:: var_os ( "CARGO_TARGET_DIR" ) . unwrap_or_else ( || "target" . into ( ) ) ) . join ( "ui_test" ) ,
138145 ..compiletest:: Config :: rustc ( Path :: new ( "tests" ) . join ( test_dir) )
139146 } ;
140147 let current_exe_path = env:: current_exe ( ) . unwrap ( ) ;
@@ -172,38 +179,18 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) {
172179 ( config, args)
173180}
174181
175- fn test_filter ( ) -> Box < dyn Sync + Fn ( & Path ) -> bool > {
176- if let Ok ( filters) = env:: var ( "TESTNAME" ) {
177- let filters: Vec < _ > = filters. split ( ',' ) . map ( ToString :: to_string) . collect ( ) ;
178- Box :: new ( move |path| filters. iter ( ) . any ( |f| path. to_string_lossy ( ) . contains ( f) ) )
179- } else {
180- Box :: new ( |_| true )
181- }
182- }
183-
184182fn run_ui ( ) {
185183 let ( config, args) = base_config ( "ui" ) ;
186- //config.rustfix_coverage = true;
187184 // use tests/clippy.toml
188185 let _g = VarGuard :: set ( "CARGO_MANIFEST_DIR" , canonicalize ( "tests" ) ) ;
189- let _threads = VarGuard :: set (
190- "RUST_TEST_THREADS" ,
191- // if RUST_TEST_THREADS is set, adhere to it, otherwise override it
192- env:: var ( "RUST_TEST_THREADS" ) . unwrap_or_else ( |_| {
193- std:: thread:: available_parallelism ( )
194- . map_or ( 1 , std:: num:: NonZeroUsize :: get)
195- . to_string ( )
196- } ) ,
197- ) ;
198-
199- let test_filter = test_filter ( ) ;
186+ let _threads = VarGuard :: set ( "RUST_TEST_THREADS" , args. threads . to_string ( ) ) ;
200187
201188 let quiet = args. quiet ;
202189
203190 compiletest:: run_tests_generic (
204191 vec ! [ config] ,
205192 args,
206- move |path , args , config| compiletest:: default_file_filter ( path , args , config ) && test_filter ( path ) ,
193+ compiletest:: default_file_filter,
207194 compiletest:: default_per_file_config,
208195 if quiet {
209196 status_emitter:: Text :: quiet ( )
@@ -221,15 +208,14 @@ fn run_internal_tests() {
221208 }
222209 let ( mut config, args) = base_config ( "ui-internal" ) ;
223210 if let OutputConflictHandling :: Error ( err) = & mut config. output_conflict_handling {
224- * err = "cargo uitest --features internal" . into ( ) ;
211+ * err = "cargo uitest --features internal -- -- --bless " . into ( ) ;
225212 }
226- let test_filter = test_filter ( ) ;
227213 let quiet = args. quiet ;
228214
229215 compiletest:: run_tests_generic (
230216 vec ! [ config] ,
231217 args,
232- move |path , args , config| compiletest:: default_file_filter ( path , args , config ) && test_filter ( path ) ,
218+ compiletest:: default_file_filter,
233219 compiletest:: default_per_file_config,
234220 if quiet {
235221 status_emitter:: Text :: quiet ( )
@@ -255,13 +241,12 @@ fn run_ui_toml() {
255241 "$$DIR" ,
256242 ) ;
257243
258- let test_filter = test_filter ( ) ;
259244 let quiet = args. quiet ;
260245
261246 ui_test:: run_tests_generic (
262247 vec ! [ config] ,
263248 args,
264- |path , args , config| compiletest:: default_file_filter ( path , args , config ) && test_filter ( path ) ,
249+ compiletest:: default_file_filter,
265250 |config, path, _file_contents| {
266251 config
267252 . program
@@ -312,13 +297,12 @@ fn run_ui_cargo() {
312297 "$$DIR" ,
313298 ) ;
314299
315- let test_filter = test_filter ( ) ;
316300 let quiet = args. quiet ;
317301
318302 ui_test:: run_tests_generic (
319303 vec ! [ config] ,
320304 args,
321- |path, _args , _config| test_filter ( path) && path . ends_with ( "Cargo.toml" ) ,
305+ |path, args , _config| path. ends_with ( "Cargo.toml" ) && ui_test :: default_filter_by_arg ( path , args ) ,
322306 |config, path, _file_contents| {
323307 config. out_dir = canonicalize (
324308 std:: env:: current_dir ( )
0 commit comments