Skip to content

Commit 4657015

Browse files
committed
Fix issue ' cargo t --doc does not respect --color when a compilation error occurs #14403 '
1 parent 4494032 commit 4657015

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

src/cargo/ops/cargo_test.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::core::compiler::{Compilation, CompileKind, Doctest, Metadata, Unit, UnitOutput};
22
use crate::core::profiles::PanicStrategy;
3+
use crate::core::shell::ColorChoice;
34
use crate::core::shell::Verbosity;
45
use crate::core::{TargetKind, Workspace};
56
use crate::ops;
@@ -176,6 +177,7 @@ fn run_doc_tests(
176177
let gctx = ws.gctx();
177178
let mut errors = Vec::new();
178179
let doctest_xcompile = gctx.cli_unstable().doctest_xcompile;
180+
let color = gctx.shell().color_choice();
179181

180182
for doctest_info in &compilation.to_doc_test {
181183
let Doctest {
@@ -215,6 +217,14 @@ fn run_doc_tests(
215217
for (var, value) in env {
216218
p.env(var, value);
217219
}
220+
221+
let color_arg = match color {
222+
ColorChoice::Always => "always",
223+
ColorChoice::Never => "never",
224+
ColorChoice::CargoAuto => "auto",
225+
};
226+
p.arg("--color").arg(color_arg);
227+
218228
p.arg("--crate-name").arg(&unit.target.crate_name());
219229
p.arg("--test");
220230

tests/testsuite/build_script.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2871,7 +2871,7 @@ fn env_test() {
28712871
[RUNNING] `[ROOT]/foo/target/debug/deps/foo-[HASH][EXE]`
28722872
[RUNNING] `[ROOT]/foo/target/debug/deps/test-[HASH][EXE]`
28732873
[DOCTEST] foo
2874-
[RUNNING] `rustdoc --edition=2015 --crate-type lib --crate-name foo[..]`
2874+
[RUNNING] `rustdoc --edition=2015 --crate-type lib --color auto --crate-name foo[..]`
28752875
28762876
"#]])
28772877
.with_stdout_data(str![[r#"

tests/testsuite/lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ fn cdylib_and_rlib() {
619619
[RUNNING] `[ROOT]/foo/target/release/deps/bar-[HASH][EXE]`
620620
[RUNNING] `[ROOT]/foo/target/release/deps/b-[HASH][EXE]`
621621
[DOCTEST] bar
622-
[RUNNING] `rustdoc --edition=2015 --crate-type cdylib --crate-type rlib --crate-name bar --test [..]-C lto [..]
622+
[RUNNING] `rustdoc --edition=2015 --crate-type cdylib --crate-type rlib --color auto --crate-name bar --test [..]-C lto [..]
623623
624624
"#]].unordered())
625625
.run();

tests/testsuite/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5555,7 +5555,7 @@ fn cargo_test_print_env_verbose() {
55555555
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
55565556
[RUNNING] `[..]CARGO_MANIFEST_DIR=[ROOT]/foo[..] [ROOT]/foo/target/debug/deps/foo-[HASH][EXE]`
55575557
[DOCTEST] foo
5558-
[RUNNING] `[..]CARGO_MANIFEST_DIR=[ROOT]/foo[..] rustdoc --edition=2015 --crate-type lib --crate-name foo[..]`
5558+
[RUNNING] `[..]CARGO_MANIFEST_DIR=[ROOT]/foo[..] rustdoc --edition=2015 --crate-type lib --color auto --crate-name foo[..]`
55595559
55605560
"#]]).run();
55615561
}

0 commit comments

Comments
 (0)