Reputation: 879
I use Ctest to run a bunch of google tests that I have registered using add_test()
. Currently, these tests do not take any arguments. However, I want to give them all arguments (common to all, specifically --gtest_output=xml
) while running ctest
.
I heard that this is possible using that --test-command
option, however, I see that we need to use --test-command
along with --build-and-test
. Is there an example for this usage?
Upvotes: 11
Views: 5209
Reputation: 18243
The format for ctest
arguments are specified in the CTest documentation as such:
ctest --build-and-test <path-to-source> <path-to-build> --build-generator <generator> [<options>...] [--build-options <opts>...] [--test-command <command> [<args>...]]
So, on Visual Studio for example, you could run test Test1
from your build folder (using ..
for the source directory, and .
for the binary directory):
ctest --build-and-test .. . --build-generator "Visual Studio 16 2019" --test-command Test1 --gtest_output=xml
As of CMake 3.17, you can now specify arguments to pass to CTest (and arguments for individual tests) in the CMake file where you define the test itself. The CMAKE_CTEST_ARGUMENTS
variable takes a semicolon-delimited list of arguments to pass to CTest. So, sticking with the above example, you could do something like this:
set(CMAKE_CTEST_ARGUMENTS "--build-and-test;${CMAKE_SOURCE_DIR};${CMAKE_BINARY_DIR};--build-generator;${CMAKE_GENERATOR};--test-command;Test1;--gtest_output=xml")
Upvotes: 3