#[==[.rst: vtkModuleTesting ---------------- VTK uses the ExternalData_ CMake module to handle the data management for its test suite. Test data is only downloaded when a test which requires it is enabled and it is cached so that every build does not need to redownload the same data. To facilitate this workflow, there are a number of CMake functions available in order to indicate that test data is required. .. _ExternalData: https://cmake.org/cmake/help/latest/module/ExternalData.html #]==] include(ExternalData) get_filename_component(_vtkModuleTesting_dir "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY) if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") add_test( NAME HTTPServerStart COMMAND "${CMAKE_CROSSCOMPILING_EMULATOR}" "${_vtkModuleTesting_dir}/wasm/server.js" "--directory" "${CMAKE_BINARY_DIR}/Testing/Temporary" "--port" "0" "--operation" "start") set_tests_properties(HTTPServerStart PROPERTIES FIXTURES_SETUP "HTTP") add_test( NAME HTTPServerStop COMMAND "${CMAKE_CROSSCOMPILING_EMULATOR}" "${_vtkModuleTesting_dir}/wasm/server.js" "--directory" "${CMAKE_BINARY_DIR}/Testing/Temporary" "--port" "0" "--operation" "stop") set_tests_properties(HTTPServerStop PROPERTIES FIXTURES_CLEANUP "HTTP") endif () #[==[.rst: Loading data ^^^^^^^^^^^^ .. cmake:command:: vtk_module_test_data Download test data. |module| Data may be downloaded manually using this function: .. code-block:: cmake vtk_module_test_data(...) This will download data inside of the input data directory for the modules being built at that time (see the ``TEST_INPUT_DATA_DIRECTORY`` argument of ``vtk_module_build``). For supported `PATHSPEC` syntax, see the associated documentation in ref:`ExternalData`. These arguments are already wrapped in the ``DATA{}`` syntax and are assumed to be relative paths from the input data directory. #]==] function (vtk_module_test_data) set(data_args) foreach (arg IN LISTS ARGN) if (IS_ABSOLUTE "${arg}") list(APPEND data_args "DATA{${arg}}") else () list(APPEND data_args "DATA{${_vtk_build_TEST_INPUT_DATA_DIRECTORY}/${arg}}") endif () endforeach () ExternalData_Expand_Arguments("${_vtk_build_TEST_DATA_TARGET}" _ ${data_args}) endfunction () # Opt-in option from projects using VTK to activate SSIM baseline comparison if (DEFINED DEFAULT_USE_SSIM_IMAGE_COMP AND DEFAULT_USE_SSIM_IMAGE_COMP) set(default_image_compare "VTK_TESTING_IMAGE_COMPARE_METHOD=TIGHT_VALID") # We are compiling VTK standalone if we succeed the following condition elseif (DEFINED VTK_VERSION) set(default_image_compare "VTK_TESTING_IMAGE_COMPARE_METHOD=TIGHT_VALID") else() set(default_image_compare "VTK_TESTING_IMAGE_COMPARE_METHOD=LEGACY_VALID") endif() #[==[.rst: Creating test executables ^^^^^^^^^^^^^^^^^^^^^^^^^ .. cmake:command:: vtk_module_test_executable This function creates an executable from the list of sources passed to it. It is automatically linked to the module the tests are intended for as well as any declared test dependencies of the module. .. code-block:: cmake vtk_module_test_executable( ...) This function is not usually used directly, but instead through the other convenience functions. #]==] function (vtk_module_test_executable name) add_executable("${name}") target_sources("${name}" PRIVATE ${ARGN}) get_property(test_depends GLOBAL PROPERTY "_vtk_module_${_vtk_build_test}_test_depends") get_property(test_optional_depends GLOBAL PROPERTY "_vtk_module_${_vtk_build_test}_test_optional_depends") set(optional_depends_flags) foreach (test_optional_depend IN LISTS test_optional_depends) _vtk_module_optional_dependency_exists("${test_optional_depend}" SATISFIED_VAR test_optional_depend_exists) if (test_optional_depend_exists) list(APPEND test_depends "${test_optional_depend}") endif () string(REPLACE "::" "_" safe_test_optional_depend "${test_optional_depend}") list(APPEND optional_depends_flags "VTK_MODULE_ENABLE_${safe_test_optional_depend}=$") endforeach () if (_vtk_build_UTILITY_TARGET) target_link_libraries("${name}" PRIVATE "${_vtk_build_UTILITY_TARGET}") endif () target_link_libraries("${name}" PRIVATE "${_vtk_build_test}" ${test_depends}) if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") target_link_libraries("${name}" PRIVATE VTK::vtkWebAssemblyTestLinkOptions) endif () target_compile_definitions("${name}" PRIVATE ${optional_depends_flags}) vtk_module_autoinit( TARGETS "${name}" MODULES "${_vtk_build_test}" ${test_depends}) endfunction () #[==[.rst: Test name parsing ^^^^^^^^^^^^^^^^^ Test names default to using the basename of the filename which contains the test. Two tests may share the same file by prefixing with a custom name for the test and a comma. The two parsed syntaxes are: - ``CustomTestName,TestFile`` - ``TestFile`` Note that ``TestFile`` should already have had its extension stripped (usually done by ``_vtk_test_parse_args``). In general, the name of a test will be ``-``, however, by setting ``vtk_test_prefix``, the test name will instead be ``-``. #]==] #[==[.rst : .. cmake:command:: _vtk_test_parse_name This function parses the name from a testspec.|module-internal| The calling scope has `test_name`, `test_arg`, and `test_file` variables set in it. .. code-block:: cmake _vtk_test_parse_name() #]==] function (_vtk_test_parse_name name ext) if (name AND name MATCHES "^([^,]*),(.*)$") set(test_name "${CMAKE_MATCH_1}") set(test_file "${CMAKE_MATCH_2}") else () # Strip the extension from the test name. string(REPLACE ".${ext}" "" test_name "${name}") set(test_name "${test_name}") set(test_file "${name}") endif () string(REPLACE ".${ext}" "" test_arg "${test_file}") set(test_name "${test_name}" PARENT_SCOPE) set(test_file "${test_file}" PARENT_SCOPE) set(test_arg "${test_arg}" PARENT_SCOPE) endfunction () #[==[.rst: Test function arguments ^^^^^^^^^^^^^^^^^^^^^^^ Each test is specified using one of the two following syntaxes - ``.`` - ``.,`` Where ``NAME`` is a valid test name. If present, the specified ``OPTIONS`` are only for the associated test. The expected extension is specified by the associated test function. #]==] #[==[.rst: .. cmake:command:: _vtk_test_parse_args |module-internal| Given a list of valid "options", this function will parse out a the following variables: - ``args``: Unrecognized arguments. These should be interpreted as arguments that should be passed on the command line to all tests in this parse group. - ``options``: Options specified globally (for all tests in this group). - ``names``: A list containing all named tests. These should be parsed by ``_vtk_test_parse_name``. - ``__options``: Options specific to a certain test. .. code-block:: cmake _vtk_test_parse_args( ...) In order to be recognized as a source file, the ``SOURCE_EXT`` must be used. Without it, all non-option arguments are placed into ``args``. Each test is parsed out matching these: #]==] function (_vtk_test_parse_args options source_ext) set(global_options) set(names) set(args) foreach (arg IN LISTS ARGN) set(handled 0) foreach (option IN LISTS options) if (arg STREQUAL option) list(APPEND global_options "${option}") set(handled 1) break () endif () endforeach () if (handled) # Do nothing. elseif (source_ext AND arg MATCHES "^([^.]*\\.${source_ext}),?(.*)$") set(name "${CMAKE_MATCH_1}") string(REPLACE "," ";" "_${name}_options" "${CMAKE_MATCH_2}") list(APPEND names "${name}") else () list(APPEND args "${arg}") endif () endforeach () foreach (name IN LISTS names) set("_${name}_options" "${_${name}_options}" PARENT_SCOPE) endforeach () set(options "${global_options}" PARENT_SCOPE) set(names "${names}" PARENT_SCOPE) set(args "${args}" PARENT_SCOPE) endfunction () #[==[.rst: .. cmake:command:: _vtk_test_set_options For handling global option settings |module-internal|, this function sets variables in the calling scoped named `