Skip to content

Commit baec307

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 1e432dd commit baec307

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
@@ -197,6 +197,8 @@ pub struct TestProps {
197197
/// Extra flags to pass to `llvm-cov` when producing coverage reports.
198198
/// Only used by the "coverage-run" test mode.
199199
pub llvm_cov_flags: Vec<String>,
200+
/// Extra flags to pass to LLVM's `filecheck` tool, in tests that use it.
201+
pub filecheck_flags: Vec<String>,
200202
}
201203

202204
mod directives {
@@ -236,6 +238,7 @@ mod directives {
236238
pub const REMAP_SRC_BASE: &'static str = "remap-src-base";
237239
pub const COMPARE_OUTPUT_LINES_BY_SUBSET: &'static str = "compare-output-lines-by-subset";
238240
pub const LLVM_COV_FLAGS: &'static str = "llvm-cov-flags";
241+
pub const FILECHECK_FLAGS: &'static str = "filecheck-flags";
239242
// This isn't a real directive, just one that is probably mistyped often
240243
pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
241244
}
@@ -286,6 +289,7 @@ impl TestProps {
286289
mir_unit_test: None,
287290
remap_src_base: false,
288291
llvm_cov_flags: vec![],
292+
filecheck_flags: vec![],
289293
}
290294
}
291295

@@ -542,6 +546,10 @@ impl TestProps {
542546
if let Some(flags) = config.parse_name_value_directive(ln, LLVM_COV_FLAGS) {
543547
self.llvm_cov_flags.extend(split_flags(&flags));
544548
}
549+
550+
if let Some(flags) = config.parse_name_value_directive(ln, FILECHECK_FLAGS) {
551+
self.filecheck_flags.extend(split_flags(&flags));
552+
}
545553
},
546554
);
547555

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)