diff options
Diffstat (limited to 'tests/auto/tools/qmake/tst_qmake.cpp')
-rw-r--r-- | tests/auto/tools/qmake/tst_qmake.cpp | 86 |
1 files changed, 70 insertions, 16 deletions
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 <QDir> +#include <QDirIterator> #include <QObject> #include <QStandardPaths> -#include <QDir> +#include <QTemporaryDir> #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(); |