Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CTest - Using Labels for different tests CTestTestfile.cmake

Tags:

cmake

ctest

I cannot find how to specify labels. It should be something like

ADD_TEST( FirstTest RunSomeProgram "withArguments" )
SET_TESTS_PROPERTIES( FirstTest PROPERTIES LABEL "TESTLABEL" )

Can someone tell me how I can set one of these labels, that I can access using the

ctest -S someScript -L TESTLABEL
like image 713
user3791162 Avatar asked Jun 30 '14 17:06

user3791162


People also ask

Does CTest run tests in parallel?

Run the tests in parallel using the given number of jobs. This option tells CTest to run the tests in parallel using given number of jobs. This option can also be set by setting the CTEST_PARALLEL_LEVEL environment variable. This option can be used with the PROCESSORS test property.

Is CTest part of CMake?

CTest is an executable that comes with CMake; it handles running the tests for the project. While CTest works well with CMake, you do not have to use CMake in order to use CTest.

What is Enable_testing in CMake?

enable_testing() Enables testing for this directory and below. This command should be in the source directory root because ctest expects to find a test file in the build directory root. This command is automatically invoked when the CTest module is included, except if the BUILD_TESTING option is turned off.

What does CMake add_test do?

Options To add_test(...) COMMAND specifies the command to run for the test. Essentially, this can be any command that would normally run in your terminal. You can also pass the name of an executable target, and CMake will replace it with the full location of the executable.


1 Answers

You're close - the test property is named LABELS, not LABEL.

There are a couple of ways of setting labels; the one you've chosen (using set_tests_properties) has a slight gotcha. The signature is:

set_tests_properties(test1 [test2...] PROPERTIES prop1 value1 prop2 value2)

This means that each property can only have a single value applied. So if you want to apply multiple labels to tests this way, you need to "trick" CMake by passing the list of labels as a single string comprising a semi-colon-separated list:

set_tests_properties(FirstTest PROPERTIES LABELS "TESTLABEL;UnitTest;FooModule")

or

set(Labels TESTLABEL UnitTest FooModule)
set_tests_properties(FirstTest PROPERTIES LABELS "${Labels}")  # Quotes essential


On the other hand, you can pass a proper list of labels using the more general set_property command:

set_property(TEST FirstTest PROPERTY LABELS TESTLABEL UnitTest FooModule)

or

set_property(TEST FirstTest PROPERTY LABELS ${Labels})  # No quotes needed

The slight downside of this command is that you can only apply one property per call.

like image 142
Fraser Avatar answered Sep 18 '22 02:09

Fraser