Add QT_TEST_RUNNING_IN_CTEST environment variable for test

When running tests with CMake's CTest, set the environment
QT_TEST_RUNNING_IN_CTEST to 1. This can be useful to deal with tests
that do not properly work when running from CTest.

For instance, the qmake test in this patch has one test that only works
when not run from CTest.

Change-Id: I01eea9131de69c18118a9ed9f96e9296d5ea20f1
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
bb10
Leander Beernaert 2020-01-13 13:56:04 +01:00
parent ba96b0cbd9
commit 3854b5892b
2 changed files with 4 additions and 1 deletions

View File

@ -2892,10 +2892,10 @@ function(qt_add_test name)
if (arg_TIMEOUT)
set_tests_properties(${name} PROPERTIES TIMEOUT ${arg_TIMEOUT})
endif()
# Get path to qtbase/bin, then prepend this path containing the shared libraries to PATH
set(INSTALL_PREFIX_BIN "${CMAKE_INSTALL_PREFIX}/bin")
set_property(TEST "${name}" APPEND PROPERTY ENVIRONMENT "PATH=${CMAKE_CURRENT_BINARY_DIR}${QT_PATH_SEPARATOR}${INSTALL_PREFIX_BIN}${QT_PATH_SEPARATOR}$ENV{PATH}")
set_property(TEST "${name}" APPEND PROPERTY ENVIRONMENT "QT_TEST_RUNNING_IN_CTEST=1")
# Add the install prefix to list of plugin paths when doing a prefix build
if(NOT QT_INSTALL_DIR)

View File

@ -318,6 +318,9 @@ void tst_qmake::subdirs()
void tst_qmake::subdir_via_pro_file_extra_target()
{
if (QProcessEnvironment::systemEnvironment().contains(QStringLiteral("QT_TEST_RUNNING_IN_CTEST")))
QSKIP("This test does not run properly when invoked from CTest.");
QString workDir = base_path + "/testdata/subdir_via_pro_file_extra_target";
QDir D;