CMake and CTest's default “test” command skips a specially named test

孤人 提交于 2019-12-05 23:34:33

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)" 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

Now, make test WILL skip these tests! make ignore_Tests will run the ignored tests + the un-ignored tests, which I'm okay with.

I'm not sure of a way to do this entirely via CTest, but since you've tagged this question with "googletest", I assume you're using that as your test framework. So, you could perhaps make use of Gtest's ability to disable tests and also to run disabled tests.

By changing the test(s) in question to have a leading DISABLED_ in their name(s), these won't be run by default when you do make test.

You can then add your custom target which will invoke your test executable with the appropriate Gtest flags to run only the disabled tests:

add_custom_target(skip_test
    MyTestBinary --gtest_filter=*DISABLED_* --gtest_also_run_disabled_tests VERBATIM)

It's a bit of an abuse of the Gtest functionality - it's really meant to be used to temporarily disable tests while you refactor whatever to get the test passing again. This beats just commenting out the test since it continues to compile it, and it gives a nagging reminder after running the suite that you have disabled tests.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!