From 4cfc7b3f73a1a813098f35d992ad94727d2a206b Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Fri, 16 Apr 2021 17:05:59 -0400 Subject: [PATCH] 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. --- src/tools/compiletest/src/header.rs | 21 ++++++++++++--------- src/tools/compiletest/src/header/tests.rs | 7 +++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 363105a9f09c0..f31a24738df6c 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -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"); }); @@ -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); @@ -723,9 +719,16 @@ impl Config { self.parse_name_value_directive(line, "compile-flags") } - fn parse_revisions(&self, line: &str) -> Option> { - 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) { + 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 { diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index c41b43cdd0b53..ca7458d255c3c 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -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"); +}