Skip to content

Commit b8c585b

Browse files
committed
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.
1 parent 4ceacca commit b8c585b

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/tools/compiletest/src/header.rs

+8
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ pub struct TestProps {
181181
/// Extra flags to pass to `llvm-cov` when producing coverage reports.
182182
/// Only used by the "coverage-run" test mode.
183183
pub llvm_cov_flags: Vec<String>,
184+
/// Extra flags to pass to LLVM's `filecheck` tool, in tests that use it.
185+
pub filecheck_flags: Vec<String>,
184186
}
185187

186188
mod directives {
@@ -220,6 +222,7 @@ mod directives {
220222
pub const REMAP_SRC_BASE: &'static str = "remap-src-base";
221223
pub const COMPARE_OUTPUT_LINES_BY_SUBSET: &'static str = "compare-output-lines-by-subset";
222224
pub const LLVM_COV_FLAGS: &'static str = "llvm-cov-flags";
225+
pub const FILECHECK_FLAGS: &'static str = "filecheck-flags";
223226
// This isn't a real directive, just one that is probably mistyped often
224227
pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
225228
}
@@ -270,6 +273,7 @@ impl TestProps {
270273
mir_unit_test: None,
271274
remap_src_base: false,
272275
llvm_cov_flags: vec![],
276+
filecheck_flags: vec![],
273277
}
274278
}
275279

@@ -504,6 +508,10 @@ impl TestProps {
504508
if let Some(flags) = config.parse_name_value_directive(ln, LLVM_COV_FLAGS) {
505509
self.llvm_cov_flags.extend(split_flags(&flags));
506510
}
511+
512+
if let Some(flags) = config.parse_name_value_directive(ln, FILECHECK_FLAGS) {
513+
self.filecheck_flags.extend(split_flags(&flags));
514+
}
507515
});
508516
}
509517

src/tools/compiletest/src/runtest.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -2907,11 +2907,8 @@ impl<'test> TestCx<'test> {
29072907
let mut filecheck = Command::new(self.config.llvm_filecheck.as_ref().unwrap());
29082908
filecheck.arg("--input-file").arg(output).arg(&self.testpaths.file);
29092909

2910-
// It would be more appropriate to make most of the arguments configurable through
2911-
// a comment-attribute similar to `compile-flags`. For example, --check-prefixes is a very
2912-
// useful flag.
2913-
//
2914-
// For now, though…
2910+
// FIXME: Consider making some of these prefix flags opt-in per test,
2911+
// via `filecheck-flags` or by adding new header directives.
29152912

29162913
// Because we use custom prefixes, we also have to register the default prefix.
29172914
filecheck.arg("--check-prefix=CHECK");
@@ -2931,6 +2928,10 @@ impl<'test> TestCx<'test> {
29312928

29322929
// Provide more context on failures.
29332930
filecheck.args(&["--dump-input-context", "100"]);
2931+
2932+
// Add custom flags supplied by the `filecheck-flags:` test header.
2933+
filecheck.args(&self.props.filecheck_flags);
2934+
29342935
self.compose_and_run(filecheck, "", None, None)
29352936
}
29362937

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Arguments provided via `filecheck-flags` should be passed to `filecheck`.
2+
3+
// revisions: good bad
4+
// [good] filecheck-flags: --check-prefix=CUSTOM
5+
// [bad] should-fail
6+
7+
// CUSTOM: main
8+
fn main() {}

0 commit comments

Comments
 (0)