mitsuhiko / similar-asserts

Provides assert_eq! like macros with colorized diff output
Apache License 2.0
126 stars 6 forks source link

No colored diff with cargo-nextest #10

Open mlafeldt opened 9 months ago

mlafeldt commented 9 months ago

Hey, while giving this library a try, I noticed that it wouldn't output colored diffs when using cargo-next as a test runner (which otherwise works fine with pretty_assertions).

cargo nextest run with similar-asserts:

image

cargo nextest run with pretty_assertions:

image

cargo test works fine too (unsurprisingly):

image

Since cargo-nextest is a popular test runner, is there anything we can do to get colored output with it too?

mlafeldt commented 9 months ago

OTOH, it works with cargo nextest run --no-capture, which has the downside of running tests serially though.

sunshowers commented 8 months ago

Hi, main author of nextest here. The problem is that the output is captured, and since similar-asserts (correctly) thinks this isn't a tty so doesn't output color.

The usual way to handle this is with CLICOLOR_FORCE. Nextest could set that env var, but my concern with it being set that is that it would break tests which execute subprocesses of their own and depend on the output not containing colors (in fact, the nextest repo itself has some tests which work that way.)

Nextest could in principle set its own NEXTEST_COLOR=1 and =0 variable to indicate whether test utilities like similar-asserts should produce colored output. Would that work? @mitsuhiko's opinion would be really valuable here.