Skip to content

Commit bccb9bb

Browse files
committed
Auto merge of #120881 - jieyouxu:migrate-ui-test-directives, r=oli-obk
Migrate ui tests from legacy compiletest-style directives `//` to `ui_test`-style directives `//@` ## Preface There's an on-going effort to rewrite parts of or the entirety of compiletest (<rust-lang/compiler-team#536>). A step towards this involve migrating ui tests to use the [`ui_test`](https://github.com/oli-obk/ui_test) framework, which involves changing compiletest directives in `// <directive-name>` style to `ui_test` `//@ <directive-name>` style (rust-lang/compiler-team#512). This PR aims to implement the directive-style change from `//` to `//`@`` for ui tests only and make compiletest only accept `//`@`` directives in the "ui" test suite (only). ## Key Changes 1. All ui test `//` directives are replaced by `//`@`` directives. 2. Only accept `//`@`` directives for "ui" test suite. 3. Errors if a comment could be interpreted as a legacy-style `//` directive. ## Diff Generation The diff is generated by: - Collecting directives from ui tests via hacking on compiletest. - Using a migration tool to replace `//` directives in ui tests with `//`@`.` ### Reproduction Steps 0. Delete the temporary directory `$RUSTC_REPO_PATH/build/x86_64-apple-darwin/test/ui/__directive_lines` and the temporary file `$RUSTC_REPO_PATH/build/x86_64-apple-darwin/test/ui/__directive_lines.txt` (if you ran the collection script before). 1. Use the <https://github.com/jieyouxu/rust/tree/collect-test-directives> collect-test-directives script, which outputs temporary files recording headers occuring in each ui test. - You need to checkout this branch: `git checkout collect-test-directives`. - You might need to rebase on lastest master and ensure there are no conflicts. - You likely need to run `./x test tests/ui --stage 1 --force-rerun` to generate the temporary files consistently. 2. Checkout the `migrate-ui-test-directives` branch. 4. Run the migration tool <https://github.com/jieyouxu/compiletest-ui_test-header-migration>. - You will need to first generate a `migration_config.toml` via `cargo run -- generate-config` under `$CWD`. - Then, update `manual_directives = ["// should-fail"]` in `migration_config.toml`. This is required because the collection script doesn't deal with some special meta ui tests and there are no other `// should-fail` occurrences. 5. Check that the migration at least does not cause UI test failures if you change compiletest to accept `//`@`` directives for ui tests only. - `RUSTC_TEST_FAIL_FAST=1 ./x test tests/ui --stage 1 --bless` 6. Confirm that there is no difference after running the migration tool when you are on the `migrate-ui-test-directives` branch. ## Next Steps - [x] ~~Need to implement some kind of warning or tidy script to help contributors catch old-style `// <directive-name>` directives, while only accepting `ui_test`-style `//@ <directive-name>` directives.~~ An error is emitted if a comment that could be interpreted as legacy-style test directive is encountered. - [ ] Need to properly document this change in e.g. rustc-dev-guide (rust-lang/rustc-dev-guide#1885). - [x] Add a `README.md` to `tests/ui` describing the directive style change.
2 parents 93a65c6 + ec2cc76 commit bccb9bb

File tree

9,930 files changed

+17008
-16703
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

9,930 files changed

+17008
-16703
lines changed

src/tools/compiletest/src/header.rs

+480-230
Large diffs are not rendered by default.

src/tools/compiletest/src/header/tests.rs

+77-70
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,15 @@ fn should_fail() {
210210

211211
let d = make_test_description(&config, tn.clone(), p, std::io::Cursor::new(""), None);
212212
assert_eq!(d.should_panic, test::ShouldPanic::No);
213-
let d = make_test_description(&config, tn, p, std::io::Cursor::new("// should-fail"), None);
213+
let d = make_test_description(&config, tn, p, std::io::Cursor::new("//@ should-fail"), None);
214214
assert_eq!(d.should_panic, test::ShouldPanic::Yes);
215215
}
216216

