Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ctest - run tests having 2 labels

Tags:

label

ctest

lest assume I have some project that consists of N domains (D1, D2, ... , DN) . Each domain has tests of two kinds: lest say UT and MT. They are defined like so:

add_test(
  NAME Di_UT
  COMMAND <blah>
)

add_test(
  NAME Di_MT
  COMMAND <blah>
)

And I'd like to be able to filter them by labels. So I add the labels:

set_tests_properties(Di_UT PROPERTIES LABELS "UT;Di")
set_tests_properties(Di_MT PROPERTIES LABELS "MT;Di")

Then I execute ctest:

ctest -L Di

will execute all tests for domain Di, and of course the opposite:

ctest -L UT

Will execute all tests with UT label.

But how to filter by both labels? execute only UT for domain Di?

From what i observe, passing multiple -L causes them to overwrite. (the last one has effect). Any other ideas? my cmake version is

ctest version 3.13.4

like image 412
murison Avatar asked Oct 24 '25 12:10

murison


2 Answers

It seems that such thing is simply not supported. So as a workaround, I am simply adding a 3rd label containig the other two - and then pas it to ctest. So:

add_test(
  NAME Di_UT
  COMMAND <blah>
)

set_tests_properties(Di_UT PROPERTIES LABELS "UT;Di;UT-Di")

add_test(
  NAME Di_MT
  COMMAND <blah>
)
set_tests_properties(Di_MT PROPERTIES LABELS "MT;Di;MT-Di")

So then i can execute like so:

execute all UT:

ctest -L UT

execute all Tests for domain Di:

ctest -L Di

execute only UT for Di:

ctest -L Ut-Di

This seems only available option.

like image 170
murison Avatar answered Oct 28 '25 03:10

murison


I've been struggling with this too. It's such a pity that such feature is not supported, especially if you consider that the logical or works:

ctest -L 'label1|label2'

What I came up with is to create my own bash function which boils down to the following:

ctest -R "$(echo "$(ctest -N -L label1 | awk '/Test #/ { print $3}')" | tr '\n' '|')" -L label2

I know, it's a bit ugly, but let's break it down.

  1. You ask ctest to give you all the tests with label1 (-N, so you only list them).
  2. Then use awk to extract the test name (without the string Test #xyz: first).
  3. Then you put all those lines into a single regexp, by replacing \n with |.
  4. You use this string as a regexp for ctest, combined with a request for a new label. This makes ctest run tests which have label2 and match any of the test names you found at step 1.

It's quite cumbersome, especially if you want to run tests that have N labels.

like image 41
bartgol Avatar answered Oct 28 '25 02:10

bartgol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!