Skip to content

Commit 3342195

Browse files
committed
Allow coverage tests to enable llvm-cov --use-color
1 parent 677ed75 commit 3342195

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

src/tools/compiletest/src/header.rs

+9
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ pub struct TestProps {
178178
// Whether to tell `rustc` to remap the "src base" directory to a fake
179179
// directory.
180180
pub remap_src_base: bool,
181+
/// Extra flags to pass to `llvm-cov` when producing coverage reports.
182+
/// Only used by the "coverage-run" test mode.
183+
pub llvm_cov_flags: Vec<String>,
181184
}
182185

183186
mod directives {
@@ -216,6 +219,7 @@ mod directives {
216219
pub const MIR_UNIT_TEST: &'static str = "unit-test";
217220
pub const REMAP_SRC_BASE: &'static str = "remap-src-base";
218221
pub const COMPARE_OUTPUT_LINES_BY_SUBSET: &'static str = "compare-output-lines-by-subset";
222+
pub const LLVM_COV_FLAGS: &'static str = "llvm-cov-flags";
219223
// This isn't a real directive, just one that is probably mistyped often
220224
pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
221225
}
@@ -265,6 +269,7 @@ impl TestProps {
265269
stderr_per_bitwidth: false,
266270
mir_unit_test: None,
267271
remap_src_base: false,
272+
llvm_cov_flags: vec![],
268273
}
269274
}
270275

@@ -495,6 +500,10 @@ impl TestProps {
495500
COMPARE_OUTPUT_LINES_BY_SUBSET,
496501
&mut self.compare_output_lines_by_subset,
497502
);
503+
504+
if let Some(flags) = config.parse_name_value_directive(ln, LLVM_COV_FLAGS) {
505+
self.llvm_cov_flags.extend(split_flags(&flags));
506+
}
498507
});
499508
}
500509

src/tools/compiletest/src/runtest.rs

+2
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ impl<'test> TestCx<'test> {
575575
cmd.arg("--object");
576576
cmd.arg(bin);
577577
}
578+
579+
cmd.args(&self.props.llvm_cov_flags);
578580
});
579581
if !proc_res.status.success() {
580582
self.fatal_proc_rec("llvm-cov show failed!", &proc_res);

tests/coverage/color.coverage

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
LL| |// edition: 2021
2+
LL| |// ignore-mode-coverage-map
3+
LL| |// ignore-windows
4+
LL| |// llvm-cov-flags: --use-color
5+
LL| |
6+
LL| |// Verify that telling `llvm-cov` to use colored output actually works.
7+
LL| |// Ignored on Windows because we can't tell the tool to use ANSI escapes.
8+
LL| |
9+
LL| 1|fn main() {
10+
LL| 1| for _i in 0..0 {}
11+
^0 ^0
12+
LL| 1|}
13+

tests/coverage/color.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// edition: 2021
2+
// ignore-mode-coverage-map
3+
// ignore-windows
4+
// llvm-cov-flags: --use-color
5+
6+
// Verify that telling `llvm-cov` to use colored output actually works.
7+
// Ignored on Windows because we can't tell the tool to use ANSI escapes.
8+
9+
fn main() {
10+
for _i in 0..0 {}
11+
}

0 commit comments

Comments
 (0)