diff options
| author | bors <bors@rust-lang.org> | 2021-04-17 15:29:34 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-04-17 15:29:34 +0000 |
| commit | 42bee5a404e5a3145f3ef974b97eefb01844c63d (patch) | |
| tree | 2502753113d6615944f9a02cf240217c87618e19 | |
| parent | cd9b30527e96969b7d6b5471e05ad5d4185e390f (diff) | |
| parent | 4cfc7b3f73a1a813098f35d992ad94727d2a206b (diff) | |
| download | rust-42bee5a404e5a3145f3ef974b97eefb01844c63d.tar.gz rust-42bee5a404e5a3145f3ef974b97eefb01844c63d.zip | |
Auto merge of #84261 - Aaron1011:error-dup-revisions, r=Mark-Simulacrum
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.
| -rw-r--r-- | src/tools/compiletest/src/header.rs | 21 | ||||
| -rw-r--r-- | 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 363105a9f09..f31a24738df 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<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> { diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index c41b43cdd0b..ca7458d255c 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"); +} |
