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

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

Closed
max-sixty opened this issue Jun 2, 2023 · 2 comments
Closed
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. C-bug Category: bug

Comments

@max-sixty
Copy link

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]
@max-sixty max-sixty added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Jun 2, 2023
@weihanglo
Copy link
Member

Thanks for the report! The issue is that the tests are handled by a separate process with its own CLI and environment variables. To force color for the tests, too, you need to pass the color option to the test harness as in:

cargo test --color=always -- --color=always

Closing as a duplicate of #1983

@weihanglo weihanglo closed this as not planned Won't fix, can't repro, duplicate, stale Jun 2, 2023
@weihanglo weihanglo added A-console-output Area: Terminal output, colors, progress bar, etc. and removed S-triage Status: This issue is waiting on initial triage. labels Jun 2, 2023
@max-sixty
Copy link
Author

Thanks @weihanglo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants