summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@theqtcompany.com>2016-03-30 18:20:40 +0200
committerJoerg Bornemann <joerg.bornemann@theqtcompany.com>2016-03-31 08:57:39 +0000
commit479ee4fa461e3c9bd71480d8e7a0bcabced52919 (patch)
tree6d608371899ed9aafe0280bc2b5ca79ae200bad8 /tests
parenta4e2f2e687ca7aec88ecf82f72d42ac61e17a5b9 (diff)
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/tools/moc/tst_moc.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index 5c16c7a48f..b3f9a9f85f 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -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