Skip to content

Commit e4765dd

Browse files
committed
Allow flagging tests as unstable to disable them in normal builds
* Run production builds with a stable set of tests by default * Enable all tests by default for development builds * Allow configuring whether to run unstable tests and particular test cases via CMake variables
1 parent 637d687 commit e4765dd

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

cmake/modules/TestUtilities.cmake

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@ set(TESTING_UTILITIES_LOADED YES)
1010
include(CTest)
1111

1212
set(EXCLUDE_TEST_TARGET_BY_DEFAULT ON)
13+
set(DISABLE_UNSTABLE_TESTS_BY_DEFAULT ON)
1314
if (ENABLE_DEVEL_DEFAULTS)
1415
set(EXCLUDE_TEST_TARGET_BY_DEFAULT OFF)
16+
set(DISABLE_UNSTABLE_TESTS_BY_DEFAULT OFF)
1517
endif ()
1618
option(EXCLUDE_TESTS_FROM_ALL "specifies whether to exclude tests from the 'all' target (enabled by default)"
1719
"${EXCLUDE_TEST_TARGET_BY_DEFAULT}")
20+
option(DISABLE_UNSTABLE_TESTS
21+
"specifies whether unstable tests should be disabled (they are enabled by default for devel builds)"
22+
"${DISABLE_UNSTABLE_TESTS_BY_DEFAULT}")
1823

1924
function (configure_test_target)
2025
# parse arguments
21-
set(OPTIONAL_ARGS MANUAL REQUIRES_MAIN_TARGET)
26+
set(OPTIONAL_ARGS MANUAL UNSTABLE REQUIRES_MAIN_TARGET)
2227
set(ONE_VALUE_ARGS TARGET_NAME TEST_NAME FULL_TEST_NAME_OUT_VAR FULL_TEST_TARGET_OUT_VAR)
2328
set(MULTI_VALUE_ARGS HEADER_FILES SRC_FILES LIBRARIES RUN_ARGS)
2429
cmake_parse_arguments(ARGS "${OPTIONAL_ARGS}" "${ONE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGN})
@@ -89,6 +94,14 @@ function (configure_test_target)
8994
"${FULL_TEST_NAME}"
9095
PARENT_SCOPE)
9196
add_test(NAME "${FULL_TEST_NAME}" COMMAND "${TEST_TARGET_NAME}" ${ARGS_RUN_ARGS})
97+
set(TEST_${ARGS_TEST_NAME}_DISABLED
98+
""
99+
CACHE STRING "value for the DISABLED property of test ${ARGS_TEST_NAME}")
100+
if (NOT "${TEST_${ARGS_TEST_NAME}_DISABLED}" STREQUAL "")
101+
set_property(TEST "${FULL_TEST_NAME}" PROPERTY DISABLED "${TEST_${ARGS_TEST_NAME}_DISABLED}")
102+
elseif (ARGS_UNSTABLE AND DISABLE_UNSTABLE_TESTS)
103+
set_property(TEST "${FULL_TEST_NAME}" PROPERTY DISABLED True)
104+
endif ()
92105
endif ()
93106

94107
# add the test executable to the dependencies of the check target

0 commit comments

Comments
 (0)