diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-09-04 14:33:40 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-09-04 14:33:40 +0200 |
commit | f255b1e8e297e7e1363921580007145cff574e0d (patch) | |
tree | 9a799be282e6c0d6544d9f8c872073f83e6c0475 /tests/auto/tools/qmake | |
parent | 7e8705f6632428a8d9a937ab5fe087999347b3dd (diff) | |
parent | bf8fcab8bb92ff534c5cec048d6dbebb3b73a348 (diff) |
Merge remote-tracking branch 'origin/dev' into wip/qt6
Change-Id: I54741635460bb2d8f3fd0be535ee1968d6c442bb
Diffstat (limited to 'tests/auto/tools/qmake')
10 files changed, 218 insertions, 12 deletions
diff --git a/tests/auto/tools/qmake/testcompiler.cpp b/tests/auto/tools/qmake/testcompiler.cpp index 0a7ba3b40b..8ab8d5d721 100644 --- a/tests/auto/tools/qmake/testcompiler.cpp +++ b/tests/auto/tools/qmake/testcompiler.cpp @@ -164,15 +164,17 @@ bool TestCompiler::runCommand(const QString &cmd, const QStringList &args, bool return errorOut(); } - child.setReadChannel(QProcess::StandardError); child.waitForFinished(-1); bool ok = child.exitStatus() == QProcess::NormalExit && (expectFail ^ (child.exitCode() == 0)); - foreach (const QByteArray &output, child.readAllStandardError().split('\n')) { - testOutput_.append(QString::fromLocal8Bit(output)); - - if (output.startsWith("Project MESSAGE: FAILED")) - ok = false; + for (auto channel : { QProcess::StandardOutput, QProcess::StandardError }) { + child.setReadChannel(channel); + while (!child.atEnd()) { + const QString output = QString::fromLocal8Bit(child.readLine()); + if (output.startsWith("Project MESSAGE: FAILED")) + ok = false; + testOutput_.append(output); + } } return ok ? true : errorOut(); @@ -279,14 +281,23 @@ bool TestCompiler::qmake(const QString &workDir, const QString &proName, const Q << additionalArguments); } +bool TestCompiler::qmake(const QString &workDir, const QStringList &arguments) +{ + QDir d; + d.setCurrent(workDir); // ### runCommand should take a workingDir argument instead + return runCommand(qmakeCmd_, arguments); +} + bool TestCompiler::make( const QString &workPath, const QString &target, bool expectFail ) { QDir D; D.setCurrent( workPath ); QStringList args = makeArgs_; - if (makeCmd_.contains("nmake", Qt::CaseInsensitive)) + if (makeCmd_.contains("nmake", Qt::CaseInsensitive) || + makeCmd_.contains("jom", Qt::CaseInsensitive)) { args << "/NOLOGO"; + } if (!target.isEmpty()) args << target; diff --git a/tests/auto/tools/qmake/testcompiler.h b/tests/auto/tools/qmake/testcompiler.h index 50232669c0..d80cd8d53a 100644 --- a/tests/auto/tools/qmake/testcompiler.h +++ b/tests/auto/tools/qmake/testcompiler.h @@ -60,6 +60,8 @@ public: // executes a qmake on proName in the specified workDir, output goes to buildDir or workDir if it's null bool qmake(const QString &workDir, const QString &proName, const QString &buildDir = QString(), const QStringList &additionalArguments = QStringList()); + // executes qmake in workDir with the specified arguments + bool qmake(const QString &workDir, const QStringList &arguments); // 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 @@ -71,13 +73,17 @@ public: bool removeProject( const QString &workPath, const QString &project ); // removes the file specified by 'fileName' on the 'workPath' bool removeFile( const QString &workPath, const QString &fileName ); - // returns each line of stdout of the last command append with a "new line" character(s) to suit the platform + + // Returns each line of stdout/stderr of the last commands + // separated by platform-specific line endings. QString commandOutput() const; + // clear the results of storage of stdout for running previous commands void clearCommandOutput(); -private: bool runCommand(const QString &cmd, const QStringList &args, bool expectFail = false); + +private: bool errorOut(); QString makeCmd_; diff --git a/tests/auto/tools/qmake/testdata/conflicting_targets/conflicting_targets.pro b/tests/auto/tools/qmake/testdata/conflicting_targets/conflicting_targets.pro new file mode 100644 index 0000000000..c3e8034e35 --- /dev/null +++ b/tests/auto/tools/qmake/testdata/conflicting_targets/conflicting_targets.pro @@ -0,0 +1,5 @@ +TEMPLATE = app +CONFIG += debug_and_release +TARGET = bah +DESTDIR = shu +SOURCES += main.cpp diff --git a/tests/auto/tools/qmake/testdata/conflicting_targets/main.cpp b/tests/auto/tools/qmake/testdata/conflicting_targets/main.cpp new file mode 100644 index 0000000000..39de28135a --- /dev/null +++ b/tests/auto/tools/qmake/testdata/conflicting_targets/main.cpp @@ -0,0 +1,4 @@ +int main(int, char **) +{ + return 0; +} diff --git a/tests/auto/tools/qmake/testdata/windows_resources/inter.inc b/tests/auto/tools/qmake/testdata/windows_resources/inter.inc new file mode 100644 index 0000000000..0c2594214e --- /dev/null +++ b/tests/auto/tools/qmake/testdata/windows_resources/inter.inc @@ -0,0 +1 @@ +#include "version.inc" diff --git a/tests/auto/tools/qmake/testdata/windows_resources/main.cpp b/tests/auto/tools/qmake/testdata/windows_resources/main.cpp new file mode 100644 index 0000000000..237c8ce181 --- /dev/null +++ b/tests/auto/tools/qmake/testdata/windows_resources/main.cpp @@ -0,0 +1 @@ +int main() {} diff --git a/tests/auto/tools/qmake/testdata/windows_resources/version.inc b/tests/auto/tools/qmake/testdata/windows_resources/version.inc new file mode 100644 index 0000000000..b797c9acce --- /dev/null +++ b/tests/auto/tools/qmake/testdata/windows_resources/version.inc @@ -0,0 +1,28 @@ +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,0 + PRODUCTVERSION 1,0,0,0 + FILEFLAGS 0x0L + FILEFLAGSMASK 0x3fL + FILEOS 0x00040004L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "CompanyName", "The Qt Company Ltd" + VALUE "FileDescription", "A Good File" + VALUE "FileVersion", "1.0.0.0" + VALUE "LegalCopyright", "Copyright (C) 2019 The Qt Company Ltd." + VALUE "InternalName", "foo" + VALUE "OriginalFilename", "foo.exe" + VALUE "ProductName", "A Good Product" + VALUE "ProductVersion", "1.0.0.0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END diff --git a/tests/auto/tools/qmake/testdata/windows_resources/windows_resources.pro b/tests/auto/tools/qmake/testdata/windows_resources/windows_resources.pro new file mode 100644 index 0000000000..80a5e5c19a --- /dev/null +++ b/tests/auto/tools/qmake/testdata/windows_resources/windows_resources.pro @@ -0,0 +1,4 @@ +QT = core +SOURCES = main.cpp +RC_FILE = windows_resources.rc +TEMPLATE = app diff --git a/tests/auto/tools/qmake/testdata/windows_resources/windows_resources.rc b/tests/auto/tools/qmake/testdata/windows_resources/windows_resources.rc new file mode 100644 index 0000000000..4df652de35 --- /dev/null +++ b/tests/auto/tools/qmake/testdata/windows_resources/windows_resources.rc @@ -0,0 +1,2 @@ +#include "winver.h" +#include "inter.inc" diff --git a/tests/auto/tools/qmake/tst_qmake.cpp b/tests/auto/tools/qmake/tst_qmake.cpp index 1df31904d6..99d41d3583 100644 --- a/tests/auto/tools/qmake/tst_qmake.cpp +++ b/tests/auto/tools/qmake/tst_qmake.cpp @@ -33,6 +33,7 @@ #include <QDir> #include <QDirIterator> #include <QObject> +#include <QRegularExpression> #include <QStandardPaths> #include <QTemporaryDir> @@ -75,13 +76,17 @@ private slots: void findMocs(); void findDeps(); void rawString(); -#if defined(Q_OS_MAC) +#if defined(Q_OS_DARWIN) void bundle_spaces(); +#elif defined(Q_OS_WIN) + void windowsResources(); #endif void substitutes(); void project(); void proFileCache(); + void qinstall(); void resources(); + void conflictingTargets(); private: TestCompiler test_compiler; @@ -510,7 +515,8 @@ struct TempFile } }; -#if defined(Q_OS_MAC) +#if defined(Q_OS_DARWIN) + void tst_qmake::bundle_spaces() { QString workDir = base_path + "/testdata/bundle-spaces"; @@ -541,7 +547,34 @@ void tst_qmake::bundle_spaces() QVERIFY( !non_existing_file.exists() ); QVERIFY( test_compiler.removeMakefile(workDir) ); } -#endif // defined(Q_OS_MAC) + +#elif defined(Q_OS_WIN) // defined(Q_OS_DARWIN) + +void tst_qmake::windowsResources() +{ + QString workDir = base_path + "/testdata/windows_resources"; + QVERIFY(test_compiler.qmake(workDir, "windows_resources")); + QVERIFY(test_compiler.make(workDir)); + + // Another "make" must not rebuild the .res file + test_compiler.clearCommandOutput(); + QVERIFY(test_compiler.make(workDir)); + QVERIFY(!test_compiler.commandOutput().contains("windows_resources.rc")); + test_compiler.clearCommandOutput(); + + // Wait a second to make sure we get a new timestamp in the touch below + QTest::qWait(1000); + + // Touch the deepest include of the .rc file + QVERIFY(test_compiler.runCommand("cmd", QStringList{"/c", + "echo.>>" + QDir::toNativeSeparators(workDir + "/version.inc")})); + + // The next "make" must rebuild the .res file + QVERIFY(test_compiler.make(workDir)); + QVERIFY(test_compiler.commandOutput().contains("windows_resources.rc")); +} + +#endif // defined(Q_OS_WIN) void tst_qmake::substitutes() { @@ -588,6 +621,104 @@ void tst_qmake::proFileCache() QVERIFY( test_compiler.qmake( workDir, "pro_file_cache" )); } +void tst_qmake::qinstall() +{ + const QString testName = "qinstall"; + QDir testDataDir = base_path + "/testdata"; + if (testDataDir.exists(testName)) + testDataDir.rmdir(testName); + QVERIFY(testDataDir.mkdir(testName)); + const QString workDir = testDataDir.filePath(testName); + auto qinstall = [&](const QString &src, const QString &dst, bool executable = false) { + QStringList args = {"-install", "qinstall"}; + if (executable) + args << "-exe"; + args << src << dst; + return test_compiler.qmake(workDir, args); + }; + const QFileDevice::Permissions readFlags + = QFileDevice::ReadOwner | QFileDevice::ReadUser + | QFileDevice::ReadGroup | QFileDevice::ReadOther; + const QFileDevice::Permissions writeFlags + = QFileDevice::WriteOwner | QFileDevice::WriteUser + | QFileDevice::WriteGroup | QFileDevice::WriteOther; + const QFileDevice::Permissions exeFlags + = QFileDevice::ExeOwner | QFileDevice::ExeUser + | QFileDevice::ExeGroup | QFileDevice::ExeOther; + + // install a regular file + { + QFileInfo src(testDataDir.filePath("project/main.cpp")); + QFileInfo dst("foo.cpp"); + QVERIFY(qinstall(src.filePath(), dst.filePath())); + QVERIFY(dst.exists()); + QCOMPARE(src.size(), dst.size()); + QVERIFY(dst.permissions() & readFlags); + QVERIFY(dst.permissions() & writeFlags); + QVERIFY(!(dst.permissions() & exeFlags)); + test_compiler.clearCommandOutput(); + } + + // install an executable file + { + const QString mocFilePath = QLibraryInfo::location(QLibraryInfo::BinariesPath) + + "/moc" +#ifdef Q_OS_WIN + + ".exe" +#endif + ; + QFileInfo src(mocFilePath); + QVERIFY(src.exists()); + QVERIFY(src.permissions() & exeFlags); + QFileInfo dst("copied_" + src.fileName()); + QVERIFY(qinstall(src.filePath(), dst.filePath(), true)); + QVERIFY(dst.exists()); + QCOMPARE(src.size(), dst.size()); + QVERIFY(dst.permissions() & readFlags); + QVERIFY(dst.permissions() & writeFlags); + QVERIFY(dst.permissions() & exeFlags); + test_compiler.clearCommandOutput(); + } + + // install a read-only file + { + QFile srcfile("foo.cpp"); + QVERIFY(srcfile.setPermissions(srcfile.permissions() & ~writeFlags)); + QFileInfo src(srcfile); + QFileInfo dst("bar.cpp"); + QVERIFY(qinstall(src.filePath(), dst.filePath())); + QVERIFY(dst.exists()); + QCOMPARE(src.size(), dst.size()); + QVERIFY(dst.permissions() & readFlags); + QVERIFY(dst.permissions() & writeFlags); + QVERIFY(!(dst.permissions() & exeFlags)); + test_compiler.clearCommandOutput(); + } + + // install a directory + { + QDir src = testDataDir; + src.cd("project"); + QDir dst("narf"); + QVERIFY(qinstall(src.absolutePath(), dst.absolutePath())); + QCOMPARE(src.entryList(QDir::Files, QDir::Name), dst.entryList(QDir::Files, QDir::Name)); + test_compiler.clearCommandOutput(); + } + + // install a directory with a read-only file + { + QDir src("narf"); + QFile srcfile(src.filePath("main.cpp")); + QVERIFY(srcfile.setPermissions(srcfile.permissions() & ~writeFlags)); + QDir dst("zort"); +#ifdef Q_OS_WIN + QEXPECT_FAIL("", "QTBUG-77299", Abort); +#endif + QVERIFY(qinstall(src.absolutePath(), dst.absolutePath())); + QCOMPARE(src.entryList(QDir::Files, QDir::Name), dst.entryList(QDir::Files, QDir::Name)); + } +} + void tst_qmake::resources() { QString workDir = base_path + "/testdata/resources"; @@ -621,5 +752,18 @@ void tst_qmake::resources() QVERIFY(test_compiler.make(workDir)); } +void tst_qmake::conflictingTargets() +{ + QString workDir = base_path + "/testdata/conflicting_targets"; + QVERIFY(test_compiler.qmake(workDir, "conflicting_targets")); + const QRegularExpression rex("Targets of builds '([^']+)' and '([^']+)' conflict"); + auto match = rex.match(test_compiler.commandOutput()); + QVERIFY(match.hasMatch()); + QStringList builds = { match.captured(1), match.captured(2) }; + std::sort(builds.begin(), builds.end()); + const QStringList expectedBuilds{"Debug", "Release"}; + QCOMPARE(builds, expectedBuilds); +} + QTEST_MAIN(tst_qmake) #include "tst_qmake.moc" |