I have some tests in my build that are optional. My CMakeLists.txt looks approximately like:
add_custom_target(all-tests)
add_executable(A ...)
add_dependencies(all-tests A)
add_test(NAME A COMMAND ...)
add_executable(B ...)
add_dependencies(all-tests B)
add_test(NAME B COMMAND ...)
## optional
add_executable(C EXCLUDE_FROM_ALL ...)
add_test(NAME C COMMAND ...)
The idea being that I can run
$ make all-tests
$ ctest
To both compile all my unit tests and then run them. The problem is, since C
is optional, it doesn't build (all desired). And since it didn't build, it doesn't exist, and gets reported as having failed:
The following tests FAILED:
6 - C (Not Run)
Errors while running CTest
Is there a way to ignore this failure / have CTest not try to run tests that don't exist / otherwise express the idea of an optional test? I have a class of these optional tests that have similar names, so it'd be nice to be able to use ctest -R
to run them, if they are built, rather than having to configure some script or other approach.