From f8a6978326cf519c7ae50c4fc164ce47f619439b Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 15 Dec 2024 06:58:18 +0000 Subject: [PATCH] compiletest: Deduplicate `--check-prefix` flags Currently having a revision named like `MSVC` causes errors because it gets passed via `--check-prefix` twice; once from the revision name and once from the default `msvc_or_not` value that compiletest sets. Fix this by deduplicating revision names before passing the arguments. --- src/tools/compiletest/src/runtest.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 8af4325e7b106..281715b62da42 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1,5 +1,5 @@ use std::borrow::Cow; -use std::collections::{HashMap, HashSet}; +use std::collections::{BTreeSet, HashMap, HashSet}; use std::ffi::{OsStr, OsString}; use std::fs::{self, File, create_dir_all}; use std::hash::{DefaultHasher, Hash, Hasher}; @@ -1962,16 +1962,18 @@ impl<'test> TestCx<'test> { // via `filecheck-flags` or by adding new header directives. // Because we use custom prefixes, we also have to register the default prefix. - filecheck.arg("--check-prefix=CHECK"); + // Deduplicate these in a set so revisions like `CHECK`, `MSVC`, and `NONMSVC` don't + // cause errors. + let mut check_prefixes = BTreeSet::from(["CHECK"]); // Some tests use the current revision name as a check prefix. if let Some(rev) = self.revision { - filecheck.arg("--check-prefix").arg(rev); + check_prefixes.insert(rev); } // Some tests also expect either the MSVC or NONMSVC prefix to be defined. let msvc_or_not = if self.config.target.contains("msvc") { "MSVC" } else { "NONMSVC" }; - filecheck.arg("--check-prefix").arg(msvc_or_not); + check_prefixes.insert(msvc_or_not); // The filecheck tool normally fails if a prefix is defined but not used. // However, we define several prefixes globally for all tests. @@ -1983,6 +1985,11 @@ impl<'test> TestCx<'test> { // Add custom flags supplied by the `filecheck-flags:` test header. filecheck.args(&self.props.filecheck_flags); + for prefix in check_prefixes { + // Set the expected prefixes + filecheck.arg("--check-prefix").arg(prefix); + } + self.compose_and_run(filecheck, "", None, None) }