Allow tests to specify a //@ filecheck-flags: header

Any flags specified here will be passed to LLVM's `filecheck` tool, in tests
that use that tool.
This commit is contained in:
Zalathar 2024-02-03 11:15:05 +11:00
parent 1e432dd9f4
commit baec3076db
3 changed files with 22 additions and 5 deletions

View File

@ -197,6 +197,8 @@ pub struct TestProps {
/// Extra flags to pass to `llvm-cov` when producing coverage reports. /// Extra flags to pass to `llvm-cov` when producing coverage reports.
/// Only used by the "coverage-run" test mode. /// Only used by the "coverage-run" test mode.
pub llvm_cov_flags: Vec<String>, pub llvm_cov_flags: Vec<String>,
/// Extra flags to pass to LLVM's `filecheck` tool, in tests that use it.
pub filecheck_flags: Vec<String>,
} }
mod directives { mod directives {
@ -236,6 +238,7 @@ mod directives {
pub const REMAP_SRC_BASE: &'static str = "remap-src-base"; pub const REMAP_SRC_BASE: &'static str = "remap-src-base";
pub const COMPARE_OUTPUT_LINES_BY_SUBSET: &'static str = "compare-output-lines-by-subset"; pub const COMPARE_OUTPUT_LINES_BY_SUBSET: &'static str = "compare-output-lines-by-subset";
pub const LLVM_COV_FLAGS: &'static str = "llvm-cov-flags"; pub const LLVM_COV_FLAGS: &'static str = "llvm-cov-flags";
pub const FILECHECK_FLAGS: &'static str = "filecheck-flags";
// This isn't a real directive, just one that is probably mistyped often // This isn't a real directive, just one that is probably mistyped often
pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags"; pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
} }
@ -286,6 +289,7 @@ impl TestProps {
mir_unit_test: None, mir_unit_test: None,
remap_src_base: false, remap_src_base: false,
llvm_cov_flags: vec![], llvm_cov_flags: vec![],
filecheck_flags: vec![],
} }
} }
@ -542,6 +546,10 @@ impl TestProps {
if let Some(flags) = config.parse_name_value_directive(ln, LLVM_COV_FLAGS) { if let Some(flags) = config.parse_name_value_directive(ln, LLVM_COV_FLAGS) {
self.llvm_cov_flags.extend(split_flags(&flags)); self.llvm_cov_flags.extend(split_flags(&flags));
} }
if let Some(flags) = config.parse_name_value_directive(ln, FILECHECK_FLAGS) {
self.filecheck_flags.extend(split_flags(&flags));
}
}, },
); );

View File

@ -2907,11 +2907,8 @@ impl<'test> TestCx<'test> {
let mut filecheck = Command::new(self.config.llvm_filecheck.as_ref().unwrap()); let mut filecheck = Command::new(self.config.llvm_filecheck.as_ref().unwrap());
filecheck.arg("--input-file").arg(output).arg(&self.testpaths.file); filecheck.arg("--input-file").arg(output).arg(&self.testpaths.file);
// It would be more appropriate to make most of the arguments configurable through // FIXME: Consider making some of these prefix flags opt-in per test,
// a comment-attribute similar to `compile-flags`. For example, --check-prefixes is a very // via `filecheck-flags` or by adding new header directives.
// useful flag.
//
// For now, though…
// Because we use custom prefixes, we also have to register the default prefix. // Because we use custom prefixes, we also have to register the default prefix.
filecheck.arg("--check-prefix=CHECK"); filecheck.arg("--check-prefix=CHECK");
@ -2931,6 +2928,10 @@ impl<'test> TestCx<'test> {
// Provide more context on failures. // Provide more context on failures.
filecheck.args(&["--dump-input-context", "100"]); filecheck.args(&["--dump-input-context", "100"]);
// Add custom flags supplied by the `filecheck-flags:` test header.
filecheck.args(&self.props.filecheck_flags);
self.compose_and_run(filecheck, "", None, None) self.compose_and_run(filecheck, "", None, None)
} }

View File

@ -0,0 +1,8 @@
// Arguments provided via `filecheck-flags` should be passed to `filecheck`.
//@ revisions: good bad
//@ [good] filecheck-flags: --check-prefix=CUSTOM
//@ [bad] should-fail
// CUSTOM: main
fn main() {}