Skip to content

Commit

Permalink
compiletest: Deduplicate --check-prefix flags
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tgross35 committed Dec 15, 2024
1 parent 0b63586 commit d5bc586
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
use std::collections::{BTreeSet, HashMap, HashSet};
use std::ffi::OsString;
use std::fs::{self, File, create_dir_all};
use std::hash::{DefaultHasher, Hash, Hasher};
Expand Down Expand Up @@ -1939,16 +1939,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.
Expand All @@ -1960,6 +1962,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)
}

Expand Down

0 comments on commit d5bc586

Please sign in to comment.