Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate compiletest to use ui_test-style //@ directives #121370

Merged
merged 8 commits into from
Feb 22, 2024
  •  
  •  
  •  
73 changes: 59 additions & 14 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,14 +673,17 @@ pub fn line_directive<'line>(
/// names. This is **not** an exhaustive list of all possible directives. Instead, this is a
/// best-effort approximation for diagnostics.
Comment on lines 673 to 674
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it still the case that this is not an exhaustive list? If not can you remove the respective part of this comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's as exhaustive as the currently used directives go. It is still possible that some combination e.g. ignore-platform-xxx has never been used else where in the test suite.

const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
"assembly-output",
"aux-build",
"aux-crate",
"build-aux-docs",
"build-fail",
"build-pass",
"check-fail",
"check-pass",
"check-run-results",
"check-stdout",
"check-test-line-numbers-match",
"compile-flags",
"dont-check-compiler-stderr",
"dont-check-compiler-stdout",
Expand All @@ -691,12 +694,16 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
"failure-status",
"forbid-output",
"force-host",
"ignore-16bit",
"ignore-32bit",
"ignore-64bit",
"ignore-aarch64",
"ignore-aarch64-unknown-linux-gnu",
"ignore-android",
"ignore-arm",
"ignore-avr",
"ignore-beta",
"ignore-cdb",
"ignore-compare-mode-next-solver",
"ignore-compare-mode-polonius",
"ignore-cross-compile",
Expand All @@ -705,13 +712,21 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
"ignore-endian-big",
"ignore-freebsd",
"ignore-fuchsia",
"ignore-gdb",
"ignore-gdb-version",
"ignore-gnu",
"ignore-haiku",
"ignore-horizon",
"ignore-i686-pc-windows-msvc",
"ignore-ios",
"ignore-linux",
"ignore-lldb",
"ignore-llvm-version",
"ignore-loongarch64",
"ignore-macos",
"ignore-mode-coverage-map",
"ignore-mode-coverage-run",
"ignore-msp430",
"ignore-msvc",
"ignore-musl",
"ignore-netbsd",
Expand All @@ -720,8 +735,13 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
"ignore-nvptx64",
"ignore-openbsd",
"ignore-pass",
"ignore-remote",
"ignore-riscv64",
"ignore-s390x",
"ignore-sgx",
"ignore-spirv",
"ignore-stable",
"ignore-stage1",
"ignore-test",
"ignore-thumbv8m.base-none-eabi",
"ignore-thumbv8m.main-none-eabi",
Expand All @@ -731,9 +751,15 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
"ignore-wasm32",
"ignore-wasm32-bare",
"ignore-windows",
"ignore-windows-gnu",
"ignore-x86",
"ignore-x86_64-apple-darwin",
"incremental",
"known-bug",
"llvm-cov-flags",
"min-cdb-version",
"min-gdb-version",
"min-lldb-version",
"min-llvm-version",
"needs-asm-support",
"needs-dlltool",
Expand All @@ -742,11 +768,15 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
"needs-profiler-support",
"needs-relocation-model-pic",
"needs-run-enabled",
"needs-rust-lldb",
"needs-sanitizer-address",
"needs-sanitizer-cfi",
"needs-sanitizer-hwaddress",
"needs-sanitizer-leak",
"needs-sanitizer-memory",
"needs-sanitizer-memtag",
"needs-sanitizer-safestack",
"needs-sanitizer-shadow-call-stack",
"needs-sanitizer-support",
"needs-sanitizer-thread",
"needs-unwind",
Expand All @@ -756,23 +786,42 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
"normalize-stderr-64bit",
"normalize-stderr-test",
"normalize-stdout-test",
"only-16bit",
"only-32bit",
"only-64bit",
"only-aarch64",
"only-arm",
"only-avr",
"only-bpf",
"only-cdb",
"only-gnu",
"only-i686-pc-windows-msvc",
"only-linux",
"only-loongarch64",
"only-loongarch64-unknown-linux-gnu",
"only-macos",
"only-mips",
"only-mips64",
"only-msp430",
"only-msvc",
"only-nightly",
"only-nvptx64",
"only-riscv64",
"only-sparc",
"only-sparc64",
"only-thumb",
"only-wasm32",
"only-wasm32-bare",
"only-windows",
"only-x86",
"only-x86_64",
"only-x86_64-fortanix-unknown-sgx",
"only-x86_64-pc-windows-msvc",
"only-x86_64-unknown-linux-gnu",
"pp-exact",
"pretty-compare-only",
"pretty-expanded",
"pretty-mode",
"regex-error-pattern",
"remap-src-base",
"revisions",
Expand All @@ -783,7 +832,10 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
"rustc-env",
"rustfix-only-machine-applicable",
"should-fail",
"should-ice",
"stderr-per-bitwidth",
"unit-test",
"unset-exec-env",
"unset-rustc-env",
];

Expand Down Expand Up @@ -817,7 +869,7 @@ struct HeaderLine<'ln> {

