Handle TESTDATA for Qt Tests
These changes enable the support to handle test data and install or package them as resources when appropriate. This change does not handle the GENERATED_TESTDATA or TEST_HELPER_INSTALLS since there are very few occurrences of these and we can handle those as special cases. Finally, in add_qt_test, only append CMAKE_CURRENT_SOURCE_DIR if the path is not absolute. Change-Id: Ic20b9749d10e2a09916f2797606116471c64850b Reviewed-by: Qt CMake Build Bot Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>bb10
parent
30b3746370
commit
ec1546afc4
|
|
@ -1818,7 +1818,9 @@ endfunction()
|
|||
|
||||
# This function creates a CMake test target with the specified name for use with CTest.
|
||||
function(add_qt_test name)
|
||||
qt_parse_all_arguments(arg "add_qt_test" "RUN_SERIAL;EXCEPTIONS" "" "${__default_private_args}" ${ARGN})
|
||||
qt_parse_all_arguments(arg "add_qt_test"
|
||||
"RUN_SERIAL;EXCEPTIONS"
|
||||
"" "TESTDATA;${__default_private_args}" ${ARGN})
|
||||
set(path "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
if (${arg_EXCEPTIONS})
|
||||
|
|
@ -1857,6 +1859,47 @@ function(add_qt_test name)
|
|||
set_tests_properties("${name}" PROPERTIES RUN_SERIAL "${arg_RUN_SERIAL}" LABELS "${label}")
|
||||
set_property(TEST "${name}" APPEND PROPERTY ENVIRONMENT "PATH=${path}${QT_PATH_SEPARATOR}${CMAKE_CURRENT_BINARY_DIR}${QT_PATH_SEPARATOR}$ENV{PATH}")
|
||||
set_property(TEST "${name}" APPEND PROPERTY ENVIRONMENT "QT_PLUGIN_PATH=${PROJECT_BINARY_DIR}/${INSTALL_PLUGINSDIR}")
|
||||
|
||||
|
||||
if(ANDROID OR IOS OR WINRT)
|
||||
set(builtin_testdata TRUE)
|
||||
endif()
|
||||
|
||||
if(builtin_testdata)
|
||||
target_compile_definitions("${name}" PRIVATE BUILTIN_TESTDATA)
|
||||
|
||||
foreach(testdata IN LISTS arg_TESTDATA)
|
||||
list(APPEND builtin_files ${testdata})
|
||||
endforeach()
|
||||
|
||||
set(blacklist_path "BLACKLIST")
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${blacklist_path}")
|
||||
list(APPEND builtin_files ${blacklist_path})
|
||||
endif()
|
||||
|
||||
list(REMOVE_DUPLICATES builtin_files)
|
||||
|
||||
if (builtin_files)
|
||||
add_qt_resource(${name} "testdata"
|
||||
FILES ${builtin_files}
|
||||
BASE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
endif()
|
||||
else()
|
||||
# Install test data
|
||||
foreach(testdata IN LISTS arg_TESTDATA)
|
||||
set(testdata "${CMAKE_CURRENT_SOURCE_DIR}/${testdata}")
|
||||
if (IS_DIRECTORY "${testdata}")
|
||||
qt_copy_or_install(
|
||||
DIRECTORY "${testdata}"
|
||||
DESTINATION "${INSTALL_TESTSDIR}/${name}")
|
||||
else()
|
||||
qt_copy_or_install(
|
||||
FILES "${testdata}"
|
||||
DESTINATION "${INSTALL_TESTSDIR}/${name}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
|
||||
|
||||
|
|
@ -2044,11 +2087,16 @@ function(add_qt_resource target resourceName)
|
|||
if (NOT alias)
|
||||
set(alias "${file}")
|
||||
endif()
|
||||
|
||||
if (NOT IS_ABSOLUTE ${based_file})
|
||||
set(based_file "${CMAKE_CURRENT_SOURCE_DIR}/${based_file}")
|
||||
endif()
|
||||
|
||||
### FIXME: escape file paths to be XML conform
|
||||
# <file ...>...</file>
|
||||
string(APPEND qrcContents " <file alias=\"${alias}\">")
|
||||
string(APPEND qrcContents "${CMAKE_CURRENT_SOURCE_DIR}/${based_file}</file>\n")
|
||||
list(APPEND files "${CMAKE_CURRENT_SOURCE_DIR}/${based_file}")
|
||||
string(APPEND qrcContents "${based_file}</file>\n")
|
||||
list(APPEND files "${based_file}")
|
||||
endforeach()
|
||||
|
||||
# </qresource></RCC>
|
||||
|
|
|
|||
|
|
@ -1590,12 +1590,32 @@ def write_main_part(cm_fh: typing.IO[str], name: str, typename: str,
|
|||
# Now write out the scopes:
|
||||
write_header(cm_fh, name, typename, indent=indent)
|
||||
|
||||
# collect all testdata and insert globbing commands
|
||||
has_test_data = False
|
||||
if typename == 'Test':
|
||||
test_data = scope.expand('TESTDATA')
|
||||
if test_data:
|
||||
has_test_data = True
|
||||
cm_fh.write('# Collect test data\n')
|
||||
for data in test_data:
|
||||
if data.endswith('*'):
|
||||
cm_fh.write('{}file(GLOB test_data_glob \n{}LIST_DIRECTORIES'
|
||||
' true\n{}RELATIVE ${{CMAKE_CURRENT_SOURCE_DIR}}\n{}"{}")\n'\
|
||||
.format(spaces(indent), spaces(indent + 1), \
|
||||
spaces(indent + 1), spaces(indent + 1), data))
|
||||
cm_fh.write('{}list(APPEND test_data ${{test_data_glob}})\n'.format(spaces(indent)))
|
||||
else:
|
||||
cm_fh.write('{}list(APPEND test_data "{}")\n'.format(spaces(indent), data))
|
||||
cm_fh.write('\n')
|
||||
|
||||
cm_fh.write('{}{}({}\n'.format(spaces(indent), cmake_function, name))
|
||||
for extra_line in extra_lines:
|
||||
cm_fh.write('{} {}\n'.format(spaces(indent), extra_line))
|
||||
|
||||
write_sources_section(cm_fh, scopes[0], indent=indent, **kwargs)
|
||||
|
||||
if has_test_data:
|
||||
cm_fh.write('{} TESTDATA ${{test_data}}\n'.format(spaces(indent)))
|
||||
# Footer:
|
||||
cm_fh.write('{})\n'.format(spaces(indent)))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue