Replace ctest command with "ctest --output-on-failure" permanently for a specific project in CMakeLists.txt
Asked Answered
A

2

19

I have found that generic ctest command doesn't give much information about the tests, so I would like to add ctest --output-on-failure but not have the users to worry about the flag. I want them just to cmake, make the project and run ctest and it should run ctest with the --output-on-failure flag. Is it possible to do that in CMakeLists.txt?

EDIT:

Output of env CTEST_OUTPUT_ON_FAILURE=1 make test

 4/13 Test  #4: TEST_SSSP ........................***Failed  Required regular expression not found.Regex=[CORRECT
]  0.00 sec
Loading Matrix-market coordinate-formatted graph ...
Input graph file /home/muhammad/gunrock/dataset/small/chesapeake.mtx does not exis

Output of set_property(TEST TestName PROPERTY ENVIRONMENT "CTEST_OUTPUT_ON_FAILURE=1")

 4/13 Test  #4: TEST_SSSP ........................***Failed  Required regular expression not found.Regex=[CORRECT
]  0.00 sec

The flag in set_property is not working.

Apery answered 19/4, 2016 at 18:25 Comment(3)
" This option can also be enabled by setting the environment variable CTEST_OUTPUT_ON_FAILURE" cmake.org/cmake/help/v3.0/manual/ctest.1.htmlHoney
@NicolasHolthaus How would I permenantly set CTEST_OUTPUT_ON_FAILURE to true in CMakeLists.txt? Is it just with a simple set command?Apery
Thank you so much for your help Nicolas! I ended up adding custom target make check.Apery
J
25

In CMake 3.17 release notes, there's a new variable CMAKE_CTEST_ARGUMENTS that you can set to pass any command-line arguments to CTest, including --output-on-failure. In your specific case, you can now simply add this to your CMakeLists.txt:

list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
Jonathanjonathon answered 19/2, 2020 at 15:15 Comment(0)
A
8

I went with make check per solution: CMake: setting an environmental variable for ctest (or otherwise getting failed test output from ctest/make test automatically)

add_custom_target(check ${CMAKE_COMMAND} -E env CTEST_OUTPUT_ON_FAILURE=1
                  ${CMAKE_CTEST_COMMAND} -C $<CONFIG> --verbose
                  WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
Apery answered 19/4, 2016 at 20:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.