Skip to content

Commit f62f490

Browse files
committed
Auto merge of #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). <rust-lang/rustc-dev-guide#1895>.
2 parents 933a05b + cd25009 commit f62f490

File tree

1,837 files changed

+4882
-4845
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

+4882
-4845
lines changed

src/tools/compiletest/src/header.rs

+59-14
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,17 @@ pub fn line_directive<'line>(
673673
/// names. This is **not** an exhaustive list of all possible directives. Instead, this is a
674674
/// best-effort approximation for diagnostics.
675675
const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
676+
"assembly-output",
676677
"aux-build",
677678
"aux-crate",
679+
"build-aux-docs",
678680
"build-fail",
679681
"build-pass",
680682
"check-fail",
681683
"check-pass",
682684
"check-run-results",
683685
"check-stdout",
686+
"check-test-line-numbers-match",
684687
"compile-flags",
685688
"dont-check-compiler-stderr",
686689
"dont-check-compiler-stdout",
@@ -691,12 +694,16 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
691694
"failure-status",
692695
"forbid-output",
693696
"force-host",
697+
"ignore-16bit",
694698
"ignore-32bit",
695699
"ignore-64bit",
696700
"ignore-aarch64",
697701
"ignore-aarch64-unknown-linux-gnu",
698702
"ignore-android",
699703
"ignore-arm",
704+
"ignore-avr",
705+
"ignore-beta",
706+
"ignore-cdb",
700707
"ignore-compare-mode-next-solver",
701708
"ignore-compare-mode-polonius",
702709
"ignore-cross-compile",
@@ -705,13 +712,21 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
705712
"ignore-endian-big",
706713
"ignore-freebsd",
707714
"ignore-fuchsia",
715+
"ignore-gdb",
716+
"ignore-gdb-version",
708717
"ignore-gnu",
709718
"ignore-haiku",
710719
"ignore-horizon",
711720
"ignore-i686-pc-windows-msvc",
712721
"ignore-ios",
722+
"ignore-linux",
723+
"ignore-lldb",
713724
"ignore-llvm-version",
725+
"ignore-loongarch64",
714726
"ignore-macos",
727+
"ignore-mode-coverage-map",
728+
"ignore-mode-coverage-run",
729+
"ignore-msp430",
715730
"ignore-msvc",
716731
"ignore-musl",
717732
"ignore-netbsd",
@@ -720,8 +735,13 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
720735
"ignore-nvptx64",
721736
"ignore-openbsd",
722737
"ignore-pass",
738+
"ignore-remote",
739+
"ignore-riscv64",
740+
"ignore-s390x",
723741
"ignore-sgx",
724742
"ignore-spirv",
743+
"ignore-stable",
744+
"ignore-stage1",
725745
"ignore-test",
726746
"ignore-thumbv8m.base-none-eabi",
727747
"ignore-thumbv8m.main-none-eabi",
@@ -731,9 +751,15 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
731751
"ignore-wasm32",
732752
"ignore-wasm32-bare",
733753
"ignore-windows",
754+
"ignore-windows-gnu",
734755
"ignore-x86",
756+
"ignore-x86_64-apple-darwin",
735757
"incremental",
736758
"known-bug",
759+
"llvm-cov-flags",
760+
"min-cdb-version",
761+
"min-gdb-version",
762+
"min-lldb-version",
737763
"min-llvm-version",
738764
"needs-asm-support",
739765
"needs-dlltool",
@@ -742,11 +768,15 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
742768
"needs-profiler-support",
743769
"needs-relocation-model-pic",
744770
"needs-run-enabled",
771+
"needs-rust-lldb",
745772
"needs-sanitizer-address",
746773
"needs-sanitizer-cfi",
747774
"needs-sanitizer-hwaddress",
748775
"needs-sanitizer-leak",
749776
"needs-sanitizer-memory",
777+
"needs-sanitizer-memtag",
778+
"needs-sanitizer-safestack",
779+
"needs-sanitizer-shadow-call-stack",
750780
"needs-sanitizer-support",
751781
"needs-sanitizer-thread",
752782
"needs-unwind",
@@ -756,23 +786,42 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
756786
"normalize-stderr-64bit",
757787
"normalize-stderr-test",
758788
"normalize-stdout-test",
789+
"only-16bit",
759790
"only-32bit",
760791
"only-64bit",
761792
"only-aarch64",
793+
"only-arm",
794+
"only-avr",
795+
"only-bpf",
796+
"only-cdb",
762797
"only-gnu",
763798
"only-i686-pc-windows-msvc",
764799
"only-linux",
800+
"only-loongarch64",
801+
"only-loongarch64-unknown-linux-gnu",
765802
"only-macos",
803+
"only-mips",
804+
"only-mips64",
805+
"only-msp430",
766806
"only-msvc",
767807
"only-nightly",
808+
"only-nvptx64",
809+
"only-riscv64",
810+
"only-sparc",
811+
"only-sparc64",
812+
"only-thumb",
768813
"only-wasm32",
814+
"only-wasm32-bare",
769815
"only-windows",
770816
"only-x86",
771817
"only-x86_64",
818+
"only-x86_64-fortanix-unknown-sgx",
772819
"only-x86_64-pc-windows-msvc",
773820
"only-x86_64-unknown-linux-gnu",
774821
"pp-exact",
822+
"pretty-compare-only",
775823
"pretty-expanded",
824+
"pretty-mode",
776825
"regex-error-pattern",
777826
"remap-src-base",
778827
"revisions",
@@ -783,7 +832,10 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
783832
"rustc-env",
784833
"rustfix-only-machine-applicable",
785834
"should-fail",
835+
"should-ice",
786836
"stderr-per-bitwidth",
837+
"unit-test",
838+
"unset-exec-env",
787839
"unset-rustc-env",
788840
];
789841

