Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 206
MyDeveloperDay Avatar asked Dec 13 '15 16:12

MyDeveloperDay


3 Answers

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

like image 121
Simon Puente Avatar answered Oct 24 '22 05:10

Simon Puente


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
like image 41
MaEtUgR Avatar answered Oct 24 '22 07:10

MaEtUgR


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

export GTEST_COLOR=1
like image 16
Étienne Avatar answered Oct 24 '22 06:10

Étienne