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

when output filename is set, ANSI color codes are printed to stdout #1502

Closed
mjerabek opened this issue Jan 18, 2019 · 1 comment
Closed
Labels

Comments

@mjerabek
Copy link
Contributor

Describe the bug
When Catch output is redirected to a file via the --out option and color output is forced via --use-colour=yes, the color escape sequences are written to stdout instead of to the file.

Expected behavior
The color codes are written to the file.

Reproduction steps

$ g++ -x c++ -DCATCH_CONFIG_MAIN -o tests - <<<'#include "catch.hpp"' # or really anything
$ ./tests -s -o results.txt --use-colour=yes >captured-stdout.txt
$ cat results.txt
===============================================================================
No tests ran

$ # no colors
$ od -t x1 captured-stdout.txt
0000000 1b 5b 31 3b 33 33 6d 1b 5b 30 6d 1b 5b 31 3b 33
0000020 33 6d 1b 5b 30 6d
0000026

Platform information:

  • OS: Linux
  • Compiler+version: GCC v8.2.1
  • Catch version: v2.5.0

Additional context
I looked inside of the code and the reporters use Colour colour(Colour::ResultSuccess); as scoped colour setting. That calls Colour::use(Colour::Code) -> IColourImpl::use(Colour::Code). PosixColourImpl::setColour then retrieves the stream via Catch::cout(), which is wrong.

IMHO the cleanest solution is that the Colour RAII guard takes the stream, but that requires modifying all the reporters, even external (could be defaulted, but that would keep the code wrong unnoticed).
Alternatively retrieve the stream in setColour via getCurrentContext().getConfig()->stream(), which is much simpler, but I don't know if it could have any side effects.

@mjerabek
Copy link
Contributor Author

The commit does not compile -- it should be getCurrentContext().getConfig()->stream(), but is getCurrentContext().getConfig().stream().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants