Skip to content

Commit 806b54b

Browse files
committed
Auto merge of rust-lang#121370 - jieyouxu:migrate-compiletest-directives, r=oli-obk
Migrate compiletest to use `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 compiletest 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 the remaining non-"ui" test suite tests. ## Key Changes 1. All `tests/` tests now use `//`@`` directives. 2. Compiletest only accepts `//`@`` and issues an error if an old-style directive is detected. 3. `// ignore-tidy` and `// ignore-tidy-*` are considered tidy directives and are ignored by compiletest header parsing. ## Diff Generation The diff is generated by: - Collecting directives from `tests/` via hijacking compiletest to emit successfully parsed directive lines. - Using a migration tool (<https://github.com/jieyouxu/compiletest-ui_test-header-migration/tree/master>) to replace `//` directives in compiletest tests with `//`@`.` ### Reproduction Steps 0. Delete the temporary file `$RUSTC_REPO_PATH/build/<target_triple>/test/__directive_lines.txt`, if the collection script was previously ran. 1. Use the <https://github.com/jieyouxu/rust/tree/collect-test-directives> collect-test-directives script, which outputs a temporary file recording headers occuring in each compiletest test. - You need to checkout this branch: `git checkout collect-test-directives`. - This needs to be rebased on latest master to ensure up-to-date test directives can be collected. - You need to run `./x test` on each of the `test/*` subfolders once: ```bash ./x test tests/assembly/ --stage 1 --force-rerun ./x test tests/codegen/ --stage 1 --force-rerun ./x test tests/codegen-units/ --stage 1 --force-rerun ./x test tests/coverage/ --stage 1 --force-rerun ./x test tests/coverage-run-rustdoc/ --stage 1 --force-rerun ./x test tests/debuginfo/ --stage 1 --force-rerun ./x test tests/incremental/ --stage 1 --force-rerun ./x test tests/mir-opt/ --stage 1 --force-rerun ./x test tests/pretty/ --stage 1 --force-rerun ./x test tests/run-make/ --stage 1 --force-rerun ./x test tests/run-make-fulldeps/ --stage 1 --force-rerun ./x test tests/run-pass-valgrind/ --stage 1 --force-rerun ./x test tests/rustdoc/ --stage 1 --force-rerun TARGET=<target-triple> ./x test tests/rustdoc-gui/ --stage 1 --force-rerun ./x test tests/rustdoc-js/ --stage 1 --force-rerun ./x test tests/rustdoc-js-std/ --stage 1 --force-rerun ./x test tests/rustdoc-json/ --stage 1 --force-rerun ./x test tests/rustdoc-ui/ --stage 1 --force-rerun ./x test tests/ui/ --stage 1 --force-rerun ./x test tests/ui-fulldeps/ --stage 1 --force-rerun ``` 2. Checkout the `migrate-compiletest-directives` branch. 3. Run the migration tool <https://github.com/jieyouxu/compiletest-ui_test-header-migration>. 4. Check that the migration at least does not cause test failures if you change compiletest to accept `//`@`` directives only. This is also required if the test outputs somehow need to be blessed. - `RUSTC_TEST_FAIL_FAST=1 ./x test tests/<secondary-directory> --stage 1 --bless` 5. Confirm that there is no difference after running the migration tool when you are on the `migrate-compiletest-directives` branch. ## Follow Up Work - [ ] Adjust rustc-dev-guide docs for compiletest directives (this time for all the other suites and modes).
2 parents d7bd9cd + c3c8ad9 commit 806b54b

File tree

1,837 files changed

+4881
-4844
lines changed

Some content is hidden

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

1,837 files changed

+4881
-4844
lines changed

