assert-rs / snapbox

Snapshot testing for a herd of CLI tests
docs.rs/trycmd
Apache License 2.0
137 stars 18 forks source link

Colourised output even when TERM=dumb #360

Closed ijackson closed 2 months ago

ijackson commented 2 months ago

When running trycmd in an environment without a graphical terminal (for example, an emacs M-x compile window) trycmd still produces colourised output.

trycmd should look at TERM to decide whether to colourise the output. At the very least, if TERM=dumb it should avoid sending control codes.

CC @gabi-250 (since this is related to use of trycmd in Arti's tests)

epage commented 2 months ago

Could you provide reproduction steps? We should be checking TERM=dumb

ijackson commented 2 months ago

Steps

(not minimised, sorry)

git clone https://gitlab.torproject.org/tpo/core/arti.git
cd arti
git checkout  5e2d5532d002c9df9a4cf6d83cdbe7d6125bc4be
perl -i~ -pe 's/flamingo is not configured/XXXX/' crates/arti/tests/testcases/hss/hss.md
TERM=xterm cargo test --locked --offline -p arti --all-features -- cli_tests
TERM=dumb cargo test --locked --offline -p arti --all-features -- cli_tests

Expected output

  1. Error report containing coloured output
  2. Error report containing plain text output

Actual output

Two error reports with coloured output, including in overview report, and coloured diff.

Discussion

I may be confused, but during my testing they appeared to be influenced by previous runs. Hence the two step process above.

I can see the colour escape sequences if I add 2>&1 | cat -vet

epage commented 2 months ago
$ git checkout 3957a384aca2cef964e86ba9ad48d98c6f4cf0dc 

I got an error that that commit wasn't in my tree

ijackson commented 2 months ago

I got an error that that commit wasn't in my tree

Sorry about that. Fixed it, please use 5e2d5532d002c9df9a4cf6d83cdbe7d6125bc4be (if you still need it...)