--color_output with MinGW from MSYS2 uses escaping sequences instead of WinAPI functions
- Dominant language
- C++
- Stars
- 39.5k
- Forks
- 10.9k
- Avg merge
- 6d 13h
- Merged PRs (30d)
- 1
Description
Hello!
I have installed GCC 9.2.0 from MSYS2 and I have compiled it with my tests.
When I run googletest with `--gtest_color=yes` flag I have output with escape sequences like `[0;32m`.
Although on Windows, I think the `SetConsoleTextAttribute` function should be used.
I did a little research and found that there is a check in the code that `GTEST_OS_WINDOWS_MINGW` wasn't detected.
If it's not detected, works with Windows API functions, but if it's detected, it will try to use escape sequences.
If I remove that check, it works fine, and I can see the color output.
My question is: why is this done? I don't think it's wrong, but I don't see the point.
Please explain to me why and if possible explain how to fix it.
`gcc -v` output if needed:
```bash
Using built-in specs.
COLLECT_GCC=C:\msys64\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-9.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++ --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --enable-plugin --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev2, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 9.2.0 (Rev2, Built by MSYS2 project)
```
Contributor guide
Research direction
Start by tracing the --gtest_color handling and the GTEST_OS_WINDOWS_MINGW conditional, then compare the escape-sequence path with the SetConsoleTextAttribute path. Done means MinGW builds on Windows produce colored output without printing raw escape sequences.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- cli, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100