Skip to content

compiletest: Deny usage of special FileCheck suffixes as revision names #134925

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,9 @@ fn iter_header(

impl Config {
fn parse_and_update_revisions(&self, testfile: &Path, line: &str, existing: &mut Vec<String>) {
const FORBIDDEN_REVISION_NAMES: [&str; 9] =
["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"];

if let Some(raw) = self.parse_name_value_directive(line, "revisions") {
if self.mode == Mode::RunMake {
panic!("`run-make` tests do not support revisions: {}", testfile.display());
Expand All @@ -948,6 +951,15 @@ impl Config {
raw,
testfile.display()
);
} else if matches!(self.mode, Mode::Assembly | Mode::Codegen | Mode::MirOpt)
&& FORBIDDEN_REVISION_NAMES.contains(&revision.as_str())
{
panic!(
"revision name `{revision}` is not permitted in a test suite that uses `FileCheck` annotations\n\
as it is confusing when used as custom `FileCheck` prefix: `{revision}` in line `{}`: {}",
raw,
testfile.display()
);
}
existing.push(revision);
}
Expand Down
53 changes: 53 additions & 0 deletions src/tools/compiletest/src/header/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,59 @@ fn test_duplicate_revisions() {
parse_rs(&config, "//@ revisions: rpass1 rpass1");
}

#[test]
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: just #[should_panic] here instead of trying to catch the panic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in the latest commit. I had to select a specific revision name for this CHECK, I'm not currently aware of a way to test all of them without manually catching the panic... Any tips on this will be greatly appreciated

Copy link
Member

@jieyouxu jieyouxu Jan 4, 2025

Choose a reason for hiding this comment

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

In the long run compiletest shouldn't be using randomly placed panics as an error handling strategy (really, the lack thereof), but in the short run this is reasonable.

I think it's a reasonable compromise for the time being.

#[should_panic(
expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations"
)]
fn test_assembly_mode_forbidden_revisions() {
let config = cfg().mode("assembly").build();
parse_rs(&config, "//@ revisions: CHECK");
}

#[test]
#[should_panic(
expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations"
)]
fn test_codegen_mode_forbidden_revisions() {
let config = cfg().mode("codegen").build();
parse_rs(&config, "//@ revisions: CHECK");
}

#[test]
#[should_panic(
expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations"
)]
fn test_miropt_mode_forbidden_revisions() {
let config = cfg().mode("mir-opt").build();
parse_rs(&config, "//@ revisions: CHECK");
}

#[test]
fn test_forbidden_revisions_allowed_in_non_filecheck_dir() {
let revisions = ["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"];
let modes = [
"pretty",
"debuginfo",
"rustdoc",
"rustdoc-json",
"codegen-units",
"incremental",
"ui",
"js-doc-test",
"coverage-map",
"coverage-run",
"crashes",
];

for rev in revisions {
let content = format!("//@ revisions: {rev}");
for mode in modes {
let config = cfg().mode(mode).build();
parse_rs(&config, &content);
}
}
}

#[test]
fn ignore_arch() {
let archs = [
Expand Down
Loading