Skip to content

Cargo doesn't seem to output colors to TTY in test report with --color=always #12220

Closed as not planned
@max-sixty

Description

@max-sixty

Problem

Cargo doesn't seem to output colors to TTY in test report with --color=always

Steps

Running:

CARGO_TERM_COLOR=always cargo test --color=always -p prql-compiler --lib

...yields colors in the terminal...

image

but when piped to a file, only the header uses colors, not the ok:

�[0m�[0m�[1m�[32m    Finished�[0m test [unoptimized + debuginfo] target(s) in 0.20s
�[0m�[0m�[1m�[32m     Running�[0m unittests src/lib.rs (target/debug/deps/prql_compiler-04315f547d0d4fc4)

running 169 tests
test ast::pl::ident::test_starts_with ... ok
test parser::test::test_case ... ok
test parser::test::test_coalesce ... ok
test parser::test::test_assign ... ok

Note the escape code in the first two lines, but not around ok.

Possible Solution(s)

rust-cli/team#15 might be relevant
And #11211 is tangential

Notes

I found this by trying to get https://github.com/Canop/bacon to work with Insta. Weirdly Insta does give color codes around ok when piped to a TTY (depending on how exactly --color=always is specified):

cargo insta test -p prql-compiler --lib --color=always -- --color=always
�[0m�[0m�[1m�[32m    Finished�[0m test [unoptimized + debuginfo] target(s) in 0.22s
�[0m�[0m�[1m�[32m     Running�[0m unittests src/lib.rs (target/debug/deps/prql_compiler-04315f547d0d4fc4)

running 169 tests
test ast::pl::ident::test_starts_with ... �[32mok�(B�[m
test parser::test::test_assign ... �[32mok�(B�[m
test parser::test::test_array ... �[32mok�(B�[m
test parser::test::test_backticks ... �[32mok�(B�[m

I think the difference in color output confuses Bacon, and so it can't parse the errors when tests are run through insta. I haven't dug in more, but there does seem to be an issue with Cargo.

Version

cargo version --verbose
cargo 1.68.2 (6feb7c9cf 2023-03-26)
release: 1.68.2
commit-hash: 6feb7c9cfc0c5604732dba75e4c3b2dbea38e8d8
commit-date: 2023-03-26
host: aarch64-apple-darwin
libgit2: 1.5.0 (sys:0.16.0 vendored)
libcurl: 7.87.0 (sys:0.4.59+curl-7.86.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
os: Mac OS 13.3.1 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-console-outputArea: Terminal output, colors, progress bar, etc.C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions