Skip to content

Commit 0712bed

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 a6c5a11 commit 0712bed

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

201203
mod directives {
@@ -235,6 +237,7 @@ mod directives {
235237
pub const REMAP_SRC_BASE: &'static str = "remap-src-base";
236238
pub const COMPARE_OUTPUT_LINES_BY_SUBSET: &'static str = "compare-output-lines-by-subset";
237239
pub const LLVM_COV_FLAGS: &'static str = "llvm-cov-flags";
240+
pub const FILECHECK_FLAGS: &'static str = "filecheck-flags";
238241
// This isn't a real directive, just one that is probably mistyped often
239242
pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
240243
}
@@ -285,6 +288,7 @@ impl TestProps {
285288
mir_unit_test: None,
286289
remap_src_base: false,
287290
llvm_cov_flags: vec![],
291+
filecheck_flags: vec![],
288292
}
289293
}
290294

@@ -541,6 +545,10 @@ impl TestProps {
541545
if let Some(flags) = config.parse_name_value_directive(ln, LLVM_COV_FLAGS) {
542546
self.llvm_cov_flags.extend(split_flags(&flags));
543547
}
548+
549+
if let Some(flags) = config.parse_name_value_directive(ln, FILECHECK_FLAGS) {
550+
self.filecheck_flags.extend(split_flags(&flags));
551+
}
544552
},
545553
);
546554

src/tools/compiletest/src/runtest.rs

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

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

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

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

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)