11

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
Patrick B.
  • 11,773
  • 8
  • 58
  • 101
user3791162
  • 111
  • 1
  • 3

1 Answers1

21

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.

Fraser
  • 74,704
  • 20
  • 238
  • 215