CMake和CTest的默认“测试”命令跳过一个特别命名的测试 [英] CMake and CTest's default "test" command skips a specially named test
问题描述
我正在将CTest与CMake结合使用以运行一些测试。我使用 enable_testing()
命令,该命令为 make test
提供了一个默认命令。我的子目录中的所有测试均已考虑在内(通过执行 add_test
命令),并且 make test
效果很好,除了一个问题。
I'm using CTest with CMake to run some tests. I use the enable_testing()
command which provides me with a default command for make test
. All of the tests in my subdirectory are accounted for (by doing an add_test
command) and make test
works great, except one problem.
有一个测试,我将其命名为 skip_test
,我不想在运行时运行做进行测试
。我想添加一个自定义目标,以便我可以运行 make skip_test
,它将运行该测试。
There is a certain test, which I've named skip_test
, that I do NOT want being run when I do make test
. I would like to add a custom target so I can run make skip_test
and it will run that test.
I可以通过执行 add_custom_target(skip_test ...)
并为CTest提供 -R
标志并将其告知查找名称中包含 skip_test的文件。这似乎也可行。我现在的问题是:如何获得 make test
命令以忽略 skip_test
?
I can do this by doing add_custom_target(skip_test ...)
and providing CTest with the -R
flag and telling it to look for files containing "skip_test" in their name. This also seems to work. My problem now is: how can I get the make test
command to ignore skip_test
?
如果我尝试注释掉 enable_testing
并添加自己的 add_custom_target(test ....)
,我收到未找到测试!!!现在可以进行进行测试
或进行skip_test
。我还尝试制作一个自定义CTest文件并添加 set(CTEST_CUSTOM_TESTS_IGNORE skip_test)
。这样做可以使现在 make test
忽略 skip_test,但是现在运行 make skip_test
则返回未找到测试! !!。
If I try commenting out enable_testing
and adding my own add_custom_target(test ....)
, I get "No tests found!!!" now for either make test
or make skip_test
. I also tried making a Custom CTest file and adding set(CTEST_CUSTOM_TESTS_IGNORE skip_test)
. This worked so that now make test
ignored "skip_test", but now running make skip_test
responds with "no tests found!!!".
任何建议将不胜感激!
推荐答案
我实际上使用了不同的解决方案。这是我所做的。对于我要排除的测试,在添加它们时使用了以下命令:
I actually used a different solution. Here is what I did. For the tests that I wanted to exclude, I used the following command when adding them:
add_test(..... CONFIGURATIONS ignore_flag),其中ignore_flag是任何短语你要。然后,在我的CMakeLists.txt中,当我定义自定义目标
add_custom_target(ignore_tests ...)
时,我将其赋予ctest...。-C ignore_flag
"add_test( ..... CONFIGURATIONS ignore_flag)" where ignore_flag is whatever phrase you want. Then, in my CMakeLists.txt, when I define a custom target add_custom_target( ignore_tests ...) I give it ctest .... -C ignore_flag
现在,进行测试将跳过这些测试! make ignore_Tests将运行被忽略的测试+被忽略的测试,我可以接受。
Now, make test WILL skip these tests! make ignore_Tests will run the ignored tests + the un-ignored tests, which I'm okay with.
这篇关于CMake和CTest的默认“测试”命令跳过一个特别命名的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!