Skip to content
/ rust Public
forked from rust-lang/rust

Commit 78e681a

Browse files
Rollup merge of rust-lang#134925 - DavisRayM:130982-deny-special-filecheck-prefixes, r=jieyouxu
deny usage of special FileCheck prefixes as revision names Adds a check that ensures special FileCheck prefixes are not used as revision names. Fix rust-lang#130982
2 parents 1891c28 + 4a5e76a commit 78e681a

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/tools/compiletest/src/header.rs

+12
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,9 @@ fn iter_header(
934934

935935
impl Config {
936936
fn parse_and_update_revisions(&self, testfile: &Path, line: &str, existing: &mut Vec<String>) {
937+
const FORBIDDEN_REVISION_NAMES: [&str; 9] =
938+
["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"];
939+
937940
if let Some(raw) = self.parse_name_value_directive(line, "revisions") {
938941
if self.mode == Mode::RunMake {
939942
panic!("`run-make` tests do not support revisions: {}", testfile.display());
@@ -948,6 +951,15 @@ impl Config {
948951
raw,
949952
testfile.display()
950953
);
954+
} else if matches!(self.mode, Mode::Assembly | Mode::Codegen | Mode::MirOpt)
955+
&& FORBIDDEN_REVISION_NAMES.contains(&revision.as_str())
956+
{
957+
panic!(
958+
"revision name `{revision}` is not permitted in a test suite that uses `FileCheck` annotations\n\
959+
as it is confusing when used as custom `FileCheck` prefix: `{revision}` in line `{}`: {}",
960+
raw,
961+
testfile.display()
962+
);
951963
}
952964
existing.push(revision);
953965
}

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

+53
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,59 @@ fn test_duplicate_revisions() {
553553
parse_rs(&config, "//@ revisions: rpass1 rpass1");
554554
}
555555

556+
#[test]
557+
#[should_panic(
558+
expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations"
559+
)]
560+
fn test_assembly_mode_forbidden_revisions() {
561+
let config = cfg().mode("assembly").build();
562+
parse_rs(&config, "//@ revisions: CHECK");
563+
}
564+
565+
#[test]
566+
#[should_panic(
567+
expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations"
568+
)]
569+
fn test_codegen_mode_forbidden_revisions() {
570+
let config = cfg().mode("codegen").build();
571+
parse_rs(&config, "//@ revisions: CHECK");
572+
}
573+
574+
#[test]
575+
#[should_panic(
576+
expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations"
577+
)]
578+
fn test_miropt_mode_forbidden_revisions() {
579+
let config = cfg().mode("mir-opt").build();
580+
parse_rs(&config, "//@ revisions: CHECK");
581+
}
582+
583+
#[test]
584+
fn test_forbidden_revisions_allowed_in_non_filecheck_dir() {
585+
let revisions = ["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"];
586+
let modes = [
587+
"pretty",
588+
"debuginfo",
589+
"rustdoc",
590+
"rustdoc-json",
591+
"codegen-units",
592+
"incremental",
593+
"ui",
594+
"js-doc-test",
595+
"coverage-map",
596+
"coverage-run",
597+
"crashes",
598+
];
599+
600+
for rev in revisions {
601+
let content = format!("//@ revisions: {rev}");
602+
for mode in modes {
603+
let config = cfg().mode(mode).build();
604+
parse_rs(&config, &content);
605+
}
606+
}
607+
}
608+
556609
#[test]
557610
fn ignore_arch() {
558611
let archs = [

0 commit comments

Comments
 (0)