src/tools/compiletest/src/header.rs

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -676,14 +676,17 @@ pub fn line_directive<'line>(
676676
/// names. This is **not** an exhaustive list of all possible directives. Instead, this is a
677677
/// best-effort approximation for diagnostics.
678678
const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
679+
"assembly-output",
679680
"aux-build",
680681
"aux-crate",
682+
"build-aux-docs",
681683
"build-fail",
682684
"build-pass",
683685
"check-fail",
684686
"check-pass",
685687
"check-run-results",
686688
"check-stdout",
689+
"check-test-line-numbers-match",
687690
"compile-flags",
688691
"dont-check-compiler-stderr",
689692
"dont-check-compiler-stdout",
@@ -694,12 +697,16 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
694697
"failure-status",
695698
"forbid-output",
696699
"force-host",
700+
"ignore-16bit",
697701
"ignore-32bit",
698702
"ignore-64bit",
699703
"ignore-aarch64",
700704
"ignore-aarch64-unknown-linux-gnu",
701705
"ignore-android",
702706
"ignore-arm",
707+
"ignore-avr",
708+
"ignore-beta",
709+
"ignore-cdb",
703710
"ignore-compare-mode-next-solver",
704711
"ignore-compare-mode-polonius",
705712
"ignore-cross-compile",
@@ -708,13 +715,21 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
708715
"ignore-endian-big",
709716
"ignore-freebsd",
710717
"ignore-fuchsia",
718+
"ignore-gdb",
719+
"ignore-gdb-version",
711720
"ignore-gnu",
712721
"ignore-haiku",
713722
"ignore-horizon",
714723
"ignore-i686-pc-windows-msvc",
715724
"ignore-ios",
725+
"ignore-linux",
726+
"ignore-lldb",
716727
"ignore-llvm-version",
728+
"ignore-loongarch64",
717729
"ignore-macos",
730+
"ignore-mode-coverage-map",
731+
"ignore-mode-coverage-run",
732+
"ignore-msp430",
718733
"ignore-msvc",
719734
"ignore-musl",
720735
"ignore-netbsd",
@@ -723,8 +738,13 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
723738
"ignore-nvptx64",
724739
"ignore-openbsd",
725740
"ignore-pass",
741+
"ignore-remote",
742+
"ignore-riscv64",
743+
"ignore-s390x",
726744
"ignore-sgx",
727745
"ignore-spirv",
746+
"ignore-stable",
747+
"ignore-stage1",
728748
"ignore-test",
729749
"ignore-thumbv8m.base-none-eabi",
730750
"ignore-thumbv8m.main-none-eabi",
@@ -734,9 +754,15 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
734754
"ignore-wasm32",
735755
"ignore-wasm32-bare",
736756
"ignore-windows",
757+
"ignore-windows-gnu",
737758
"ignore-x86",
759+
"ignore-x86_64-apple-darwin",
738760
"incremental",
739761
"known-bug",
762+
"llvm-cov-flags",
763+
"min-cdb-version",
764+
"min-gdb-version",
765+
"min-lldb-version",
740766
"min-llvm-version",
741767
"needs-asm-support",
742768
"needs-dlltool",
@@ -745,11 +771,15 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
745771
"needs-profiler-support",
746772
"needs-relocation-model-pic",
747773
"needs-run-enabled",
774+
"needs-rust-lldb",
748775
"needs-sanitizer-address",
749776
"needs-sanitizer-cfi",
750777
"needs-sanitizer-hwaddress",
751778
"needs-sanitizer-leak",
752779
"needs-sanitizer-memory",
780+
"needs-sanitizer-memtag",
781+
"needs-sanitizer-safestack",
782+
"needs-sanitizer-shadow-call-stack",
753783
"needs-sanitizer-support",
754784
"needs-sanitizer-thread",
755785
"needs-unwind",
@@ -759,23 +789,42 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
759789
"normalize-stderr-64bit",
760790
"normalize-stderr-test",
761791
"normalize-stdout-test",
792+
"only-16bit",
762793
"only-32bit",
763794
"only-64bit",
764795
"only-aarch64",
796+
"only-arm",
797+
"only-avr",
798+
"only-bpf",
799+
"only-cdb",
765800
"only-gnu",
766801
"only-i686-pc-windows-msvc",
767802
"only-linux",
803+
"only-loongarch64",
804+
"only-loongarch64-unknown-linux-gnu",
768805
"only-macos",
806+
"only-mips",
807+
"only-mips64",
808+
"only-msp430",
769809
"only-msvc",
770810
"only-nightly",
811+
"only-nvptx64",
812+
"only-riscv64",
813+
"only-sparc",
814+
"only-sparc64",
815+
"only-thumb",
771816
"only-wasm32",
817+
"only-wasm32-bare",
772818
"only-windows",
773819
"only-x86",
774820
"only-x86_64",
821+
"only-x86_64-fortanix-unknown-sgx",
775822
"only-x86_64-pc-windows-msvc",
776823
"only-x86_64-unknown-linux-gnu",
777824
"pp-exact",
825+
"pretty-compare-only",
778826
"pretty-expanded",
827+
"pretty-mode",
779828
"regex-error-pattern",
780829
"remap-src-base",
781830
"revisions",
@@ -786,7 +835,10 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
786835
"rustc-env",
787836
"rustfix-only-machine-applicable",
788837
"should-fail",
838+
"should-ice",
789839
"stderr-per-bitwidth",
840+
"unit-test",
841+
"unset-exec-env",
790842
"unset-rustc-env",
791843
];
792844

