Skip to content

Commit 4a5e76a

Browse files
committed
limit special FileCheck revision checks
1 parent 891041f commit 4a5e76a

File tree

2 files changed

+51
-11
lines changed

2 files changed

+51
-11
lines changed

src/tools/compiletest/src/header.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -951,10 +951,12 @@ impl Config {
951951
raw,
952952
testfile.display()
953953
);
954-
} else if FORBIDDEN_REVISION_NAMES.contains(&revision.as_str()) {
954+
} else if matches!(self.mode, Mode::Assembly | Mode::Codegen | Mode::MirOpt)
955+
&& FORBIDDEN_REVISION_NAMES.contains(&revision.as_str())
956+
{
955957
panic!(
956-
"invalid revision: `{}` in line `{}`: {}",
957-
revision,
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 `{}`: {}",
958960
raw,
959961
testfile.display()
960962
);

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

+46-8
Original file line numberDiff line numberDiff line change
@@ -554,16 +554,54 @@ fn test_duplicate_revisions() {
554554
}
555555

556556
#[test]
557-
fn test_forbidden_revisions() {
558-
let config: Config = cfg().build();
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() {
559585
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+
560600
for rev in revisions {
561-
let res = std::panic::catch_unwind(|| {
562-
parse_rs(&config, format!("//@ revisions: {rev}").as_str());
563-
});
564-
assert!(res.is_err());
565-
if let Some(msg) = res.unwrap_err().downcast_ref::<String>() {
566-
assert!(msg.contains(format!("invalid revision: `{rev}` in line ` {rev}`").as_str()))
601+
let content = format!("//@ revisions: {rev}");
602+
for mode in modes {
603+
let config = cfg().mode(mode).build();
604+
parse_rs(&config, &content);
567605
}
568606
}
569607
}

0 commit comments

Comments
 (0)