QCommandLineParser: show application name in error messages
Change-Id: I2c39759294ca0a11a59b9a38207bf1aef941b070 Fixes: QTBUG-58490 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
f3b980a253
commit
50d53533e5
@ -589,7 +589,7 @@ static void showParserMessage(const QString &message, MessageType type)
|
||||
void QCommandLineParser::process(const QStringList &arguments)
|
||||
{
|
||||
if (!d->parse(arguments)) {
|
||||
showParserMessage(errorText() + QLatin1Char('\n'), ErrorMessage);
|
||||
showParserMessage(QCoreApplication::applicationName() + QLatin1String(": ") + errorText() + QLatin1Char('\n'), ErrorMessage);
|
||||
qt_call_post_routines();
|
||||
::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -74,6 +74,7 @@ private slots:
|
||||
void testHelpOption_data();
|
||||
void testHelpOption();
|
||||
void testQuoteEscaping();
|
||||
void testUnknownOption();
|
||||
};
|
||||
|
||||
static char *empty_argv[] = { 0 };
|
||||
@ -648,6 +649,27 @@ void tst_QCommandLineParser::testQuoteEscaping()
|
||||
#endif // QT_CONFIG(process)
|
||||
}
|
||||
|
||||
void tst_QCommandLineParser::testUnknownOption()
|
||||
{
|
||||
#if !QT_CONFIG(process)
|
||||
QSKIP("This test requires QProcess support");
|
||||
#elif defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
|
||||
QSKIP("Deploying executable applications to file system on Android not supported.");
|
||||
#else
|
||||
QCoreApplication app(empty_argc, empty_argv);
|
||||
QProcess process;
|
||||
process.start("testhelper/qcommandlineparser_test_helper", QStringList() <<
|
||||
QString::number(QCommandLineParser::ParseAsLongOptions) <<
|
||||
"-unknown-option");
|
||||
QVERIFY(process.waitForFinished(5000));
|
||||
QCOMPARE(process.exitStatus(), QProcess::NormalExit);
|
||||
process.setReadChannel(QProcess::StandardError);
|
||||
QString output = process.readAll();
|
||||
QVERIFY2(output.contains("qcommandlineparser_test_helper"), qPrintable(output)); // separate in case of .exe extension
|
||||
QVERIFY2(output.contains(": Unknown option 'unknown-option'"), qPrintable(output));
|
||||
#endif // QT_CONFIG(process)
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_QCommandLineParser)
|
||||
#include "tst_qcommandlineparser.moc"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user