1
- #![feature(test)] // compiletest_rs requires this attribute
2
1
#![feature(lazy_cell)]
3
2
#![feature(is_sorted)]
4
3
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
@@ -117,24 +116,32 @@ fn canonicalize(path: impl AsRef<Path>) -> PathBuf {
117
116
}
118
117
119
118
fn 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
+
121
134
let mut config = compiletest::Config {
122
135
mode: TestMode::Yolo { rustfix: true },
123
136
stderr_filters: vec![],
124
137
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 {
128
139
OutputConflictHandling::Bless
129
140
} else {
130
141
OutputConflictHandling::Error("cargo uibless".into())
131
142
},
132
143
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"),
138
145
..compiletest::Config::rustc(Path::new("tests").join(test_dir))
139
146
};
140
147
let current_exe_path = env::current_exe().unwrap();
@@ -172,38 +179,18 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) {
172
179
(config, args)
173
180
}
174
181
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
-
184
182
fn run_ui() {
185
183
let (config, args) = base_config("ui");
186
- //config.rustfix_coverage = true;
187
184
// use tests/clippy.toml
188
185
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());
200
187
201
188
let quiet = args.quiet;
202
189
203
190
compiletest::run_tests_generic(
204
191
vec![config],
205
192
args,
206
- move |path, args, config| compiletest::default_file_filter(path, args, config) && test_filter(path) ,
193
+ compiletest::default_file_filter,
207
194
compiletest::default_per_file_config,
208
195
if quiet {
209
196
status_emitter::Text::quiet()
@@ -221,15 +208,14 @@ fn run_internal_tests() {
221
208
}
222
209
let (mut config, args) = base_config("ui-internal");
223
210
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();
225
212
}
226
- let test_filter = test_filter();
227
213
let quiet = args.quiet;
228
214
229
215
compiletest::run_tests_generic(
230
216
vec![config],
231
217
args,
232
- move |path, args, config| compiletest::default_file_filter(path, args, config) && test_filter(path) ,
218
+ compiletest::default_file_filter,
233
219
compiletest::default_per_file_config,
234
220
if quiet {
235
221
status_emitter::Text::quiet()
@@ -255,13 +241,12 @@ fn run_ui_toml() {
255
241
"$$DIR",
256
242
);
257
243
258
- let test_filter = test_filter();
259
244
let quiet = args.quiet;
260
245
261
246
ui_test::run_tests_generic(
262
247
vec![config],
263
248
args,
264
- |path, args, config| compiletest::default_file_filter(path, args, config) && test_filter(path) ,
249
+ compiletest::default_file_filter,
265
250
|config, path, _file_contents| {
266
251
config
267
252
.program
@@ -312,13 +297,12 @@ fn run_ui_cargo() {
312
297
"$$DIR",
313
298
);
314
299
315
- let test_filter = test_filter();
316
300
let quiet = args.quiet;
317
301
318
302
ui_test::run_tests_generic(
319
303
vec![config],
320
304
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 ),
322
306
|config, path, _file_contents| {
323
307
config.out_dir = canonicalize(
324
308
std::env::current_dir()
0 commit comments