Skip to content

Commit 58a15e7

Browse files
committed
Allow coverage tests to enable llvm-cov --use-color
1 parent c38aeb0 commit 58a15e7

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

src/tools/compiletest/src/header.rs

+7
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+
// If true, tells the `llvm-cov` tool to produce colored output.
182+
// Only used by the "coverage-run" test mode.
183+
pub llvm_cov_use_color: bool,
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_USE_COLOR: &'static str = "llvm-cov-use-color";
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_use_color: false,
268273
}
269274
}
270275

@@ -488,6 +493,8 @@ impl TestProps {
488493
COMPARE_OUTPUT_LINES_BY_SUBSET,
489494
&mut self.compare_output_lines_by_subset,
490495
);
496+
497+
config.set_name_directive(ln, LLVM_COV_USE_COLOR, &mut self.llvm_cov_use_color);
491498
});
492499
}
493500

src/tools/compiletest/src/runtest.rs

+4
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,10 @@ impl<'test> TestCx<'test> {
565565
let proc_res = self.run_llvm_tool("llvm-cov", |cmd| {
566566
cmd.args(["show", "--format=text", "--show-line-counts-or-regions"]);
567567

568+
if self.props.llvm_cov_use_color {
569+
cmd.arg("--use-color=1");
570+
}
571+
568572
cmd.arg("--Xdemangler");
569573
cmd.arg(self.config.rust_demangler_path.as_ref().unwrap());
570574

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-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-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)