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

libtest output is not colored #2292

Closed
RalfJung opened this issue Jun 30, 2022 · 13 comments · Fixed by #2471
Closed

libtest output is not colored #2292

RalfJung opened this issue Jun 30, 2022 · 13 comments · Fixed by #2471
Labels
A-shims Area: This affects the external function shims A-ux Area: This affects the general user experience C-bug Category: This is a bug.

Comments

@RalfJung
Copy link
Member

RalfJung commented Jun 30, 2022

cargo miri test output is not colored the same way cargo test is: the output that is generated inside Miri (the libtest runner) uses no colors. I think this is probably because of the hack where we remove the TERM environment variable even with isolation disabled -- that makes libtest think that the terminal does not support color so it falls back to no colors. (EDIT: looks like I am wrong, see below.)

We remove the TERM variable because having it makes libtest startup super slow (that was #1702). Maybe we need another work-around for this problem, like adding a cfg(miri) somewhere to skip the slow code -- or actually making Miri less slow on that code.^^

@saethlin this is the bug you mentioned in one of your PRs; it has nothing to do with --color=always (other than, even with --color=always, libtest still uses no color unless TERM indicates that the terminal supports color).

@RalfJung RalfJung added C-bug Category: This is a bug. A-ux Area: This affects the general user experience labels Jun 30, 2022
@RalfJung
Copy link
Member Author

With #2293 we can use MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-env-forward=TERM" cargo miri test to test what happens when TERM is properly forwarded... and strangely there are still no colors. Hm...

@RalfJung
Copy link
Member Author

Ah, got it -- in addition to forwarding TERM, we also need to adjust our isatty shim, which currently just says nothing is a TTY.

I am not sure what the best solution is here, given the multi-second wait triggered by forwarding TERM.

@saethlin
Copy link
Member

Is it sufficient to just lie about whether we are a TTY? I was honestly thinking of hacking up something like that for myself to induce colors to appear.

@RalfJung
Copy link
Member Author

As I said, we need both TERM and the isatty change.

@saethlin
Copy link
Member

Argh I was reading your phrasing in the most desperately optimistic way possible.

terminfo files are a mess, and I really wonder how much portability this is actually providing for libtest. Are people actually running cargo test or cargo miri test on a terminal that only supports 8-bit colors? That would be shocking. I wonder if whoever is in charge of this code would be okay with us just bypassing the parsing with a #[cfg(miri)] and selecting some terminfo that we think is reasonable everywhere that Cargo/Miri can run.

@RalfJung
Copy link
Member Author

RalfJung commented Jun 30, 2022 via email

@saethlin
Copy link
Member

I was thinking of a flag so the user could pick, but it would be better to have the shim work correctly.

@RalfJung
Copy link
Member Author

RalfJung commented Jun 30, 2022 via email

@saethlin
Copy link
Member

saethlin commented Jun 30, 2022

Everyone goes through this crate https://crates.io/crates/atty

@RalfJung
Copy link
Member Author

RalfJung commented Jul 1, 2022

Hm, not sure how I feel about adding external dependencies. We are quite conservative about that here. OTOH that sounds like exactly the API we want and it is even cross-platform...

But anyway it seems like there are two orthogonal steps here:

  • make whatever code in libtest parses the TERM stuff just skip all that under cfg(miri) and assume a reasonably modern terminal, but still honor isatty
  • do something more clever with Miri's isatty shim

@RalfJung RalfJung added the A-shims Area: This affects the external function shims label Jul 2, 2022
@RalfJung
Copy link
Member Author

RalfJung commented Jul 2, 2022

Everyone goes through this crate https://crates.io/crates/atty

Alternatively we could copy this file which is tiny.

bors added a commit that referenced this issue Jul 18, 2022
Improve isatty support

Per #2292 (comment), this is an attempt at

> do something more clever with Miri's `isatty` shim

Since Unix -> Unix is very simple, I'm starting with a patch that just does that. Happy to augment/rewrite this based on feedback.

The linked file in libtest specifically only supports stdout. If we're doing this to support terminal applications, I think it would be strange to support one but not all 3 of the standard streams.

The `atty` crate contains a bunch of extra logic that libtest does not contain, in order to support MSYS terminals: softprops/atty@db8d55f so I think if we're going to do Windows support, we should probably access all that logic somehow. I think it's pretty clear that the implementation is not going to change, so I think if we want to, pasting the contents of the `atty` crate into Miri is on the table, instead of taking a dependency.
@RalfJung
Copy link
Member Author

RalfJung commented Jul 18, 2022

With #2349, the following now produces colored output:

MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-env-forward=TERM" cargo miri test

However it also takes forever to start, due to the terminfo parsing.
(And I feel like that has gotten slower recently? It used to take maybe 2-10s, now it is on the order of 30-60s... @saethlin there might be a benchmark hiding here that got worse recently)

@RalfJung
Copy link
Member Author

(never mind I was running a Miri with debug assertions^^)

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 7, 2022
test: skip terminfo parsing in Miri

Terminfo parsing takes a significant amount of time in Miri, making libtest startup very slow. To work around that Miri in fact unsets the `TERM` variable. However, this means we don't get colors in `cargo miri test`.

So I propose we add some logic in libtest that skips parsing terminfo files under Miri, and just uses the regular basic coloring commands (taken from the `colored` crate).

As far as I can see, these two commands are all that libtest ever needs from terminfo, so Miri doesn't even lose any functionality through this. If you want I can entirely remove the terminfo parsing code and just use these commands instead.

Cc rust-lang/miri#2292 `@saethlin`
@bors bors closed this as completed in 654e15b Aug 8, 2022
workingjubilee pushed a commit to tcdi/postgrestd that referenced this issue Sep 15, 2022
test: skip terminfo parsing in Miri

Terminfo parsing takes a significant amount of time in Miri, making libtest startup very slow. To work around that Miri in fact unsets the `TERM` variable. However, this means we don't get colors in `cargo miri test`.

So I propose we add some logic in libtest that skips parsing terminfo files under Miri, and just uses the regular basic coloring commands (taken from the `colored` crate).

As far as I can see, these two commands are all that libtest ever needs from terminfo, so Miri doesn't even lose any functionality through this. If you want I can entirely remove the terminfo parsing code and just use these commands instead.

Cc rust-lang/miri#2292 `@saethlin`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-shims Area: This affects the external function shims A-ux Area: This affects the general user experience C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants