Skip to content

Commit

Permalink
Fix cargo fix not showing colors.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Oct 28, 2019
1 parent 759431f commit 91a59e6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ pub fn fix_maybe_exec_rustc() -> CargoResult<bool> {
// - If the fix succeeded, show any remaining warnings.
let mut cmd = Command::new(&rustc);
args.apply(&mut cmd);
for arg in args.format_args {
// Add any json/error format arguments that Cargo wants. This allows
// things like colored output to work correctly.
cmd.arg(arg);
}
exit_with(cmd.status().context("failed to spawn rustc")?);
}

Expand Down Expand Up @@ -587,6 +592,7 @@ struct FixArgs {
other: Vec<OsString>,
rustc: Option<PathBuf>,
clippy_args: Vec<String>,
format_args: Vec<String>,
}

enum PrepareFor {
Expand Down Expand Up @@ -627,6 +633,7 @@ impl FixArgs {
if s.starts_with("--error-format=") || s.starts_with("--json=") {
// Cargo may add error-format in some cases, but `cargo
// fix` wants to add its own.
ret.format_args.push(s.to_string());
continue;
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1289,3 +1289,22 @@ fn fix_with_clippy() {
"
);
}

#[cargo_test]
fn fix_color_message() {
// Check that color appears in diagnostics.
let p = project()
.file("src/lib.rs", "std::compile_error!{\"color test\"}")
.build();

p.cargo("fix --allow-no-vcs --color=always")
.with_stderr_contains("[..]\x1b[[..]")
.with_status(101)
.run();

p.cargo("fix --allow-no-vcs --color=never")
.with_stderr_contains("error: color test")
.with_stderr_does_not_contain("[..]\x1b[[..]")
.with_status(101)
.run();
}

0 comments on commit 91a59e6

Please sign in to comment.