about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2023-12-16 13:30:47 +1100
committerZalathar <Zalathar@users.noreply.github.com>2024-01-05 13:42:54 +1100
commit731ba80a6b53e3397eadeda37b18bd8fb3016aad (patch)
tree994a1cbd24e62a938d19d42f3b91056f6426adbf
parent9ab8c632ee2ede9a350104278864154d933ed1db (diff)
downloadrust-731ba80a6b53e3397eadeda37b18bd8fb3016aad.tar.gz
rust-731ba80a6b53e3397eadeda37b18bd8fb3016aad.zip
Allow coverage tests to enable `llvm-cov --use-color`
-rw-r--r--src/tools/compiletest/src/header.rs9
-rw-r--r--src/tools/compiletest/src/runtest.rs2
-rw-r--r--tests/coverage/color.coverage13
-rw-r--r--tests/coverage/color.rs11
4 files changed, 35 insertions, 0 deletions
diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs
index a9f022664cf..e70e01e8757 100644
--- a/src/tools/compiletest/src/header.rs
+++ b/src/tools/compiletest/src/header.rs
@@ -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,
+    /// Extra flags to pass to `llvm-cov` when producing coverage reports.
+    /// Only used by the "coverage-run" test mode.
+    pub llvm_cov_flags: Vec<String>,
 }
 
 mod directives {
@@ -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_FLAGS: &'static str = "llvm-cov-flags";
     // This isn't a real directive, just one that is probably mistyped often
     pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
 }
@@ -265,6 +269,7 @@ impl TestProps {
             stderr_per_bitwidth: false,
             mir_unit_test: None,
             remap_src_base: false,
+            llvm_cov_flags: vec![],
         }
     }
 
@@ -495,6 +500,10 @@ impl TestProps {
                     COMPARE_OUTPUT_LINES_BY_SUBSET,
                     &mut self.compare_output_lines_by_subset,
                 );
+
+                if let Some(flags) = config.parse_name_value_directive(ln, LLVM_COV_FLAGS) {
+                    self.llvm_cov_flags.extend(split_flags(&flags));
+                }
             });
         }
 
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index 1f5f77839de..b258b748ca8 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -575,6 +575,8 @@ impl<'test> TestCx<'test> {
                 cmd.arg("--object");
                 cmd.arg(bin);
             }
+
+            cmd.args(&self.props.llvm_cov_flags);
         });
         if !proc_res.status.success() {
             self.fatal_proc_rec("llvm-cov show failed!", &proc_res);
diff --git a/tests/coverage/color.coverage b/tests/coverage/color.coverage
new file mode 100644
index 00000000000..bc49fff9cb7
--- /dev/null
+++ b/tests/coverage/color.coverage
@@ -0,0 +1,13 @@
+   LL|       |// edition: 2021
+   LL|       |// ignore-mode-coverage-map
+   LL|       |// ignore-windows
+   LL|       |// llvm-cov-flags: --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|}
+
diff --git a/tests/coverage/color.rs b/tests/coverage/color.rs
new file mode 100644
index 00000000000..bd727946c78
--- /dev/null
+++ b/tests/coverage/color.rs
@@ -0,0 +1,11 @@
+// edition: 2021
+// ignore-mode-coverage-map
+// ignore-windows
+// llvm-cov-flags: --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 {}
+}