Skip to content

Commit

Permalink
Auto merge of #84261 - Aaron1011:error-dup-revisions, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Error when compiletest is passed duplicate revisions

Currently, we allow the user to write things like
'// revisions: rpass1 rpass1', which will not test what they were
intending to test.
  • Loading branch information
bors committed Apr 17, 2021
2 parents cd9b305 + 4cfc7b3 commit 42bee5a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ impl EarlyProps {
props.aux_crate.push(ac);
}

if let Some(r) = config.parse_revisions(ln) {
props.revisions.extend(r);
}
config.parse_and_update_revisions(ln, &mut props.revisions);

props.should_fail = props.should_fail || config.parse_name_directive(ln, "should-fail");
});
Expand Down Expand Up @@ -432,9 +430,7 @@ impl TestProps {
self.compile_flags.push(format!("--edition={}", edition));
}

if let Some(r) = config.parse_revisions(ln) {
self.revisions.extend(r);
}
config.parse_and_update_revisions(ln, &mut self.revisions);

if self.run_flags.is_none() {
self.run_flags = config.parse_run_flags(ln);
Expand Down Expand Up @@ -723,9 +719,16 @@ impl Config {
self.parse_name_value_directive(line, "compile-flags")
}

fn parse_revisions(&self, line: &str) -> Option<Vec<String>> {
self.parse_name_value_directive(line, "revisions")
.map(|r| r.split_whitespace().map(|t| t.to_string()).collect())
fn parse_and_update_revisions(&self, line: &str, existing: &mut Vec<String>) {
if let Some(raw) = self.parse_name_value_directive(line, "revisions") {
let mut duplicates: HashSet<_> = existing.iter().cloned().collect();
for revision in raw.split_whitespace().map(|r| r.to_string()) {
if !duplicates.insert(revision.clone()) {
panic!("Duplicate revision: `{}` in line `{}`", revision, raw);
}
existing.push(revision);
}
}
}

fn parse_run_flags(&self, line: &str) -> Option<String> {
Expand Down
7 changes: 7 additions & 0 deletions src/tools/compiletest/src/header/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,10 @@ fn test_extract_version_range() {
assert_eq!(extract_version_range(" - 4.5.6", extract_llvm_version), None);
assert_eq!(extract_version_range("0 -", extract_llvm_version), None);
}

#[test]
#[should_panic(expected = "Duplicate revision: `rpass1` in line ` rpass1 rpass1`")]
fn test_duplicate_revisions() {
let config = config();
parse_rs(&config, "// revisions: rpass1 rpass1");
}

0 comments on commit 42bee5a

Please sign in to comment.