Skip to content
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

Option --color=always does not work on tests #11581

Closed
carlomilanesi opened this issue Jan 14, 2023 · 1 comment
Closed

Option --color=always does not work on tests #11581

carlomilanesi opened this issue Jan 14, 2023 · 1 comment
Labels
C-bug Category: bug

Comments

@carlomilanesi
Copy link

Problem

The option --color=always should keep ANSI codes when output is sent to a pipe.
Instead, when running a test, the green texts ok, and the red texts FAILED are not colored.

Steps

Create a project using cargo new dummy --lib.
Type cargo --color=always test | more.
The text ok appears three times not colored, instead of dark green.

Possible Solution(s)

No response

Notes

Test output is directed to stdout, while normal cargo output goes to stderr. It appears that ANSI codes are kept only for stderr.

Version

cargo 1.66.1 (ad779e08b 2023-01-10)
release: 1.66.1
commit-hash: ad779e08be893e57a9e17a810223a3e966f8c0d8
commit-date: 2023-01-10
host: x86_64-unknown-linux-gnu
libgit2: 1.5.0 (sys:0.16.0 vendored)
libcurl: 7.83.1-DEV (sys:0.4.55+curl-7.83.1 vendored ssl:OpenSSL/1.1.1q)
os: Linux Mint 20.3 (una) [64-bit]
@carlomilanesi carlomilanesi added the C-bug Category: bug label Jan 14, 2023
@ehuss
Copy link
Contributor

ehuss commented Jan 14, 2023

Thanks for the report! The issue is that the tests are handled by a separate process with its own CLI and environment variables. To force color for the tests, too, you need to pass the color option to the test harness as in:

cargo test --color=always -- --color=always

Closing as a duplicate of #1983

@ehuss ehuss closed this as not planned Won't fix, can't repro, duplicate, stale Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants