#[==[.md # `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]: TODO #]==] include(ExternalData) get_filename_component(_vtkModuleTesting_dir "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY) #[==[.md ## Loading data Data may be downloaded manually using this function: ~~~ 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][ExternalData pathspecs] in `ExternalData`. These arguments are already wrapped in the `DATA{}` syntax and are assumed to be relative paths from the input data directory. [ExternalData pathspecs]: TODO #]==] 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 () #[==[.md ## Creating test executables 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. ~~~ 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}" ${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) if (TARGET "${test_optional_depend}") list(APPEND test_depends "${test_optional_depend}") set(test_optional_depend_flag "1") else () set(test_optional_depend_flag "0") endif () string(REPLACE "::" "_" safe_test_optional_depend "${test_optional_depend}") list(APPEND optional_depends_flags "VTK_MODULE_ENABLE_${safe_test_optional_depend}=${test_optional_depend_flag}") endforeach () target_link_libraries("${name}" PRIVATE "${_vtk_build_test}" ${test_depends}) target_compile_definitions("${name}" PRIVATE ${optional_depends_flags}) vtk_module_autoinit( TARGETS "${name}" MODULES "${_vtk_build_test}" ${test_depends}) endfunction () #[==[.md ## 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 `-`. #]==] #[==[.md INTERNAL This function parses the name from a testspec. The calling scope has `test_name` and `test_file` variables set in it. ~~~ _vtk_test_parse_name() ~~~ #]==] function (_vtk_test_parse_name name) if (name AND name MATCHES "^([^,]*),(.*)$") set(test_name "${CMAKE_MATCH_1}" PARENT_SCOPE) set(test_file "${CMAKE_MATCH_2}" PARENT_SCOPE) else () set(test_name "${name}" PARENT_SCOPE) set(test_file "${name}" PARENT_SCOPE) endif () endfunction () #[==[.md ## 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. #]==] #[==[.md 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. ~~~ _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 () #[==[.md INTERNAL For handling global option settings, this function sets variables in the calling scoped named `