From 2abd969ef6f5841526c48da2e54fe47a001e8d69 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 12 Mar 2019 09:03:13 +0100 Subject: tst_qmake: Keep the source dir clean Copy the test data into a temporary directory and do all the work there without tainting the source directory. More importantly, do not pull in any settings from the Qt build to test what actual users will encounter. Change-Id: I793b86bfadb7597efb47c8f2d3fc863384c78a79 Reviewed-by: Oliver Wolff --- tests/auto/tools/qmake/testcompiler.cpp | 4 +- tests/auto/tools/qmake/testcompiler.h | 3 +- .../testdata/subdirs/simple_dll/simple_dll.pro | 1 - tests/auto/tools/qmake/tst_qmake.cpp | 86 ++++++++++++++++++---- 4 files changed, 75 insertions(+), 19 deletions(-) diff --git a/tests/auto/tools/qmake/testcompiler.cpp b/tests/auto/tools/qmake/testcompiler.cpp index da76b3f2ca..3276d97354 100644 --- a/tests/auto/tools/qmake/testcompiler.cpp +++ b/tests/auto/tools/qmake/testcompiler.cpp @@ -67,7 +67,9 @@ static QString targetName( BuildType buildMode, const QString& target, const QSt break; case Dll: // dll targetName.prepend("lib"); - targetName.append("." + version + ".dylib"); + if (!version.isEmpty()) + targetName.append('.' + version); + targetName.append(".dylib"); break; case Lib: // lib targetName.prepend("lib"); diff --git a/tests/auto/tools/qmake/testcompiler.h b/tests/auto/tools/qmake/testcompiler.h index a46c9b6b6a..d3fe6d88f8 100644 --- a/tests/auto/tools/qmake/testcompiler.h +++ b/tests/auto/tools/qmake/testcompiler.h @@ -60,7 +60,8 @@ public: // executes a make in the specified workPath, with an optional target (eg. install) bool make( const QString &workPath, const QString &target = QString(), bool expectFail = false ); // checks if the executable exists in destDir - bool exists( const QString &destDir, const QString &exeName, BuildType buildType, const QString &version ); + bool exists(const QString &destDir, const QString &exeName, BuildType buildType, + const QString &version = QString()); // removes the makefile bool removeMakefile( const QString &workPath ); // removes the project file specified by 'project' on the 'workPath' diff --git a/tests/auto/tools/qmake/testdata/subdirs/simple_dll/simple_dll.pro b/tests/auto/tools/qmake/testdata/subdirs/simple_dll/simple_dll.pro index 4e362bb918..d13f49bb89 100644 --- a/tests/auto/tools/qmake/testdata/subdirs/simple_dll/simple_dll.pro +++ b/tests/auto/tools/qmake/testdata/subdirs/simple_dll/simple_dll.pro @@ -6,7 +6,6 @@ DEFINES += SIMPLEDLL_MAKEDLL HEADERS = simple.h SOURCES = simple.cpp -VERSION = 1.0.0 INCLUDEPATH += . tmp MOC_DIR = tmp OBJECTS_DIR = tmp diff --git a/tests/auto/tools/qmake/tst_qmake.cpp b/tests/auto/tools/qmake/tst_qmake.cpp index 10aabcf196..2b822e682f 100644 --- a/tests/auto/tools/qmake/tst_qmake.cpp +++ b/tests/auto/tools/qmake/tst_qmake.cpp @@ -30,9 +30,11 @@ #include "testcompiler.h" +#include +#include #include #include -#include +#include #if defined(DEBUG_BUILD) # define DIR_INFIX "debug/" @@ -46,8 +48,12 @@ class tst_qmake : public QObject { Q_OBJECT +public: + tst_qmake(); + private slots: void initTestCase(); + void cleanupTestCase(); void cleanup(); void simple_app(); void simple_app_shadowbuild(); @@ -78,11 +84,41 @@ private slots: private: TestCompiler test_compiler; + QTemporaryDir tempWorkDir; QString base_path; + const QString origCurrentDirPath; }; +tst_qmake::tst_qmake() + : tempWorkDir(QDir::tempPath() + "/tst_qmake"), + origCurrentDirPath(QDir::currentPath()) +{ +} + +static void copyDir(const QString &sourceDirPath, const QString &targetDirPath) +{ + QDir currentDir; + QDirIterator dit(sourceDirPath, QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden); + while (dit.hasNext()) { + dit.next(); + const QString targetPath = targetDirPath + QLatin1Char('/') + dit.fileName(); + currentDir.mkpath(targetPath); + copyDir(dit.filePath(), targetPath); + } + + QDirIterator fit(sourceDirPath, QDir::Files | QDir::Hidden); + while (fit.hasNext()) { + fit.next(); + const QString targetPath = targetDirPath + QLatin1Char('/') + fit.fileName(); + QFile::remove(targetPath); // allowed to fail + QFile src(fit.filePath()); + QVERIFY2(src.copy(targetPath), qPrintable(src.errorString())); + } +} + void tst_qmake::initTestCase() { + QVERIFY2(tempWorkDir.isValid(), qPrintable(tempWorkDir.errorString())); QString binpath = QLibraryInfo::location(QLibraryInfo::BinariesPath); QString cmd = QString("%1/qmake").arg(binpath); #ifdef Q_CC_MSVC @@ -99,13 +135,31 @@ void tst_qmake::initTestCase() #else test_compiler.setBaseCommands( "make", cmd ); #endif - //Detect the location of the testdata - QString subProgram = QLatin1String("testdata/simple_app/main.cpp"); - base_path = QFINDTESTDATA(subProgram); - if (base_path.lastIndexOf(subProgram) > 0) - base_path = base_path.left(base_path.lastIndexOf(subProgram)); - else - base_path = QCoreApplication::applicationDirPath(); + const QString testDataSubDir = QStringLiteral("testdata"); + const QString subProgram = testDataSubDir + QLatin1String("/simple_app/main.cpp"); + QString testDataPath = QFINDTESTDATA(subProgram); + if (!testDataPath.endsWith(subProgram)) + QFAIL("Cannot find test data directory."); + testDataPath.chop(subProgram.length() - testDataSubDir.length()); + + QString userWorkDir = qgetenv("TST_QMAKE_BUILD_DIR"); + if (userWorkDir.isEmpty()) { + base_path = tempWorkDir.path(); + } else { + if (!QFile::exists(userWorkDir)) { + QFAIL(qUtf8Printable(QStringLiteral("TST_QMAKE_BUILD_DIR %1 does not exist.") + .arg(userWorkDir))); + } + base_path = userWorkDir; + } + + copyDir(testDataPath, base_path + QLatin1Char('/') + testDataSubDir); +} + +void tst_qmake::cleanupTestCase() +{ + // On Windows, ~QTemporaryDir fails to remove the directory if we're still in there. + QDir::setCurrent(origCurrentDirPath); } void tst_qmake::cleanup() @@ -205,12 +259,12 @@ void tst_qmake::subdirs() D.remove( workDir + "/simple_dll/Makefile"); QVERIFY( test_compiler.qmake( workDir, "subdirs" )); QVERIFY( test_compiler.make( workDir )); - QVERIFY( test_compiler.exists( workDir + "/simple_app/dest dir", "simple app", Exe, "1.0.0" )); - QVERIFY( test_compiler.exists( workDir + "/simple_dll/dest dir", "simple dll", Dll, "1.0.0" )); + QVERIFY( test_compiler.exists(workDir + "/simple_app/dest dir", "simple app", Exe)); + QVERIFY( test_compiler.exists(workDir + "/simple_dll/dest dir", "simple dll", Dll)); QVERIFY( test_compiler.makeClean( workDir )); // Should still exist after a make clean - QVERIFY( test_compiler.exists( workDir + "/simple_app/dest dir", "simple app", Exe, "1.0.0" )); - QVERIFY( test_compiler.exists( workDir + "/simple_dll/dest dir", "simple dll", Dll, "1.0.0" )); + QVERIFY( test_compiler.exists(workDir + "/simple_app/dest dir", "simple app", Exe)); + QVERIFY( test_compiler.exists(workDir + "/simple_dll/dest dir", "simple dll", Dll)); // Since subdirs templates do not have a make dist clean, we should clean up ourselves // properly QVERIFY( test_compiler.makeDistClean( workDir )); @@ -500,8 +554,8 @@ void tst_qmake::resources() QVERIFY(test_compiler.qmake(workDir, "resources")); { - QFile qrcFile(workDir + "/.rcc/" DIR_INFIX "qmake_pro_file.qrc"); - QVERIFY(qrcFile.exists()); + QFile qrcFile(workDir + '/' + DIR_INFIX "qmake_pro_file.qrc"); + QVERIFY2(qrcFile.exists(), qPrintable(qrcFile.fileName())); QVERIFY(qrcFile.open(QFile::ReadOnly)); QByteArray qrcXml = qrcFile.readAll(); QVERIFY(qrcXml.contains("alias=\"resources.pro\"")); @@ -509,7 +563,7 @@ void tst_qmake::resources() } { - QFile qrcFile(workDir + "/.rcc/" DIR_INFIX "qmake_subdir.qrc"); + QFile qrcFile(workDir + '/' + DIR_INFIX "qmake_subdir.qrc"); QVERIFY(qrcFile.exists()); QVERIFY(qrcFile.open(QFile::ReadOnly)); QByteArray qrcXml = qrcFile.readAll(); @@ -517,7 +571,7 @@ void tst_qmake::resources() } { - QFile qrcFile(workDir + "/.rcc/" DIR_INFIX "qmake_qmake_immediate.qrc"); + QFile qrcFile(workDir + '/' + DIR_INFIX "qmake_qmake_immediate.qrc"); QVERIFY(qrcFile.exists()); QVERIFY(qrcFile.open(QFile::ReadOnly)); QByteArray qrcXml = qrcFile.readAll(); -- cgit v1.2.3