deny usage of FileCheck prefixes as revision names

This commit is contained in:
Davis Muro 2024-12-30 08:18:22 -08:00
parent c1566141b6
commit 891041fbc9
No known key found for this signature in database
GPG key ID: E733EF073829DCA1
2 changed files with 25 additions and 0 deletions

View file

@ -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());
@ -948,6 +951,13 @@ impl Config {
raw,
testfile.display()
);
} else if FORBIDDEN_REVISION_NAMES.contains(&revision.as_str()) {
panic!(
"invalid revision: `{}` in line `{}`: {}",
revision,
raw,
testfile.display()
);
}
existing.push(revision);
}

View file

@ -553,6 +553,21 @@ fn test_duplicate_revisions() {
parse_rs(&config, "//@ revisions: rpass1 rpass1");
}
#[test]
fn test_forbidden_revisions() {
let config: Config = cfg().build();
let revisions = ["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"];
for rev in revisions {
let res = std::panic::catch_unwind(|| {
parse_rs(&config, format!("//@ revisions: {rev}").as_str());
});
assert!(res.is_err());
if let Some(msg) = res.unwrap_err().downcast_ref::<String>() {
assert!(msg.contains(format!("invalid revision: `{rev}` in line ` {rev}`").as_str()))
}
}
}
#[test]
fn ignore_arch() {
let archs = [