diff options
author | Richard Weickelt <richard@weickelt.de> | 2020-02-16 14:33:11 +0100 |
---|---|---|
committer | Richard Weickelt <richard@weickelt.de> | 2020-02-27 09:48:20 +0000 |
commit | a3a89138cf8924c1236d9d288e9ab3cdc37ef8c7 (patch) | |
tree | c61d46f781a5d414ce410af8eaf4e80fe1ffc296 /tests | |
parent | e5f115d256361359917614b34886e09d04c766f0 (diff) |
Introduce QBS_TEST_SOURCE_ROOT environment variable
This patch introduces QBS_TEST_SOURCE_ROOT environment variable that can be used
to customize the source location of test data. Previously, the original testdata
location was compiled into the test binaries. Thus it was impossible to run the
test suites on a different host than the build host.
In order to improve test coverage, we want to build the test suites once (for
instance in a Docker environment) and then run them multiple times in different
environments which might have a different file layout. In that case, the
testdata location must be configurable.
Change-Id: I7673826e6ea6f2e3aa893e657351a84c49a1033e
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/api/tst_api.cpp | 2 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackboxbase.cpp | 2 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackboxqt.cpp | 2 | ||||
-rw-r--r-- | tests/auto/language/tst_language.cpp | 7 | ||||
-rw-r--r-- | tests/auto/shared.h | 26 |
5 files changed, 32 insertions, 7 deletions
diff --git a/tests/auto/api/tst_api.cpp b/tests/auto/api/tst_api.cpp index 3c3666489..bc9ed4f0d 100644 --- a/tests/auto/api/tst_api.cpp +++ b/tests/auto/api/tst_api.cpp @@ -144,7 +144,7 @@ static bool waitForFinished(qbs::AbstractJob *job, int timeout = 0) TestApi::TestApi() : m_logSink(new LogSink) - , m_sourceDataDir(QDir::cleanPath(SRCDIR "/testdata")) + , m_sourceDataDir(testDataSourceDir(SRCDIR "/testdata")) , m_workingDataDir(testWorkDir(QStringLiteral("api"))) { } diff --git a/tests/auto/blackbox/tst_blackboxbase.cpp b/tests/auto/blackbox/tst_blackboxbase.cpp index 4550edcac..90afaabfc 100644 --- a/tests/auto/blackbox/tst_blackboxbase.cpp +++ b/tests/auto/blackbox/tst_blackboxbase.cpp @@ -64,7 +64,7 @@ static bool supportsSettingsDirOption(const QString &command) { TestBlackboxBase::TestBlackboxBase(const QString &testDataSrcDir, const QString &testName) : testDataDir(testWorkDir(testName)), - testSourceDir(QDir::cleanPath(testDataSrcDir)), + testSourceDir(testDataSourceDir(testDataSrcDir)), qbsExecutableFilePath(initQbsExecutableFilePath()), defaultInstallRoot(relativeBuildDir() + QLatin1Char('/') + InstallOptions::defaultInstallRoot()) { diff --git a/tests/auto/blackbox/tst_blackboxqt.cpp b/tests/auto/blackbox/tst_blackboxqt.cpp index 474fb95f3..132408820 100644 --- a/tests/auto/blackbox/tst_blackboxqt.cpp +++ b/tests/auto/blackbox/tst_blackboxqt.cpp @@ -118,7 +118,7 @@ void TestBlackboxQt::combinedMoc() void TestBlackboxQt::createProject() { QDir::setCurrent(testDataDir + "/create-project"); - QVERIFY(QFile::copy(SRCDIR "/../../../examples/helloworld-qt/main.cpp", + QVERIFY(QFile::copy(testSourceDir + "/../../../../examples/helloworld-qt/main.cpp", QDir::currentPath() + "/main.cpp")); QbsRunParameters createParams("create-project"); createParams.profile.clear(); diff --git a/tests/auto/language/tst_language.cpp b/tests/auto/language/tst_language.cpp index cc87fb750..25e549d18 100644 --- a/tests/auto/language/tst_language.cpp +++ b/tests/auto/language/tst_language.cpp @@ -79,8 +79,7 @@ using namespace qbs; using namespace qbs::Internal; static QString testDataDir() { - return FileInfo::resolvePath(QStringLiteral(SRCDIR), - QStringLiteral("../../../tests/auto/language/testdata")); + return testDataSourceDir(SRCDIR "/testdata"); } static QString testProject(const char *fileName) { return testDataDir() + QLatin1Char('/') + QLatin1String(fileName); @@ -180,7 +179,7 @@ void TestLanguage::initTestCase() m_engine = ScriptEngine::create(m_logger, EvalContext::PropertyEvaluation, this); loader = new Loader(m_engine, m_logger); loader->setSearchPaths(QStringList() - << QStringLiteral(SRCDIR "/../../../share/qbs")); + << (testDataDir() + "/../../../../share/qbs")); defaultParameters.setTopLevelProfile(profileName()); defaultParameters.setConfigurationName("default"); defaultParameters.expandBuildConfiguration(); @@ -2480,7 +2479,7 @@ void TestLanguage::projectFileLookup_data() QTest::addColumn<QString>("projectFileOutput"); QTest::addColumn<bool>("failureExpected"); - const QString baseDir = QLatin1String(SRCDIR) + "/testdata"; + const QString baseDir = testDataDir(); const QString multiProjectsDir = baseDir + "/dirwithmultipleprojects"; const QString noProjectsDir = baseDir + "/dirwithnoprojects"; const QString oneProjectDir = baseDir + "/dirwithoneproject"; diff --git a/tests/auto/shared.h b/tests/auto/shared.h index e251d506c..ac950f12a 100644 --- a/tests/auto/shared.h +++ b/tests/auto/shared.h @@ -46,6 +46,8 @@ #include <memory> + + #define REPLACE_IN_FILE(filePath, oldContent, newContent) \ do { \ QFile f((filePath)); \ @@ -285,6 +287,30 @@ inline QString inputDirHash(const QString &dir) return QCryptographicHash::hash(dir.toLatin1(), QCryptographicHash::Sha1).toHex().left(16); } +inline QString testDataSourceDir(const QString &dir) +{ + QDir result; + QString testSourceRootDirFromEnv = QDir::fromNativeSeparators(qEnvironmentVariable("QBS_TEST_SOURCE_ROOT")); + if (testSourceRootDirFromEnv.isEmpty()) { + result.setPath(dir); + } else { + QDir testSourceRootDir(dir); + while (testSourceRootDir.dirName() != "tests") + testSourceRootDir = QFileInfo(testSourceRootDir, "").dir(); + + QString relativeDataPath = testSourceRootDir.relativeFilePath(dir); + QString absoluteDataPath = QDir(testSourceRootDirFromEnv).absoluteFilePath(relativeDataPath); + result.setPath(absoluteDataPath); + } + + if (!result.exists()) + qFatal("Expected data folder '%s' to be present, but it does not exist. You may set " + "QBS_TEST_SOURCE_ROOT to the 'tests' folder in your qbs repository to configure " + "a custom location.", qPrintable(result.absolutePath())); + + return result.absolutePath(); +} + inline QString testWorkDir(const QString &testName) { QString dir = QDir::fromNativeSeparators(QString::fromLocal8Bit(qgetenv("QBS_TEST_WORK_ROOT"))); |