From 844600eb03b5f7a1f82d940faabd886ec8984fe2 Mon Sep 17 00:00:00 2001 From: Shashi Sugrim <34145834+ShashiSugrim@users.noreply.github.com> Date: Sun, 18 Aug 2024 16:51:14 -0400 Subject: [PATCH] Fix issue ' cargo t --doc does not respect --color when a compilation error occurs #14403 ' --- src/cargo/ops/cargo_test.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 86e830e76f05..0056928ad9e4 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -1,5 +1,6 @@ use crate::core::compiler::{Compilation, CompileKind, Doctest, Metadata, Unit, UnitOutput}; use crate::core::profiles::PanicStrategy; +use crate::core::shell::ColorChoice; use crate::core::shell::Verbosity; use crate::core::{TargetKind, Workspace}; use crate::ops; @@ -176,6 +177,7 @@ fn run_doc_tests( let gctx = ws.gctx(); let mut errors = Vec::new(); let doctest_xcompile = gctx.cli_unstable().doctest_xcompile; + let color = gctx.shell().color_choice(); for doctest_info in &compilation.to_doc_test { let Doctest { @@ -212,6 +214,13 @@ fn run_doc_tests( gctx.shell().status("Doc-tests", unit.target.name())?; let mut p = compilation.rustdoc_process(unit, *script_meta)?; + let color_arg = match color { + ColorChoice::Always => "always", + ColorChoice::Never => "never", + ColorChoice::CargoAuto => "auto", + }; + p.arg("--color").arg(color_arg); + for (var, value) in env { p.env(var, value); }