MyDeveloperDay
MyDeveloperDay

Reputation: 2670

Can ctest display googletest console colors

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?

Upvotes: 17

Views: 8392

Answers (4)

Rob Ruchte
Rob Ruchte

Reputation: 3707

You can specify arguments in the add_test COMMAND option like so:

add_test(NAME testExecutable
        COMMAND testExecutable --gtest_color=1)

This will cause the output to be rendered with the correct colors when run from CMake.

Upvotes: 1

Simon Puente
Simon Puente

Reputation: 491

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

Upvotes: 7

MaEtUgR
MaEtUgR

Reputation: 383

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

Upvotes: 14

Étienne
Étienne

Reputation: 4984

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

export GTEST_COLOR=1

Upvotes: 21

Related Questions