From 479ee4fa461e3c9bd71480d8e7a0bcabced52919 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 30 Mar 2016 18:20:40 +0200 Subject: 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) --- tests/auto/tools/moc/tst_moc.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/auto/tools/moc/tst_moc.cpp') 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("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 -- cgit v1.2.3