@@ -817,7 +869,7 @@ struct HeaderLine<'ln> {
817869

818870
fn iter_header(
819871
mode: Mode,
820-
suite: &str,
872+
_suite: &str,
821873
poisoned: &mut bool,
822874
testfile: &Path,
823875
rdr: impl Read,
@@ -848,11 +900,7 @@ fn iter_header(
848900
}
849901
}
850902

851-
let comment = if testfile.extension().is_some_and(|e| e == "rs") {
852-
if mode == Mode::Ui && suite == "ui" { "//@" } else { "//" }
853-
} else {
854-
"#"
855-
};
903+
let comment = if testfile.extension().is_some_and(|e| e == "rs") { "//@" } else { "#" };
856904

857905
let mut rdr = BufReader::with_capacity(1024, rdr);
858906
let mut ln = String::new();
@@ -879,7 +927,7 @@ fn iter_header(
879927
// First try to accept `ui_test` style comments
880928
} else if let Some((header_revision, directive)) = line_directive(comment, ln) {
881929
it(HeaderLine { line_number, original_line, header_revision, directive });
882-
} else if mode == Mode::Ui && suite == "ui" && !REVISION_MAGIC_COMMENT_RE.is_match(ln) {
930+
} else if !REVISION_MAGIC_COMMENT_RE.is_match(ln) {
883931
let Some((_, rest)) = line_directive("//", ln) else {
884932
continue;
885933
};
@@ -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),
@@ -912,7 +960,7 @@ fn iter_header(
912960
// directive. We emit an error here to warn the user.
913961
*poisoned = true;
914962
eprintln!(
915-
"error: detected legacy-style directives in ui test: {}:{}, please use `ui_test`-style directives `//@` instead:{:#?}",
963+
"error: detected legacy-style directives in compiletest test: {}:{}, please use `ui_test`-style directives `//@` instead:{:#?}",
916964
testfile.display(),
917965
line_number,
918966
line_directive("//", ln),
@@ -1213,11 +1261,8 @@ pub fn make_test_description<R: Read>(
12131261

12141262
if let Some((_, post)) = original_line.trim_start().split_once("//") {
12151263
let post = post.trim_start();
1216-
if post.starts_with("ignore-tidy")
1217-
&& config.mode == Mode::Ui
1218-
&& config.suite == "ui"
1219-
{
1220-
// not handled by compiletest under the ui test mode and ui test suite.
1264+
if post.starts_with("ignore-tidy") {
1265+
// Not handled by compiletest.
12211266
} else {
12221267
decision!(cfg::handle_ignore(config, ln));
12231268
}

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -578,12 +578,7 @@ fn ignore_mode() {
578578
assert_eq!(config.mode, Mode::from_str(mode).unwrap());
579579
assert_ne!(config.mode, Mode::from_str(other).unwrap());
580580

581-
if mode == "ui" {
582-
assert!(check_ignore(&config, &format!("//@ ignore-mode-{mode}")));
583-
assert!(!check_ignore(&config, &format!("//@ ignore-mode-{other}")));
584-
} else {
585-
assert!(check_ignore(&config, &format!("// ignore-mode-{mode}")));
586-
assert!(!check_ignore(&config, &format!("// ignore-mode-{other}")));
587-
}
581+
assert!(check_ignore(&config, &format!("//@ ignore-mode-{mode}")));
582+
assert!(!check_ignore(&config, &format!("//@ ignore-mode-{other}")));
588583
}
589584
}

src/tools/compiletest/src/runtest.rs

+4-9
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

+1-1
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

+1-1
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

+4-4
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

+4-4
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

+3-3
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

+3-3
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

+4-4
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

+6-6
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

+3-3
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

+5-5
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

+5-5
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

+3-3
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)