fn iter_header(
mode: Mode,
suite: &str,
_suite: &str,
poisoned: &mut bool,
testfile: &Path,
rdr: impl Read,
Expand Down Expand Up @@ -848,11 +900,7 @@ fn iter_header(
}
}

let comment = if testfile.extension().is_some_and(|e| e == "rs") {
if mode == Mode::Ui && suite == "ui" { "//@" } else { "//" }
} else {
"#"
};
let comment = if testfile.extension().is_some_and(|e| e == "rs") { "//@" } else { "#" };

let mut rdr = BufReader::with_capacity(1024, rdr);
let mut ln = String::new();
Expand All @@ -879,7 +927,7 @@ fn iter_header(
// First try to accept `ui_test` style comments
} else if let Some((header_revision, directive)) = line_directive(comment, ln) {
it(HeaderLine { line_number, original_line, header_revision, directive });
} else if mode == Mode::Ui && suite == "ui" && !REVISION_MAGIC_COMMENT_RE.is_match(ln) {
} else if !REVISION_MAGIC_COMMENT_RE.is_match(ln) {
let Some((_, rest)) = line_directive("//", ln) else {
continue;
};
Expand All @@ -899,7 +947,7 @@ fn iter_header(
// directive. We emit an error here to warn the user.
*poisoned = true;
eprintln!(
"error: detected legacy-style directives in ui test: {}:{}, please use `ui_test`-style directives `//@` instead:{:#?}",
"error: detected legacy-style directives in compiletest test: {}:{}, please use `ui_test`-style directives `//@` instead:{:#?}",
testfile.display(),
line_number,
line_directive("//", ln),
Expand All @@ -912,7 +960,7 @@ fn iter_header(
// directive. We emit an error here to warn the user.
*poisoned = true;
eprintln!(
"error: detected legacy-style directives in ui test: {}:{}, please use `ui_test`-style directives `//@` instead:{:#?}",
"error: detected legacy-style directives in compiletest test: {}:{}, please use `ui_test`-style directives `//@` instead:{:#?}",
testfile.display(),
line_number,
line_directive("//", ln),
Expand Down Expand Up @@ -1213,11 +1261,8 @@ pub fn make_test_description<R: Read>(

if let Some((_, post)) = original_line.trim_start().split_once("//") {
let post = post.trim_start();
if post.starts_with("ignore-tidy")
&& config.mode == Mode::Ui
&& config.suite == "ui"
{
// not handled by compiletest under the ui test mode and ui test suite.
if post.starts_with("ignore-tidy") {
// Not handled by compiletest.
} else {
decision!(cfg::handle_ignore(config, ln));
}
Expand Down
9 changes: 2 additions & 7 deletions src/tools/compiletest/src/header/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,7 @@ fn ignore_mode() {
assert_eq!(config.mode, Mode::from_str(mode).unwrap());
assert_ne!(config.mode, Mode::from_str(other).unwrap());

if mode == "ui" {
assert!(check_ignore(&config, &format!("//@ ignore-mode-{mode}")));
assert!(!check_ignore(&config, &format!("//@ ignore-mode-{other}")));
} else {
assert!(check_ignore(&config, &format!("// ignore-mode-{mode}")));
assert!(!check_ignore(&config, &format!("// ignore-mode-{other}")));
}
assert!(check_ignore(&config, &format!("//@ ignore-mode-{mode}")));
assert!(!check_ignore(&config, &format!("//@ ignore-mode-{other}")));
}
}
13 changes: 4 additions & 9 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3938,15 +3938,10 @@ impl<'test> TestCx<'test> {
self.props.compare_output_lines_by_subset,
);
} else if !expected_fixed.is_empty() {
if self.config.suite == "ui" {
panic!(
"the `//@ run-rustfix` directive wasn't found but a `*.fixed` file was found"
);
} else {
panic!(
"the `// run-rustfix` directive wasn't found but a `*.fixed` file was found"
);
}
panic!(
"the `//@ run-rustfix` directive wasn't found but a `*.fixed` \
file was found"
);
}

if errors > 0 {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/tidy/src/target_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{collections::HashSet, path::Path};

const TARGET_DEFINITIONS_PATH: &str = "compiler/rustc_target/src/spec/targets/";
const ASSEMBLY_TEST_PATH: &str = "tests/assembly/targets/";
const REVISION_LINE_START: &str = "// revisions: ";
const REVISION_LINE_START: &str = "//@ revisions: ";
const EXCEPTIONS: &[&str] = &[
// FIXME: disabled since it fails on CI saying the csky component is missing
"csky_unknown_linux_gnuabiv2",
Expand Down
2 changes: 1 addition & 1 deletion src/tools/tidy/src/target_specific_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::path::Path;

use crate::walk::filter_not_rust;

const COMMENT: &str = "//";
const COMMENT: &str = "//@";
const LLVM_COMPONENTS_HEADER: &str = "needs-llvm-components:";
const COMPILE_FLAGS_HEADER: &str = "compile-flags:";

Expand Down
8 changes: 4 additions & 4 deletions tests/assembly/aarch64-naked-fn-no-bti-prolog.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// compile-flags: -C no-prepopulate-passes -Zbranch-protection=bti
// assembly-output: emit-asm
// needs-asm-support
// only-aarch64
//@ compile-flags: -C no-prepopulate-passes -Zbranch-protection=bti
//@ assembly-output: emit-asm
//@ needs-asm-support
//@ only-aarch64

#![crate_type = "lib"]
#![feature(naked_functions)]
Expand Down
8 changes: 4 additions & 4 deletions tests/assembly/aarch64-pointer-auth.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Test that PAC instructions are emitted when branch-protection is specified.

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

#![feature(no_core, lang_items)]
#![no_std]
Expand Down
6 changes: 3 additions & 3 deletions tests/assembly/align_offset.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// assembly-output: emit-asm
// compile-flags: -Copt-level=1
// only-x86_64
//@ assembly-output: emit-asm
//@ compile-flags: -Copt-level=1
//@ only-x86_64
#![crate_type="rlib"]

// CHECK-LABEL: align_offset_byte_ptr
Expand Down
6 changes: 3 additions & 3 deletions tests/assembly/asm/aarch64-el2vmsa.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// assembly-output: emit-asm
// compile-flags: --target aarch64-unknown-linux-gnu
// needs-llvm-components: aarch64
//@ assembly-output: emit-asm
//@ compile-flags: --target aarch64-unknown-linux-gnu
//@ needs-llvm-components: aarch64

#![feature(no_core, lang_items, rustc_attrs)]
#![crate_type = "rlib"]
Expand Down
8 changes: 4 additions & 4 deletions tests/assembly/asm/aarch64-modifiers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// assembly-output: emit-asm
// compile-flags: -O
// compile-flags: --target aarch64-unknown-linux-gnu
// needs-llvm-components: aarch64
//@ assembly-output: emit-asm
//@ compile-flags: -O
//@ compile-flags: --target aarch64-unknown-linux-gnu
//@ needs-llvm-components: aarch64

#![feature(no_core, lang_items, rustc_attrs)]
#![crate_type = "rlib"]
Expand Down
12 changes: 6 additions & 6 deletions tests/assembly/asm/aarch64-outline-atomics.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// assembly-output: emit-asm
// compile-flags: -O
// compile-flags: --target aarch64-unknown-linux-gnu
// needs-llvm-components: aarch64
// only-aarch64
// only-linux
//@ assembly-output: emit-asm
//@ compile-flags: -O
//@ compile-flags: --target aarch64-unknown-linux-gnu
//@ needs-llvm-components: aarch64
//@ only-aarch64
//@ only-linux

#![crate_type = "rlib"]

Expand Down
6 changes: 3 additions & 3 deletions tests/assembly/asm/aarch64-types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// assembly-output: emit-asm
// compile-flags: --target aarch64-unknown-linux-gnu
// needs-llvm-components: aarch64
//@ assembly-output: emit-asm
//@ compile-flags: --target aarch64-unknown-linux-gnu
//@ needs-llvm-components: aarch64

#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![crate_type = "rlib"]
Expand Down
10 changes: 5 additions & 5 deletions tests/assembly/asm/arm-modifiers.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// assembly-output: emit-asm
// compile-flags: -O
// compile-flags: --target armv7-unknown-linux-gnueabihf
// compile-flags: -C target-feature=+neon
// needs-llvm-components: arm
//@ assembly-output: emit-asm
//@ compile-flags: -O
//@ compile-flags: --target armv7-unknown-linux-gnueabihf
//@ compile-flags: -C target-feature=+neon
//@ needs-llvm-components: arm

#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![crate_type = "rlib"]
Expand Down
10 changes: 5 additions & 5 deletions tests/assembly/asm/arm-types.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// assembly-output: emit-asm
// compile-flags: --target armv7-unknown-linux-gnueabihf
// compile-flags: -C target-feature=+neon
// compile-flags: -C opt-level=0
// needs-llvm-components: arm
//@ assembly-output: emit-asm
//@ compile-flags: --target armv7-unknown-linux-gnueabihf
//@ compile-flags: -C target-feature=+neon
//@ compile-flags: -C opt-level=0
//@ needs-llvm-components: arm

#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![crate_type = "rlib"]
Expand Down
6 changes: 3 additions & 3 deletions tests/assembly/asm/avr-modifiers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// assembly-output: emit-asm
// compile-flags: --target avr-unknown-gnu-atmega328
// needs-llvm-components: avr
//@ assembly-output: emit-asm
//@ compile-flags: --target avr-unknown-gnu-atmega328
//@ needs-llvm-components: avr

#![feature(no_core, lang_items, rustc_attrs, asm_experimental_arch)]
#![crate_type = "rlib"]
Expand Down
Loading
Loading