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

Disabling colored output requires convoluted cargo test --color=never -- --color=never incantation #1983

Open
slimsag opened this issue Sep 11, 2015 · 12 comments
Labels
A-cli Area: Command-line interface, option parsing, etc. A-console-output Area: Terminal output, colors, progress bar, etc. Command-test S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@slimsag
Copy link

slimsag commented Sep 11, 2015

EDIT: see durka's comment below

It seems that there is no way to disable the colored output of cargo test. This is a nice thing to have when displaying output on e.g. CI sites that do not support ASCII escape codes.

Combinations I tried blindly that didn't work include:

  • cargo test --no-color
  • cargo test -- --no-color
  • cargo test --color
  • cargo test -- --color
  • cargo test --color never

Also checked output of cargo -h and cargo test -h but saw nothing.

@durka
Copy link
Contributor

durka commented Sep 11, 2015

On cargo 0.5.0 2015-09-04 (the one distributed with current nightly), the correct incantation seems to be

cargo test --color=never -- --color=never

Perhaps cargo test should automatically forward the color flag to the test runner?

@slimsag
Copy link
Author

slimsag commented Sep 11, 2015

Thanks @durka! I can confirm that works. I will update the title of the issue because cargo test --color=never -- --color=never seems a bit convoluted to me 👍

@slimsag slimsag changed the title Can't disable colored output of cargo test Disabling colored output requires convoluted cargo test --color=never -- --color=never incantation Sep 11, 2015
@alexcrichton alexcrichton added E-easy Experience: Easy Command-test labels Sep 13, 2015
@alexcrichton
Copy link
Member

While I think this should probably apply to all invocations of rustc or rustdoc, I'm much more wary to pass this down to test executables. Currently we have only one test framework but one day there will likely be many, and even today you can create test executables without a harness (e.g. no --test) where this option may not be supported or recognized.

I think a better solution may be for the test harness and Cargo to agree on an environment variable to disable or enable colorization or some other method not involving an extra argument.

@alexcrichton alexcrichton removed the E-easy Experience: Easy label Sep 13, 2015
@durka
Copy link
Contributor

durka commented Sep 14, 2015

There is already RUST_TEST_THREADS, so following the pattern would be RUST_TEST_COLOR, I suppose?

@alexcrichton
Copy link
Member

Sounds pretty reasonable to me!

@durka
Copy link
Contributor

durka commented Sep 14, 2015

@alexcrichton though... were you thinking this env var would disable color in other Cargo modes, as well? Like building and doc-ing?

@durka
Copy link
Contributor

durka commented Sep 14, 2015

The way I see it, there are two orthogonal-ish questions:

  • Will the environment variable affect color just for testing or across all of the tooling (is rustc going to learn it)?
  • Should cargo set this flag when passed --color or will that switch eventually go away leaving the environment variable as the Right Way to do it?

@alexcrichton
Copy link
Member

So to start out with I was just thinking that whenever Cargo executed a test binary it would set this environment variable according to the flags passed to Cargo itself, but there's certainly a broader question of if there's an environment variable everyone can agree on to control this aspect. One has been proposed in rust-lang/rust#27867, for example.

@stale
Copy link

stale bot commented Nov 17, 2018

As there hasn't been any activity here in a while would someone (the author, a team member, or any interested party) be able to summarise the current state, perhaps making explicit:

  • Is this still relevant?
  • If so, what is blocking it?
  • Is it known what could be done to help move this forward?

Thank you!

(The cargo team is currently evaluating the use of Stale bot, and using #6035 as the tracking issue to gather feedback.)

If you're reading this comment from the distant future, fear not if this was closed automatically. If you believe it's still an issue please leave a comment and a team member can reopen this issue. Opening a new issue is also acceptable!

@stale stale bot added the stale label Nov 17, 2018
@stale
Copy link

stale bot commented Dec 17, 2018

As I didn't see any updates in 30 days I'm going to close this. Please see the previous comment for more information!

@stale stale bot closed this as completed Dec 17, 2018
@ehuss
Copy link
Contributor

ehuss commented Dec 18, 2018

I think this could probably stay open. I think there is an open question of forwarding flags to libtest, and how to handle other test harnesses (as being discussed in #6358 and #4325).

In particular, the following are also awkward:

cargo test -j2 -- --test-threads=2
cargo test --message-format=json -- --format=json
cargo test --quiet -- --quiet
cargo test --color=never -- --color=never

It might be a good idea to forward flags to libtest. But it would also be good to handle other harnesses, which isn't so straightforward. Environment variables are another option, which circumvents the issue of other harnesses not understanding the command-line (they would just be ignored).

@epage epage added the S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. label May 24, 2023
@epage
Copy link
Contributor

epage commented May 24, 2023

For #5609, I am looking at changing how cargo and libtest interact, with cargo taking more control over the rendering of output which would mean cargo will be showing the colored output, instead of libtest, resolving this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: Command-line interface, option parsing, etc. A-console-output Area: Terminal output, colors, progress bar, etc. Command-test S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
Status: No status
Development

No branches or pull requests

6 participants