Extend add_qt_test to support qmltestcase
Extend add_qt_test for qmltest by setting the option QMLTEST when we detect the config qmltestcase. We also forwards the GUI option to the tests when detected. This is a requirement for some QtQuickControls2 tests. Finally when doing a prefix build, we add the install directory to the QT_PLUGIN_PATH environment variable. Change-Id: I3b2ecb494955976e98abbcf3d03925c314336122 Reviewed-by: Qt CMake Build Bot Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
parent
1072a8f579
commit
2cc865b943
@ -1943,16 +1943,21 @@ 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"
|
||||
"" "TESTDATA;${__default_private_args}" ${ARGN})
|
||||
"RUN_SERIAL;EXCEPTIONS;GUI;QMLTEST"
|
||||
"QML_IMPORTPATH" "TESTDATA;${__default_private_args}" ${ARGN})
|
||||
set(path "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
if (${arg_EXCEPTIONS})
|
||||
set(EXCEPTIONS_TEXT "EXCEPTIONS")
|
||||
set(exceptions_text "EXCEPTIONS")
|
||||
endif()
|
||||
|
||||
if (${arg_GUI})
|
||||
set(gui_text "GUI")
|
||||
endif()
|
||||
|
||||
add_qt_executable("${name}"
|
||||
${EXCEPTIONS_TEXT}
|
||||
${exceptions_text}
|
||||
${gui_text}
|
||||
NO_INSTALL
|
||||
OUTPUT_DIRECTORY "${path}"
|
||||
SOURCES "${arg_SOURCES}"
|
||||
@ -1974,16 +1979,49 @@ function(add_qt_test name)
|
||||
DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS}
|
||||
)
|
||||
|
||||
# QMLTest specifics
|
||||
|
||||
extend_target("${name}" CONDITION arg_QMLTEST
|
||||
PUBLIC_LIBRARIES ${QT_CMAKE_EXPORT_NAMESPACE}::QuickTest
|
||||
)
|
||||
|
||||
extend_target("${name}" CONDITION arg_QMLTEST AND NOT ANDROID
|
||||
DEFINES
|
||||
QUICK_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
)
|
||||
|
||||
extend_target("${name}" CONDITION arg_QMLTEST AND ANDROID
|
||||
DEFINES
|
||||
QUICK_TEST_SOURCE_DIR=":/"
|
||||
)
|
||||
|
||||
if (arg_QML_IMPORTPATH)
|
||||
set(extra_test_args "-import" "${arg_QML_IMPORTPATH}")
|
||||
endif()
|
||||
|
||||
# Generate a label in the form tests/auto/foo/bar/tst_baz
|
||||
# and use it also for XML output
|
||||
file(RELATIVE_PATH label "${PROJECT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
|
||||
|
||||
add_test(NAME "${name}" COMMAND "${name}" -o ${name}.xml,xml -o -,txt WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
if(arg_QMLTEST AND NOT arg_SOURCES)
|
||||
set(test_executable ${QT_CMAKE_EXPORT_NAMESPACE}::qmltestrunner "$<TARGET_FILE:${name}>")
|
||||
else()
|
||||
set(test_executable "${name}")
|
||||
endif()
|
||||
|
||||
add_test(NAME "${name}" COMMAND ${test_executable} ${extra_test_args} -o ${name}.xml,xml -o -,txt WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
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}")
|
||||
|
||||
# Add the install prefix to list of plugin paths when doing a prefix build
|
||||
if(NOT QT_INSTALL_DIR)
|
||||
list(APPEND plugin_paths "${CMAKE_INSTALL_PREFIX}/${INSTALL_PLUGINSDIR}")
|
||||
endif()
|
||||
#TODO: Collect all paths from known repositories when performing a super
|
||||
# build.
|
||||
list(APPEND plugin_paths "${PROJECT_BINARY_DIR}/${INSTALL_PLUGINSDIR}")
|
||||
list(JOIN plugin_paths "${QT_PATH_SEPARATOR}" plugin_paths_joined)
|
||||
set_property(TEST "${name}" APPEND PROPERTY ENVIRONMENT "QT_PLUGIN_PATH=${plugin_paths_joined}")
|
||||
|
||||
if(ANDROID OR IOS OR WINRT)
|
||||
set(builtin_testdata TRUE)
|
||||
|
@ -1698,14 +1698,26 @@ def write_tool(cm_fh: typing.IO[str], scope: Scope, *,
|
||||
extra_lines=extra, extra_keys=['CONFIG'])
|
||||
|
||||
|
||||
def write_test(cm_fh: typing.IO[str], scope: Scope, *,
|
||||
indent: int = 0) -> None:
|
||||
def write_test(cm_fh: typing.IO[str], scope: Scope,
|
||||
gui: bool = False, *, indent: int = 0) -> None:
|
||||
test_name = scope.TARGET
|
||||
assert test_name
|
||||
|
||||
extra = ['GUI',] if gui else []
|
||||
libraries={'Qt::Core', 'Qt::Test'}
|
||||
|
||||
if 'qmltestcase' in scope.get('CONFIG'):
|
||||
libraries.add('Qt::QmlTest')
|
||||
extra.append('QMLTEST')
|
||||
importpath = scope.get('IMPORTPATH')
|
||||
if importpath:
|
||||
qml_importpath = scope.expandString(importpath)
|
||||
if qml_importpath:
|
||||
extra.append('QML_IMPORTPATH "{}"'.format(qml_importpath))
|
||||
|
||||
write_main_part(cm_fh, test_name, 'Test', 'add_qt_test', scope,
|
||||
indent=indent, known_libraries={'Qt::Core', 'Qt::Test',},
|
||||
extra_keys=[])
|
||||
indent=indent, known_libraries=libraries,
|
||||
extra_lines=extra, extra_keys=[])
|
||||
|
||||
|
||||
def write_binary(cm_fh: typing.IO[str], scope: Scope,
|
||||
@ -1713,7 +1725,7 @@ def write_binary(cm_fh: typing.IO[str], scope: Scope,
|
||||
binary_name = scope.TARGET
|
||||
assert binary_name
|
||||
|
||||
extra = ['GUI',] if gui else[]
|
||||
extra = ['GUI',] if gui else []
|
||||
|
||||
target_path = scope.get_string('target.path')
|
||||
if target_path:
|
||||
@ -1857,13 +1869,14 @@ def handle_app_or_lib(scope: Scope, cm_fh: typing.IO[str], *,
|
||||
assert not is_example
|
||||
write_tool(cm_fh, scope, indent=indent)
|
||||
else:
|
||||
if 'testcase' in scope.get('CONFIG') \
|
||||
or 'testlib' in scope.get('CONFIG'):
|
||||
config = scope.get('CONFIG')
|
||||
gui = all(val not in config for val in ['console', 'cmdline'])
|
||||
if 'testcase' in config \
|
||||
or 'testlib' in config \
|
||||
or 'qmltestcase' in config:
|
||||
assert not is_example
|
||||
write_test(cm_fh, scope, indent=indent)
|
||||
write_test(cm_fh, scope, gui, indent=indent)
|
||||
else:
|
||||
config = scope.get('CONFIG')
|
||||
gui = all(val not in config for val in ['console', 'cmdline'])
|
||||
if is_example:
|
||||
write_example(cm_fh, scope, gui, indent=indent)
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user