Skip to content

Commit

Permalink
Allow coverage tests to enable llvm-cov --use-color
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Jan 3, 2024
1 parent c38aeb0 commit 58a15e7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ pub struct TestProps {
// Whether to tell `rustc` to remap the "src base" directory to a fake
// directory.
pub remap_src_base: bool,
// If true, tells the `llvm-cov` tool to produce colored output.
// Only used by the "coverage-run" test mode.
pub llvm_cov_use_color: bool,
}

mod directives {
Expand Down Expand Up @@ -216,6 +219,7 @@ mod directives {
pub const MIR_UNIT_TEST: &'static str = "unit-test";
pub const REMAP_SRC_BASE: &'static str = "remap-src-base";
pub const COMPARE_OUTPUT_LINES_BY_SUBSET: &'static str = "compare-output-lines-by-subset";
pub const LLVM_COV_USE_COLOR: &'static str = "llvm-cov-use-color";
// This isn't a real directive, just one that is probably mistyped often
pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
}
Expand Down Expand Up @@ -265,6 +269,7 @@ impl TestProps {
stderr_per_bitwidth: false,
mir_unit_test: None,
remap_src_base: false,
llvm_cov_use_color: false,
}
}

Expand Down Expand Up @@ -488,6 +493,8 @@ impl TestProps {
COMPARE_OUTPUT_LINES_BY_SUBSET,
&mut self.compare_output_lines_by_subset,
);

config.set_name_directive(ln, LLVM_COV_USE_COLOR, &mut self.llvm_cov_use_color);
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,10 @@ impl<'test> TestCx<'test> {
let proc_res = self.run_llvm_tool("llvm-cov", |cmd| {
cmd.args(["show", "--format=text", "--show-line-counts-or-regions"]);

if self.props.llvm_cov_use_color {
cmd.arg("--use-color=1");
}

cmd.arg("--Xdemangler");
cmd.arg(self.config.rust_demangler_path.as_ref().unwrap());

Expand Down
13 changes: 13 additions & 0 deletions tests/coverage/color.coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
LL| |// edition: 2021
LL| |// ignore-mode-coverage-map
LL| |// ignore-windows
LL| |// llvm-cov-use-color
LL| |
LL| |// Verify that telling `llvm-cov` to use colored output actually works.
LL| |// Ignored on Windows because we can't tell the tool to use ANSI escapes.
LL| |
LL| 1|fn main() {
LL| 1| for _i in 0..0 {}
^0 ^0
LL| 1|}

11 changes: 11 additions & 0 deletions tests/coverage/color.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// edition: 2021
// ignore-mode-coverage-map
// ignore-windows
// llvm-cov-use-color

// Verify that telling `llvm-cov` to use colored output actually works.
// Ignored on Windows because we can't tell the tool to use ANSI escapes.

fn main() {
for _i in 0..0 {}
}

0 comments on commit 58a15e7

Please sign in to comment.