@@ -804,7 +856,7 @@ struct HeaderLine<'ln> {
804856

805857
fn iter_header(
806858
mode: Mode,
807-
suite: &str,
859+
_suite: &str,
808860
poisoned: &mut bool,
809861
testfile: &Path,
810862
rdr: impl Read,
@@ -835,11 +887,7 @@ fn iter_header(
835887
}
836888
}
837889

838-
let comment = if testfile.extension().is_some_and(|e| e == "rs") {
839-
if mode == Mode::Ui && suite == "ui" { "//@" } else { "//" }
840-
} else {
841-
"#"
842-
};
890+
let comment = if testfile.extension().is_some_and(|e| e == "rs") { "//@" } else { "#" };
843891

844892
let mut rdr = BufReader::with_capacity(1024, rdr);
845893
let mut ln = String::new();
@@ -866,7 +914,7 @@ fn iter_header(
866914
// First try to accept `ui_test` style comments
867915
} else if let Some((header_revision, directive)) = line_directive(comment, ln) {
868916
it(HeaderLine { header_revision, original_line, directive, line_number });
869-
} else if mode == Mode::Ui && suite == "ui" && !REVISION_MAGIC_COMMENT_RE.is_match(ln) {
917+
} else if !REVISION_MAGIC_COMMENT_RE.is_match(ln) {
870918
let Some((_, rest)) = line_directive("//", ln) else {
871919
continue;
872920
};
@@ -886,7 +934,7 @@ fn iter_header(
886934
// directive. We emit an error here to warn the user.
887935
*poisoned = true;
888936
eprintln!(
889-
"error: detected legacy-style directives in ui test: {}:{}, please use `ui_test`-style directives `//@` instead:{:#?}",
937+
"error: detected legacy-style directives in compiletest test: {}:{}, please use `ui_test`-style directives `//@` instead:{:#?}",
890938
testfile.display(),
891939
line_number,
892940
line_directive("//", ln),
@@ -899,7 +947,7 @@ fn iter_header(
899947
// directive. We emit an error here to warn the user.
900948
*poisoned = true;
901949
eprintln!(
902-
"error: detected legacy-style directives in ui test: {}:{}, please use `ui_test`-style directives `//@` instead:{:#?}",
950+
"error: detected legacy-style directives in compiletest test: {}:{}, please use `ui_test`-style directives `//@` instead:{:#?}",
903951
testfile.display(),
904952
line_number,
905953
line_directive("//", ln),
@@ -1200,11 +1248,8 @@ pub fn make_test_description<R: Read>(
12001248

12011249
if let Some((_, post)) = original_line.trim_start().split_once("//") {
12021250
let post = post.trim_start();
1203-
if post.starts_with("ignore-tidy")
1204-
&& config.mode == Mode::Ui
1205-
&& config.suite == "ui"
1206-
{
1207-
// not handled by compiletest under the ui test mode and ui test suite.
1251+
if post.starts_with("ignore-tidy") {
1252+
// Not handled by compiletest.
12081253
} else {
12091254
decision!(cfg::handle_ignore(config, ln));
12101255
}

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,7 @@ fn ignore_mode() {
571571
assert_eq!(config.mode, Mode::from_str(mode).unwrap());
572572
assert_ne!(config.mode, Mode::from_str(other).unwrap());
573573

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-
}
574+
assert!(check_ignore(&config, &format!("//@ ignore-mode-{mode}")));
575+
assert!(!check_ignore(&config, &format!("//@ ignore-mode-{other}")));
581576
}
582577
}

src/tools/compiletest/src/runtest.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3938,15 +3938,10 @@ impl<'test> TestCx<'test> {
39383938
self.props.compare_output_lines_by_subset,
39393939
);
39403940
} else if !expected_fixed.is_empty() {
3941-
if self.config.suite == "ui" {
3942-
panic!(
3943-
"the `//@ run-rustfix` directive wasn't found but a `*.fixed` file was found"
3944-
);
3945-
} else {
3946-
panic!(
3947-
"the `// run-rustfix` directive wasn't found but a `*.fixed` file was found"
3948-
);
3949-
}
3941+
panic!(
3942+
"the `//@ run-rustfix` directive wasn't found but a `*.fixed` \
3943+
file was found"
3944+
);
39503945
}
39513946

39523947
if errors > 0 {

src/tools/tidy/src/target_policy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{collections::HashSet, path::Path};
77

88
const TARGET_DEFINITIONS_PATH: &str = "compiler/rustc_target/src/spec/targets/";
99
const ASSEMBLY_TEST_PATH: &str = "tests/assembly/targets/";
10-
const REVISION_LINE_START: &str = "// revisions: ";
10+
const REVISION_LINE_START: &str = "//@ revisions: ";
1111
const EXCEPTIONS: &[&str] = &[
1212
// FIXME: disabled since it fails on CI saying the csky component is missing
1313
"csky_unknown_linux_gnuabiv2",

src/tools/tidy/src/target_specific_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::path::Path;
66

77
use crate::walk::filter_not_rust;
88

9-
const COMMENT: &str = "//";
9+
const COMMENT: &str = "//@";
1010
const LLVM_COMPONENTS_HEADER: &str = "needs-llvm-components:";
1111
const COMPILE_FLAGS_HEADER: &str = "compile-flags:";
1212

tests/assembly/aarch64-naked-fn-no-bti-prolog.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// compile-flags: -C no-prepopulate-passes -Zbranch-protection=bti
2-
// assembly-output: emit-asm
3-
// needs-asm-support
4-
// only-aarch64
1+
//@ compile-flags: -C no-prepopulate-passes -Zbranch-protection=bti
2+
//@ assembly-output: emit-asm
3+
//@ needs-asm-support
4+
//@ only-aarch64
55

66
#![crate_type = "lib"]
77
#![feature(naked_functions)]

tests/assembly/aarch64-pointer-auth.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Test that PAC instructions are emitted when branch-protection is specified.
22

3-
// assembly-output: emit-asm
4-
// compile-flags: --target aarch64-unknown-linux-gnu
5-
// compile-flags: -Z branch-protection=pac-ret,leaf
6-
// needs-llvm-components: aarch64
3+
//@ assembly-output: emit-asm
4+
//@ compile-flags: --target aarch64-unknown-linux-gnu
5+
//@ compile-flags: -Z branch-protection=pac-ret,leaf
6+
//@ needs-llvm-components: aarch64
77

88
#![feature(no_core, lang_items)]
99
#![no_std]

tests/assembly/align_offset.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// assembly-output: emit-asm
2-
// compile-flags: -Copt-level=1
3-
// only-x86_64
1+
//@ assembly-output: emit-asm
2+
//@ compile-flags: -Copt-level=1
3+
//@ only-x86_64
44
#![crate_type="rlib"]
55

66
// CHECK-LABEL: align_offset_byte_ptr

tests/assembly/asm/aarch64-el2vmsa.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// assembly-output: emit-asm
2-
// compile-flags: --target aarch64-unknown-linux-gnu
3-
// needs-llvm-components: aarch64
1+
//@ assembly-output: emit-asm
2+
//@ compile-flags: --target aarch64-unknown-linux-gnu
3+
//@ needs-llvm-components: aarch64
44

55
#![feature(no_core, lang_items, rustc_attrs)]
66
#![crate_type = "rlib"]

tests/assembly/asm/aarch64-modifiers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// assembly-output: emit-asm
2-
// compile-flags: -O
3-
// compile-flags: --target aarch64-unknown-linux-gnu
4-
// needs-llvm-components: aarch64
1+
//@ assembly-output: emit-asm
2+
//@ compile-flags: -O
3+
//@ compile-flags: --target aarch64-unknown-linux-gnu
4+
//@ needs-llvm-components: aarch64
55

66
#![feature(no_core, lang_items, rustc_attrs)]
77
#![crate_type = "rlib"]

tests/assembly/asm/aarch64-outline-atomics.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// assembly-output: emit-asm
2-
// compile-flags: -O
3-
// compile-flags: --target aarch64-unknown-linux-gnu
4-
// needs-llvm-components: aarch64
5-
// only-aarch64
6-
// only-linux
1+
//@ assembly-output: emit-asm
2+
//@ compile-flags: -O
3+
//@ compile-flags: --target aarch64-unknown-linux-gnu
4+
//@ needs-llvm-components: aarch64
5+
//@ only-aarch64
6+
//@ only-linux
77

88
#![crate_type = "rlib"]
99

tests/assembly/asm/aarch64-types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// assembly-output: emit-asm
2-
// compile-flags: --target aarch64-unknown-linux-gnu
3-
// needs-llvm-components: aarch64
1+
//@ assembly-output: emit-asm
2+
//@ compile-flags: --target aarch64-unknown-linux-gnu
3+
//@ needs-llvm-components: aarch64
44

55
#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
66
#![crate_type = "rlib"]

tests/assembly/asm/arm-modifiers.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// assembly-output: emit-asm
2-
// compile-flags: -O
3-
// compile-flags: --target armv7-unknown-linux-gnueabihf
4-
// compile-flags: -C target-feature=+neon
5-
// needs-llvm-components: arm
1+
//@ assembly-output: emit-asm
2+
//@ compile-flags: -O
3+
//@ compile-flags: --target armv7-unknown-linux-gnueabihf
4+
//@ compile-flags: -C target-feature=+neon
5+
//@ needs-llvm-components: arm
66

77
#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
88
#![crate_type = "rlib"]

tests/assembly/asm/arm-types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// assembly-output: emit-asm
2-
// compile-flags: --target armv7-unknown-linux-gnueabihf
3-
// compile-flags: -C target-feature=+neon
4-
// compile-flags: -C opt-level=0
5-
// needs-llvm-components: arm
1+
//@ assembly-output: emit-asm
2+
//@ compile-flags: --target armv7-unknown-linux-gnueabihf
3+
//@ compile-flags: -C target-feature=+neon
4+
//@ compile-flags: -C opt-level=0
5+
//@ needs-llvm-components: arm
66

77
#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
88
#![crate_type = "rlib"]

tests/assembly/asm/avr-modifiers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// assembly-output: emit-asm
2-
// compile-flags: --target avr-unknown-gnu-atmega328
3-
// needs-llvm-components: avr
1+
//@ assembly-output: emit-asm
2+
//@ compile-flags: --target avr-unknown-gnu-atmega328
3+
//@ needs-llvm-components: avr
44

55
#![feature(no_core, lang_items, rustc_attrs, asm_experimental_arch)]
66
#![crate_type = "rlib"]

0 commit comments

Comments
 (0)