moc: bail out early on missing or invalid options file
If moc is invoked with the @ argument and no options file is specified or the options file cannot be read, do not try to parse the empty arguments list. Otherwise QCommandLineParser will print an additional error message that is of no value for the user. Task-number: QTBUG-51847 Change-Id: I9aa1eb20a44097b553123be8bc6fded87473a03a Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>bb10
parent
a4e2f2e687
commit
479ee4fa46
|
|
@ -282,6 +282,8 @@ int runMoc(int argc, char **argv)
|
|||
QStringLiteral("Read additional options from option-file."));
|
||||
|
||||
const QStringList arguments = argumentsFromCommandLineAndFile(app.arguments());
|
||||
if (arguments.isEmpty())
|
||||
return 1;
|
||||
|
||||
parser.process(arguments);
|
||||
|
||||
|
|
|
|||
|
|
@ -627,6 +627,8 @@ private slots:
|
|||
void unnamedNamespaceObjectsAndGadgets();
|
||||
void veryLongStringData();
|
||||
void gadgetHierarchy();
|
||||
void optionsFileError_data();
|
||||
void optionsFileError();
|
||||
|
||||
signals:
|
||||
void sigWithUnsignedArg(unsigned foo);
|
||||
|
|
@ -3501,6 +3503,31 @@ void tst_Moc::gadgetHierarchy()
|
|||
QCOMPARE(GrandParentGadget::DerivedGadget::staticMetaObject.superClass(), &GrandParentGadget::BaseGadget::staticMetaObject);
|
||||
}
|
||||
|
||||
void tst_Moc::optionsFileError_data()
|
||||
{
|
||||
QTest::addColumn<QString>("optionsArgument");
|
||||
QTest::newRow("no filename") << QStringLiteral("@");
|
||||
QTest::newRow("nonexistent file") << QStringLiteral("@letshuntasnark");
|
||||
}
|
||||
|
||||
void tst_Moc::optionsFileError()
|
||||
{
|
||||
#ifdef MOC_CROSS_COMPILED
|
||||
QSKIP("Not tested when cross-compiled");
|
||||
#endif
|
||||
#if !defined(QT_NO_PROCESS)
|
||||
QFETCH(QString, optionsArgument);
|
||||
QProcess p;
|
||||
p.start(m_moc, QStringList(optionsArgument));
|
||||
QVERIFY(p.waitForFinished());
|
||||
QCOMPARE(p.exitCode(), 1);
|
||||
QVERIFY(p.readAllStandardOutput().isEmpty());
|
||||
const QByteArray err = p.readAllStandardError();
|
||||
QVERIFY(err.contains("moc: "));
|
||||
QVERIFY(!err.contains("QCommandLineParser"));
|
||||
#endif
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_Moc)
|
||||
|
||||
// the generated code must compile with QT_NO_KEYWORDS
|
||||
|
|
|
|||
Loading…
Reference in New Issue