Can ctest display googletest console colors
Asked Answered
R

4

16

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?

Recuperate answered 13/12, 2015 at 16:45 Comment(4)
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?Demure
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 promptRecuperate
"export GTEST_COLOR=1" worked for me (on Ubuntu).Walls
@Étienne It worked for me, thx!Milieu
C
20

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

export GTEST_COLOR=1
Casavant answered 13/12, 2015 at 16:45 Comment(1)
sadly, this doesn't work within the Windows Developer Command Prompt. GTEST_COLOR only seems to help when calling the Google Test runner manually; trying to use ctest still gives uncolored output :(Bayberry
C
14

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
Cattle answered 7/2, 2019 at 8:5 Comment(0)
M
7

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

Manet answered 14/4, 2019 at 17:47 Comment(0)
S
0

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.

Sipper answered 23/4 at 19:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.