217217
#[test]
218218
fn revisions() {
219219
let config: Config = cfg().build();
220220

221-
assert_eq!(parse_rs(&config, "// revisions: a b c").revisions, vec!["a", "b", "c"],);
221+
assert_eq!(parse_rs(&config, "//@ revisions: a b c").revisions, vec!["a", "b", "c"],);
222222
assert_eq!(
223223
parse_makefile(&config, "# revisions: hello there").revisions,
224224
vec!["hello", "there"],
@@ -233,8 +233,8 @@ fn aux_build() {
233233
parse_rs(
234234
&config,
235235
r"
236-
// aux-build: a.rs
237-
// aux-build: b.rs
236+
//@ aux-build: a.rs
237+
//@ aux-build: b.rs
238238
"
239239
)
240240
.aux,
@@ -245,128 +245,128 @@ fn aux_build() {
245245
#[test]
246246
fn llvm_version() {
247247
let config: Config = cfg().llvm_version("8.1.2").build();
248-
assert!(check_ignore(&config, "// min-llvm-version: 9.0"));
248+
assert!(check_ignore(&config, "//@ min-llvm-version: 9.0"));
249249

250250
let config: Config = cfg().llvm_version("9.0.1").build();
251-
assert!(check_ignore(&config, "// min-llvm-version: 9.2"));
251+
assert!(check_ignore(&config, "//@ min-llvm-version: 9.2"));
252252

253253
let config: Config = cfg().llvm_version("9.3.1").build();
254-
assert!(!check_ignore(&config, "// min-llvm-version: 9.2"));
254+
assert!(!check_ignore(&config, "//@ min-llvm-version: 9.2"));
255255

256256
let config: Config = cfg().llvm_version("10.0.0").build();
257-
assert!(!check_ignore(&config, "// min-llvm-version: 9.0"));
257+
assert!(!check_ignore(&config, "//@ min-llvm-version: 9.0"));
258258
}
259259

260260
#[test]
261261
fn system_llvm_version() {
262262
let config: Config = cfg().system_llvm(true).llvm_version("17.0.0").build();
263-
assert!(check_ignore(&config, "// min-system-llvm-version: 18.0"));
263+
assert!(check_ignore(&config, "//@ min-system-llvm-version: 18.0"));
264264

265265
let config: Config = cfg().system_llvm(true).llvm_version("18.0.0").build();
266-
assert!(!check_ignore(&config, "// min-system-llvm-version: 18.0"));
266+
assert!(!check_ignore(&config, "//@ min-system-llvm-version: 18.0"));
267267

268268
let config: Config = cfg().llvm_version("17.0.0").build();
269-
assert!(!check_ignore(&config, "// min-system-llvm-version: 18.0"));
269+
assert!(!check_ignore(&config, "//@ min-system-llvm-version: 18.0"));
270270
}
271271

272272
#[test]
273273
fn ignore_target() {
274274
let config: Config = cfg().target("x86_64-unknown-linux-gnu").build();
275275

276-
assert!(check_ignore(&config, "// ignore-x86_64-unknown-linux-gnu"));
277-
assert!(check_ignore(&config, "// ignore-x86_64"));
278-
assert!(check_ignore(&config, "// ignore-linux"));
279-
assert!(check_ignore(&config, "// ignore-gnu"));
280-
assert!(check_ignore(&config, "// ignore-64bit"));
276+
assert!(check_ignore(&config, "//@ ignore-x86_64-unknown-linux-gnu"));
277+
assert!(check_ignore(&config, "//@ ignore-x86_64"));
278+
assert!(check_ignore(&config, "//@ ignore-linux"));
279+
assert!(check_ignore(&config, "//@ ignore-gnu"));
280+
assert!(check_ignore(&config, "//@ ignore-64bit"));
281281

282-
assert!(!check_ignore(&config, "// ignore-x86"));
283-
assert!(!check_ignore(&config, "// ignore-windows"));
284-
assert!(!check_ignore(&config, "// ignore-msvc"));
285-
assert!(!check_ignore(&config, "// ignore-32bit"));
282+
assert!(!check_ignore(&config, "//@ ignore-x86"));
283+
assert!(!check_ignore(&config, "//@ ignore-windows"));
284+
assert!(!check_ignore(&config, "//@ ignore-msvc"));
285+
assert!(!check_ignore(&config, "//@ ignore-32bit"));
286286
}
287287

288288
#[test]
289289
fn only_target() {
290290
let config: Config = cfg().target("x86_64-pc-windows-gnu").build();
291291

292-
assert!(check_ignore(&config, "// only-x86"));
293-
assert!(check_ignore(&config, "// only-linux"));
294-
assert!(check_ignore(&config, "// only-msvc"));
295-
assert!(check_ignore(&config, "// only-32bit"));
292+
assert!(check_ignore(&config, "//@ only-x86"));
293+
assert!(check_ignore(&config, "//@ only-linux"));
294+
assert!(check_ignore(&config, "//@ only-msvc"));
295+
assert!(check_ignore(&config, "//@ only-32bit"));
296296

297-
assert!(!check_ignore(&config, "// only-x86_64-pc-windows-gnu"));
298-
assert!(!check_ignore(&config, "// only-x86_64"));
299-
assert!(!check_ignore(&config, "// only-windows"));
300-
assert!(!check_ignore(&config, "// only-gnu"));
301-
assert!(!check_ignore(&config, "// only-64bit"));
297+
assert!(!check_ignore(&config, "//@ only-x86_64-pc-windows-gnu"));
298+
assert!(!check_ignore(&config, "//@ only-x86_64"));
299+
assert!(!check_ignore(&config, "//@ only-windows"));
300+
assert!(!check_ignore(&config, "//@ only-gnu"));
301+
assert!(!check_ignore(&config, "//@ only-64bit"));
302302
}
303303

304304
#[test]
305305
fn stage() {
306306
let config: Config = cfg().stage_id("stage1-x86_64-unknown-linux-gnu").build();
307307

308-
assert!(check_ignore(&config, "// ignore-stage1"));
309-
assert!(!check_ignore(&config, "// ignore-stage2"));
308+
assert!(check_ignore(&config, "//@ ignore-stage1"));
309+
assert!(!check_ignore(&config, "//@ ignore-stage2"));
310310
}
311311

312312
#[test]
313313
fn cross_compile() {
314314
let config: Config = cfg().host("x86_64-apple-darwin").target("wasm32-unknown-unknown").build();
315-
assert!(check_ignore(&config, "// ignore-cross-compile"));
315+
assert!(check_ignore(&config, "//@ ignore-cross-compile"));
316316

317317
let config: Config = cfg().host("x86_64-apple-darwin").target("x86_64-apple-darwin").build();
318-
assert!(!check_ignore(&config, "// ignore-cross-compile"));
318+
assert!(!check_ignore(&config, "//@ ignore-cross-compile"));
319319
}
320320

321321
#[test]
322322
fn debugger() {
323323
let mut config = cfg().build();
324324
config.debugger = None;
325-
assert!(!check_ignore(&config, "// ignore-cdb"));
325+
assert!(!check_ignore(&config, "//@ ignore-cdb"));
326326

327327
config.debugger = Some(Debugger::Cdb);
328-
assert!(check_ignore(&config, "// ignore-cdb"));
328+
assert!(check_ignore(&config, "//@ ignore-cdb"));
329329

330330
config.debugger = Some(Debugger::Gdb);
331-
assert!(check_ignore(&config, "// ignore-gdb"));
331+
assert!(check_ignore(&config, "//@ ignore-gdb"));
332332

333333
config.debugger = Some(Debugger::Lldb);
334-
assert!(check_ignore(&config, "// ignore-lldb"));
334+
assert!(check_ignore(&config, "//@ ignore-lldb"));
335335
}
336336

337337
#[test]
338338
fn git_hash() {
339339
let config: Config = cfg().git_hash(false).build();
340-
assert!(check_ignore(&config, "// needs-git-hash"));
340+
assert!(check_ignore(&config, "//@ needs-git-hash"));
341341

342342
let config: Config = cfg().git_hash(true).build();
343-
assert!(!check_ignore(&config, "// needs-git-hash"));
343+
assert!(!check_ignore(&config, "//@ needs-git-hash"));
344344
}
345345

346346
#[test]
347347
fn sanitizers() {
348348
// Target that supports all sanitizers:
349349
let config: Config = cfg().target("x86_64-unknown-linux-gnu").build();
350-
assert!(!check_ignore(&config, "// needs-sanitizer-address"));
351-
assert!(!check_ignore(&config, "// needs-sanitizer-leak"));
352-
assert!(!check_ignore(&config, "// needs-sanitizer-memory"));
353-
assert!(!check_ignore(&config, "// needs-sanitizer-thread"));
350+
assert!(!check_ignore(&config, "//@ needs-sanitizer-address"));
351+
assert!(!check_ignore(&config, "//@ needs-sanitizer-leak"));
352+
assert!(!check_ignore(&config, "//@ needs-sanitizer-memory"));
353+
assert!(!check_ignore(&config, "//@ needs-sanitizer-thread"));
354354

355355
// Target that doesn't support sanitizers:
356356
let config: Config = cfg().target("wasm32-unknown-emscripten").build();
357-
assert!(check_ignore(&config, "// needs-sanitizer-address"));
358-
assert!(check_ignore(&config, "// needs-sanitizer-leak"));
359-
assert!(check_ignore(&config, "// needs-sanitizer-memory"));
360-
assert!(check_ignore(&config, "// needs-sanitizer-thread"));
357+
assert!(check_ignore(&config, "//@ needs-sanitizer-address"));
358+
assert!(check_ignore(&config, "//@ needs-sanitizer-leak"));
359+
assert!(check_ignore(&config, "//@ needs-sanitizer-memory"));
360+
assert!(check_ignore(&config, "//@ needs-sanitizer-thread"));
361361
}
362362

363363
#[test]
364364
fn profiler_support() {
365365
let config: Config = cfg().profiler_support(false).build();
366-
assert!(check_ignore(&config, "// needs-profiler-support"));
366+
assert!(check_ignore(&config, "//@ needs-profiler-support"));
367367

368368
let config: Config = cfg().profiler_support(true).build();
369-
assert!(!check_ignore(&config, "// needs-profiler-support"));
369+
assert!(!check_ignore(&config, "//@ needs-profiler-support"));
370370
}
371371

372372
#[test]
@@ -382,21 +382,21 @@ fn asm_support() {
382382
for (target, has_asm) in asms {
383383
let config = cfg().target(target).build();
384384
assert_eq!(config.has_asm_support(), has_asm);
385-
assert_eq!(check_ignore(&config, "// needs-asm-support"), !has_asm)
385+
assert_eq!(check_ignore(&config, "//@ needs-asm-support"), !has_asm)
386386
}
387387
}
388388

389389
#[test]
390390
fn channel() {
391391
let config: Config = cfg().channel("beta").build();
392392

393-
assert!(check_ignore(&config, "// ignore-beta"));
394-
assert!(check_ignore(&config, "// only-nightly"));
395-
assert!(check_ignore(&config, "// only-stable"));
393+
assert!(check_ignore(&config, "//@ ignore-beta"));
394+
assert!(check_ignore(&config, "//@ only-nightly"));
395+
assert!(check_ignore(&config, "//@ only-stable"));
396396

397-
assert!(!check_ignore(&config, "// only-beta"));
398-
assert!(!check_ignore(&config, "// ignore-nightly"));
399-
assert!(!check_ignore(&config, "// ignore-stable"));
397+
assert!(!check_ignore(&config, "//@ only-beta"));
398+
assert!(!check_ignore(&config, "//@ ignore-nightly"));
399+
assert!(!check_ignore(&config, "//@ ignore-stable"));
400400
}
401401

402402
#[test]
@@ -418,7 +418,7 @@ fn test_extract_version_range() {
418418
#[should_panic(expected = "Duplicate revision: `rpass1` in line ` rpass1 rpass1`")]
419419
fn test_duplicate_revisions() {
420420
let config: Config = cfg().build();
421-
parse_rs(&config, "// revisions: rpass1 rpass1");
421+
parse_rs(&config, "//@ revisions: rpass1 rpass1");
422422
}
423423

424424
#[test]
@@ -432,7 +432,7 @@ fn ignore_arch() {
432432
for (target, arch) in archs {
433433
let config: Config = cfg().target(target).build();
434434
assert!(config.matches_arch(arch), "{target} {arch}");
435-
assert!(check_ignore(&config, &format!("// ignore-{arch}")));
435+
assert!(check_ignore(&config, &format!("//@ ignore-{arch}")));
436436
}
437437
}
438438

@@ -447,7 +447,7 @@ fn matches_os() {
447447
for (target, os) in oss {
448448
let config = cfg().target(target).build();
449449
assert!(config.matches_os(os), "{target} {os}");
450-
assert!(check_ignore(&config, &format!("// ignore-{os}")));
450+
assert!(check_ignore(&config, &format!("//@ ignore-{os}")));
451451
}
452452
}
453453

@@ -461,7 +461,7 @@ fn matches_env() {
461461
for (target, env) in envs {
462462
let config: Config = cfg().target(target).build();
463463
assert!(config.matches_env(env), "{target} {env}");
464-
assert!(check_ignore(&config, &format!("// ignore-{env}")));
464+
assert!(check_ignore(&config, &format!("//@ ignore-{env}")));
465465
}
466466
}
467467

@@ -475,7 +475,7 @@ fn matches_abi() {
475475
for (target, abi) in abis {
476476
let config: Config = cfg().target(target).build();
477477
assert!(config.matches_abi(abi), "{target} {abi}");
478-
assert!(check_ignore(&config, &format!("// ignore-{abi}")));
478+
assert!(check_ignore(&config, &format!("//@ ignore-{abi}")));
479479
}
480480
}
481481

@@ -491,7 +491,7 @@ fn is_big_endian() {
491491
for (target, is_big) in endians {
492492
let config = cfg().target(target).build();
493493
assert_eq!(config.is_big_endian(), is_big, "{target} {is_big}");
494-
assert_eq!(check_ignore(&config, "// ignore-endian-big"), is_big);
494+
assert_eq!(check_ignore(&config, "//@ ignore-endian-big"), is_big);
495495
}
496496
}
497497

@@ -506,9 +506,9 @@ fn pointer_width() {
506506
for (target, width) in widths {
507507
let config: Config = cfg().target(target).build();
508508
assert_eq!(config.get_pointer_width(), width, "{target} {width}");
509-
assert_eq!(check_ignore(&config, "// ignore-16bit"), width == 16);
510-
assert_eq!(check_ignore(&config, "// ignore-32bit"), width == 32);
511-
assert_eq!(check_ignore(&config, "// ignore-64bit"), width == 64);
509+
assert_eq!(check_ignore(&config, "//@ ignore-16bit"), width == 16);
510+
assert_eq!(check_ignore(&config, "//@ ignore-32bit"), width == 32);
511+
assert_eq!(check_ignore(&config, "//@ ignore-64bit"), width == 64);
512512
}
513513
}
514514

@@ -534,7 +534,7 @@ fn wasm_special() {
534534
for (target, pattern, ignore) in ignores {
535535
let config: Config = cfg().target(target).build();
536536
assert_eq!(
537-
check_ignore(&config, &format!("// ignore-{pattern}")),
537+
check_ignore(&config, &format!("//@ ignore-{pattern}")),
538538
ignore,
539539
"{target} {pattern}"
540540
);
@@ -555,8 +555,8 @@ fn families() {
555555
assert!(config.matches_family(family));
556556
let other = if family == "windows" { "unix" } else { "windows" };
557557
assert!(!config.matches_family(other));
558-
assert!(check_ignore(&config, &format!("// ignore-{family}")));
559-
assert!(!check_ignore(&config, &format!("// ignore-{other}")));
558+
assert!(check_ignore(&config, &format!("//@ ignore-{family}")));
559+
assert!(!check_ignore(&config, &format!("//@ ignore-{other}")));
560560
}
561561
}
562562

@@ -566,10 +566,17 @@ fn ignore_mode() {
566566
// Indicate profiler support so that "coverage-run" tests aren't skipped.
567567
let config: Config = cfg().mode(mode).profiler_support(true).build();
568568
let other = if mode == "coverage-run" { "coverage-map" } else { "coverage-run" };
569+
569570
assert_ne!(mode, other);
570571
assert_eq!(config.mode, Mode::from_str(mode).unwrap());
571572
assert_ne!(config.mode, Mode::from_str(other).unwrap());
572-
assert!(check_ignore(&config, &format!("// ignore-mode-{mode}")));
573-
assert!(!check_ignore(&config, &format!("// ignore-mode-{other}")));
573+
574+
if mode == "ui" {
575+
assert!(check_ignore(&config, &format!("//@ ignore-mode-{mode}")));
576+
assert!(!check_ignore(&config, &format!("//@ ignore-mode-{other}")));
577+
} else {
578+
assert!(check_ignore(&config, &format!("// ignore-mode-{mode}")));
579+
assert!(!check_ignore(&config, &format!("// ignore-mode-{other}")));
580+
}
574581
}
575582
}

src/tools/tidy/src/style.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ const ANNOTATIONS_TO_IGNORE: &[&str] = &[
5555
"// CHECK",
5656
"// EMIT_MIR",
5757
"// compile-flags",
58+
"//@ compile-flags",
5859
"// error-pattern",
60+
"//@ error-pattern",
5961
"// gdb",
6062
"// lldb",
6163
"// cdb",
6264
"// normalize-stderr-test",
65+
"//@ normalize-stderr-test",
6366
];
6467

6568
// Intentionally written in decimal rather than hex
@@ -128,7 +131,15 @@ fn should_ignore(line: &str) -> bool {
128131
// This mirrors the regex in src/tools/compiletest/src/runtest.rs, please
129132
// update both if either are changed.
130133
let re = Regex::new("\\s*//(\\[.*\\])?~.*").unwrap();
131-
re.is_match(line) || ANNOTATIONS_TO_IGNORE.iter().any(|a| line.contains(a))
134+
// For `ui_test`-style UI test directives, also ignore
135+
// - `//@[rev] compile-flags`
136+
// - `//@[rev] normalize-stderr-test`
137+
let ui_test_long_directives =
138+
Regex::new("\\s*//@(\\[.*\\]) (compile-flags|normalize-stderr-test|error-pattern).*")
139+
.unwrap();
140+
re.is_match(line)
141+
|| ANNOTATIONS_TO_IGNORE.iter().any(|a| line.contains(a))
142+
|| ui_test_long_directives.is_match(line)
132143
}
133144

134145
/// Returns `true` if `line` is allowed to be longer than the normal limit.

src/tools/tidy/src/ui_tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ use std::path::{Path, PathBuf};
1414
// #73494.
1515
const ENTRY_LIMIT: usize = 900;
1616
// FIXME: The following limits should be reduced eventually.
17+
1718
const ISSUES_ENTRY_LIMIT: usize = 1781;
18-
const ROOT_ENTRY_LIMIT: usize = 870;
19+
const ROOT_ENTRY_LIMIT: usize = 871;
1920

2021
const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[
2122
"rs", // test source files

0 commit comments

Comments
 (0)