Skip to content

cargo build respects NO_COLOR=1 but cargo test does not #15343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
heaths opened this issue Mar 21, 2025 · 3 comments
Closed

cargo build respects NO_COLOR=1 but cargo test does not #15343

heaths opened this issue Mar 21, 2025 · 3 comments
Labels
C-bug Category: bug Command-test S-triage Status: This issue is waiting on initial triage.

Comments

@heaths
Copy link

heaths commented Mar 21, 2025

Problem

I was adding NO_COLOR support to our code and noticed that cargo build respects NO_COLOR=1 but cargo test does not e.g.:

Image

But:

Image

Steps

  1. cargo new repro --lib
  2. NO_COLOR=1 cargo build
  3. NO_COLOR=1 cargo test

Possible Solution(s)

No response

Notes

I appreciate there are lots of well-known/used environment variables that amount to the same thing e.g., FORCE_TTY, and I'm not advocating to support them all. It's just not possible. But it would be nice to support the ones cargo already does consistently.

Looking at some other bugs, I see you're using isatty for detection and that does seem to work in most cases e.g., piping to more. But if someone wanted to redirect output to a PTY e.g., in their own wrappers, they might still want a way to force color off since VT sequences may not be supported.

Version


@heaths heaths added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Mar 21, 2025
@epage
Copy link
Contributor

epage commented Mar 24, 2025

This appears to be a duplicate of #1983 and so I'm closing in favor of that. If there is a reason to keep this open, let us know!

@heaths
Copy link
Author

heaths commented Mar 24, 2025

Thanks. I searched for dups but didn't see that one. Found a couple similar but different behaviors e.g., build used to write color sequences regardless.

@epage
Copy link
Contributor

epage commented Mar 24, 2025

Yeah, the core of the issue is that a test harnesses color display is independent of Cargo. We want to change that. As we stabilize json output from libtest, we want to shift to more of a cargo/rustc-like relationship where libtest outputs what it wants and Cargo is responsible for stripping it when needed. We'd like to go even further and put Cargo in charge of rendering all of the results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug Command-test S-triage Status: This issue is waiting on initial triage.
Projects
Development

No branches or pull requests

2 participants