Skip to content

Commit 4e62a57

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

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

src/cargo/ops/cargo_test.rs

Lines changed: 17 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 {
@@ -212,9 +214,24 @@ fn run_doc_tests(
212214
gctx.shell().status("Doc-tests", unit.target.name())?;
213215
let mut p = compilation.rustdoc_process(unit, *script_meta)?;
214216

217+
let color_arg = match color {
218+
ColorChoice::Always => "always",
219+
ColorChoice::Never => "never",
220+
ColorChoice::CargoAuto => "auto",
221+
};
222+
p.arg("--color").arg(color_arg);
223+
215224
for (var, value) in env {
216225
p.env(var, value);
217226
}
227+
228+
let color_arg = match color {
229+
ColorChoice::Always => "always",
230+
ColorChoice::Never => "never",
231+
ColorChoice::CargoAuto => "auto",
232+
};
233+
p.arg("--color").arg(color_arg);
234+
218235
p.arg("--crate-name").arg(&unit.target.crate_name());
219236
p.arg("--test");
220237

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)