9
votes

I am building and running unit tests built with googletest inside a cmake project with ctest enabled

I run the tests with "ctest -VV"

but the test output does not color the "red" and "green"

[ RUN ] [ OK ] [ PASSSED ]

Does anyone know if there is an options to ctest to allow those colors to bleed through to the console?

3
Without knowing the way you added googletest to CMake nor your host environment, it's just a guess: Could this be duplicate to GTest's output has no colors when built with cmake+ninja and executed automatically? Can you give the googletest option --gtest_color=yes a try?Florian
So I tried --gtest_color=yes and that didn't work... but some more googling led me to GTEST_COLOR=1, setting this in my .travis.yml made the tests appear colored... but on my command line it looks like this 1: ←[0;32m[ RUN ] ←[mStringTest.Case, this suggest that googletest might be incorrectly thinking I'm an xterm, when actually I'm running bash inside a windows command promptMyDeveloperDay
"export GTEST_COLOR=1" worked for me (on Ubuntu).Étienne
@Étienne It worked for me, thx!Antonio Petricca

3 Answers

12
votes

As the OP suggested, I added this line to my .bashrc and it worked:

export GTEST_COLOR=1
4
votes

Maybe you don't want to export any variable to global scope and only have colors in one ctest call. In that case use this single command:

GTEST_COLOR=1 ctest -V
2
votes

In cmake you can pass environment variables like that:

add_executable(testExecutable
        my_test.cpp)

target_link_libraries(testExecutable
        gtest)

add_test(NAME testExecutable
        COMMAND testExecutable)

add_custom_target(check
        COMMAND env CTEST_OUTPUT_ON_FAILURE=1 GTEST_COLOR=1 ${CMAKE_CTEST_COMMAND}
        DEPENDS testExecutable)

run $ make check