tst_moc: DRY QProcess success verification
While the code that checked that exitCode() == 0 was still consistent between all the callers, when it comes to checking stderr, there were several competing implementations, incl. checking the exitCode and dumping stderr to qDebug(), and using QCOMPARE to QByteArray(), presumably in order to get more detailed output on error. Alas, QCOMPARE's toString() truncates output pretty early, making it impossible to see what's going on on failure. So write a small macro that checks the exitCode _after_ it checked that stderr was empty (printing it in full if it was not), so we consistently get the error message instead of a truncated version, or just "exitCode() != 0" without further details. Pick-to: 6.6 6.5 6.2 5.15 Change-Id: Ic8547fda3b02c645901962887c6ed7aad01f6ea4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 93af86bad566bf4c2c0a5fa7f64e84daaa20a311) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
6ceab7ec35
commit
22f0d3164e
@ -868,6 +868,14 @@ private:
|
||||
|
||||
};
|
||||
|
||||
#define VERIFY_NO_ERRORS(proc) do { \
|
||||
auto &&p = proc; \
|
||||
const QByteArray stderr = p.readAllStandardError(); \
|
||||
QVERIFY2(stderr.isEmpty(), stderr.data()); \
|
||||
QCOMPARE(p.exitCode(), 0); \
|
||||
} while (false)
|
||||
|
||||
|
||||
void tst_Moc::initTestCase()
|
||||
{
|
||||
QString binpath = QLibraryInfo::path(QLibraryInfo::BinariesPath);
|
||||
@ -882,10 +890,9 @@ void tst_Moc::initTestCase()
|
||||
QProcess proc;
|
||||
proc.start(qtpaths, QStringList() << "-query" << "QT_INSTALL_HEADERS");
|
||||
QVERIFY(proc.waitForFinished());
|
||||
QCOMPARE(proc.exitCode(), 0);
|
||||
VERIFY_NO_ERRORS(proc);
|
||||
QByteArray output = proc.readAllStandardOutput();
|
||||
QVERIFY(!output.isEmpty());
|
||||
QCOMPARE(proc.readAllStandardError(), QByteArray());
|
||||
qtIncludePath = QString::fromLocal8Bit(output).trimmed();
|
||||
QFileInfo fi(qtIncludePath);
|
||||
QVERIFY(fi.exists());
|
||||
@ -920,10 +927,9 @@ void tst_Moc::oldStyleCasts()
|
||||
QProcess proc;
|
||||
proc.start(m_moc, QStringList(m_sourceDirectory + QStringLiteral("/oldstyle-casts.h")));
|
||||
QVERIFY(proc.waitForFinished());
|
||||
QCOMPARE(proc.exitCode(), 0);
|
||||
VERIFY_NO_ERRORS(proc);
|
||||
QByteArray mocOut = proc.readAllStandardOutput();
|
||||
QVERIFY(!mocOut.isEmpty());
|
||||
QCOMPARE(proc.readAllStandardError(), QByteArray());
|
||||
|
||||
QStringList args;
|
||||
args << "-c" << "-x" << "c++" << "-Wold-style-cast" << "-I" << "."
|
||||
@ -934,8 +940,7 @@ void tst_Moc::oldStyleCasts()
|
||||
proc.closeWriteChannel();
|
||||
|
||||
QVERIFY(proc.waitForFinished());
|
||||
QCOMPARE(QString::fromLocal8Bit(proc.readAllStandardError()), QString());
|
||||
QCOMPARE(proc.exitCode(), 0);
|
||||
VERIFY_NO_ERRORS(proc);
|
||||
#else
|
||||
QSKIP("Only tested on linux/gcc");
|
||||
#endif
|
||||
@ -992,10 +997,9 @@ void tst_Moc::inputFileNameWithDotsButNoExtension()
|
||||
proc.setWorkingDirectory(m_sourceDirectory + QStringLiteral("/task71021"));
|
||||
proc.start(m_moc, QStringList("../Header"));
|
||||
QVERIFY(proc.waitForFinished());
|
||||
QCOMPARE(proc.exitCode(), 0);
|
||||
VERIFY_NO_ERRORS(proc);
|
||||
QByteArray mocOut = proc.readAllStandardOutput();
|
||||
QVERIFY(!mocOut.isEmpty());
|
||||
QCOMPARE(proc.readAllStandardError(), QByteArray());
|
||||
|
||||
QStringList args;
|
||||
args << "-c" << "-x" << "c++" << "-I" << ".."
|
||||
@ -1006,8 +1010,7 @@ void tst_Moc::inputFileNameWithDotsButNoExtension()
|
||||
proc.closeWriteChannel();
|
||||
|
||||
QVERIFY(proc.waitForFinished());
|
||||
QCOMPARE(QString::fromLocal8Bit(proc.readAllStandardError()), QString());
|
||||
QCOMPARE(proc.exitCode(), 0);
|
||||
VERIFY_NO_ERRORS(proc);
|
||||
#else
|
||||
QSKIP("Only tested on linux/gcc");
|
||||
#endif
|
||||
@ -1284,11 +1287,7 @@ void tst_Moc::ignoreOptionClashes()
|
||||
if (!finished)
|
||||
qWarning("waitForFinished failed. QProcess error: %d", (int)proc.error());
|
||||
QVERIFY(finished);
|
||||
if (proc.exitCode() != 0) {
|
||||
qDebug() << proc.readAllStandardError();
|
||||
}
|
||||
QCOMPARE(proc.exitCode(), 0);
|
||||
QCOMPARE(proc.readAllStandardError(), QByteArray());
|
||||
VERIFY_NO_ERRORS(proc);
|
||||
QByteArray mocOut = proc.readAllStandardOutput();
|
||||
|
||||
// If -pthread wasn't ignored, it was parsed as a prefix of "thread/", which breaks compilation.
|
||||
@ -1302,7 +1301,7 @@ void tst_Moc::ignoreOptionClashes()
|
||||
proc.closeWriteChannel();
|
||||
|
||||
QVERIFY(proc.waitForFinished());
|
||||
QCOMPARE(QString::fromLocal8Bit(proc.readAllStandardError()), QString());
|
||||
VERIFY_NO_ERRORS(proc);
|
||||
#else
|
||||
QSKIP("Only tested on linux/gcc");
|
||||
#endif
|
||||
@ -1407,11 +1406,7 @@ void tst_Moc::frameworkSearchPath()
|
||||
if (!finished)
|
||||
qWarning("waitForFinished failed. QProcess error: %d", (int)proc.error());
|
||||
QVERIFY(finished);
|
||||
if (proc.exitCode() != 0) {
|
||||
qDebug() << proc.readAllStandardError();
|
||||
}
|
||||
QCOMPARE(proc.exitCode(), 0);
|
||||
QCOMPARE(proc.readAllStandardError(), QByteArray());
|
||||
VERIFY_NO_ERRORS(proc);
|
||||
#else
|
||||
QSKIP("Only tested/relevant on unixy platforms");
|
||||
#endif
|
||||
@ -1443,11 +1438,9 @@ void tst_Moc::templateGtGt()
|
||||
QProcess proc;
|
||||
proc.start(m_moc, QStringList(m_sourceDirectory + QStringLiteral("/template-gtgt.h")));
|
||||
QVERIFY(proc.waitForFinished());
|
||||
QCOMPARE(proc.exitCode(), 0);
|
||||
VERIFY_NO_ERRORS(proc);
|
||||
QByteArray mocOut = proc.readAllStandardOutput();
|
||||
QVERIFY(!mocOut.isEmpty());
|
||||
QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError());
|
||||
QVERIFY(mocWarning.isEmpty());
|
||||
#else
|
||||
QSKIP("Only tested on unix/gcc");
|
||||
#endif
|
||||
@ -1464,8 +1457,7 @@ void tst_Moc::defineMacroViaCmdline()
|
||||
|
||||
proc.start(m_moc, args);
|
||||
QVERIFY(proc.waitForFinished());
|
||||
QCOMPARE(proc.exitCode(), 0);
|
||||
QCOMPARE(proc.readAllStandardError(), QByteArray());
|
||||
VERIFY_NO_ERRORS(proc);
|
||||
QByteArray mocOut = proc.readAllStandardOutput();
|
||||
QVERIFY(!mocOut.isEmpty());
|
||||
#else
|
||||
@ -1484,8 +1476,7 @@ void tst_Moc::defineMacroViaForcedInclude()
|
||||
|
||||
proc.start(m_moc, args);
|
||||
QVERIFY(proc.waitForFinished());
|
||||
QCOMPARE(proc.exitCode(), 0);
|
||||
QCOMPARE(proc.readAllStandardError(), QByteArray());
|
||||
VERIFY_NO_ERRORS(proc);
|
||||
QByteArray mocOut = proc.readAllStandardOutput();
|
||||
QVERIFY(!mocOut.isEmpty());
|
||||
#else
|
||||
@ -1504,8 +1495,7 @@ void tst_Moc::defineMacroViaForcedIncludeRelative()
|
||||
|
||||
proc.start(m_moc, args);
|
||||
QVERIFY(proc.waitForFinished());
|
||||
QCOMPARE(proc.exitCode(), 0);
|
||||
QCOMPARE(proc.readAllStandardError(), QByteArray());
|
||||
VERIFY_NO_ERRORS(proc);
|
||||
QByteArray mocOut = proc.readAllStandardOutput();
|
||||
QVERIFY(!mocOut.isEmpty());
|
||||
#else
|
||||
@ -1550,8 +1540,7 @@ void tst_Moc::environmentIncludePaths()
|
||||
proc.setProcessEnvironment(env);
|
||||
proc.start(m_moc, args);
|
||||
QVERIFY(proc.waitForFinished());
|
||||
QCOMPARE(proc.exitCode(), 0);
|
||||
QCOMPARE(proc.readAllStandardError(), QByteArray());
|
||||
VERIFY_NO_ERRORS(proc);
|
||||
QByteArray mocOut = proc.readAllStandardOutput();
|
||||
QVERIFY(!mocOut.isEmpty());
|
||||
#else
|
||||
@ -2009,11 +1998,10 @@ void tst_Moc::notifyError()
|
||||
const QString header = m_sourceDirectory + QStringLiteral("/error-on-wrong-notify.h");
|
||||
proc.start(m_moc, QStringList(header));
|
||||
QVERIFY(proc.waitForFinished());
|
||||
QCOMPARE(proc.exitCode(), 0);
|
||||
VERIFY_NO_ERRORS(proc);
|
||||
QCOMPARE(proc.exitStatus(), QProcess::NormalExit);
|
||||
QByteArray mocOut = proc.readAllStandardOutput();
|
||||
QVERIFY(!mocOut.isEmpty());
|
||||
QCOMPARE(proc.readAllStandardError(), QByteArray());
|
||||
|
||||
QStringList args;
|
||||
args << "-c" << "-x" << "c++" << "-I" << "."
|
||||
@ -3758,10 +3746,9 @@ void tst_Moc::preprocessorOnly()
|
||||
QProcess proc;
|
||||
proc.start(m_moc, QStringList() << "-E" << m_sourceDirectory + QStringLiteral("/pp-dollar-signs.h"));
|
||||
QVERIFY(proc.waitForFinished());
|
||||
QCOMPARE(proc.exitCode(), 0);
|
||||
VERIFY_NO_ERRORS(proc);
|
||||
QByteArray mocOut = proc.readAllStandardOutput();
|
||||
QVERIFY(!mocOut.isEmpty());
|
||||
QCOMPARE(proc.readAllStandardError(), QByteArray());
|
||||
|
||||
QVERIFY(mocOut.contains("$$ = parser->createFoo()"));
|
||||
#else
|
||||
|
Loading…
x
Reference in New Issue
Block a user