diff options
Diffstat (limited to 'tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp')
-rw-r--r-- | tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp index 6252440232..812cf2d1b3 100644 --- a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp +++ b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp @@ -1,6 +1,6 @@ // Copyright (C) 2021 David Faure <faure@kde.org> // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #if QT_CONFIG(process) @@ -126,6 +126,7 @@ void tst_QCommandLineParser::testBooleanOption() QVERIFY(parser.parse(args)); QCOMPARE(parser.optionNames(), expectedOptionNames); QCOMPARE(parser.isSet("b"), expectedIsSet); + QTest::ignoreMessage(QtWarningMsg, "QCommandLineParser: option not expecting values: \"b\""); QCOMPARE(parser.values("b"), QStringList()); QCOMPARE(parser.positionalArguments(), QStringList()); // Should warn on typos @@ -163,6 +164,7 @@ void tst_QCommandLineParser::testOptionsAndPositional() QVERIFY(parser.parse(args)); QCOMPARE(parser.optionNames(), expectedOptionNames); QCOMPARE(parser.isSet("b"), expectedIsSet); + QTest::ignoreMessage(QtWarningMsg, "QCommandLineParser: option not expecting values: \"b\""); QCOMPARE(parser.values("b"), QStringList()); QCOMPARE(parser.positionalArguments(), expectedPositionalArguments); } @@ -361,6 +363,7 @@ void tst_QCommandLineParser::testProcessNotCalled() QTest::ignoreMessage(QtWarningMsg, "QCommandLineParser: call process() or parse() before isSet"); QVERIFY(!parser.isSet("b")); QTest::ignoreMessage(QtWarningMsg, "QCommandLineParser: call process() or parse() before values"); + QTest::ignoreMessage(QtWarningMsg, "QCommandLineParser: option not expecting values: \"b\""); QCOMPARE(parser.values("b"), QStringList()); } @@ -448,37 +451,40 @@ void tst_QCommandLineParser::testSingleDashWordOptionModes_data() QTest::addColumn<QStringList>("commandLine"); QTest::addColumn<QStringList>("expectedOptionNames"); QTest::addColumn<QStringList>("expectedOptionValues"); + QTest::addColumn<QStringList>("invalidOptionValues"); QTest::newRow("collapsed") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "-abc" << "val") - << (QStringList() << "a" << "b" << "c") << (QStringList() << QString() << QString() << "val"); + << (QStringList() << "a" << "b" << "c") << (QStringList() << QString() << QString() << "val") + << (QStringList() << "a" << "b"); QTest::newRow("collapsed_with_equalsign_value") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "-abc=val") - << (QStringList() << "a" << "b" << "c") << (QStringList() << QString() << QString() << "val"); + << (QStringList() << "a" << "b" << "c") << (QStringList() << QString() << QString() << "val") + << (QStringList() << "a" << "b"); QTest::newRow("collapsed_explicit_longoption") << QCommandLineParser::ParseAsCompactedShortOptions << QStringList("--nn") - << QStringList("nn") << QStringList(); + << QStringList("nn") << QStringList() << QStringList(); QTest::newRow("collapsed_longoption_value") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "--abc" << "val") - << QStringList("abc") << QStringList("val"); + << QStringList("abc") << QStringList("val") << QStringList(); QTest::newRow("compiler") << QCommandLineParser::ParseAsCompactedShortOptions << QStringList("-cab") - << QStringList("c") << QStringList("ab"); + << QStringList("c") << QStringList("ab") << QStringList(); QTest::newRow("compiler_with_space") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "-c" << "val") - << QStringList("c") << QStringList("val"); + << QStringList("c") << QStringList("val") << QStringList(); QTest::newRow("implicitlylong") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-abc" << "val") - << QStringList("abc") << QStringList("val"); + << QStringList("abc") << QStringList("val") << QStringList(); QTest::newRow("implicitlylong_equal") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-abc=val") - << QStringList("abc") << QStringList("val"); + << QStringList("abc") << QStringList("val") << QStringList(); QTest::newRow("implicitlylong_longoption") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "--nn") - << QStringList("nn") << QStringList(); + << QStringList("nn") << QStringList() << QStringList(); QTest::newRow("implicitlylong_longoption_value") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "--abc" << "val") - << QStringList("abc") << QStringList("val"); + << QStringList("abc") << QStringList("val") << QStringList(); QTest::newRow("implicitlylong_with_space") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "-c" << "val") - << QStringList("c") << QStringList("val"); + << QStringList("c") << QStringList("val") << QStringList(); QTest::newRow("forceshort_detached") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-I" << "45") - << QStringList("I") << QStringList("45"); + << QStringList("I") << QStringList("45") << QStringList(); QTest::newRow("forceshort_attached") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-I46") - << QStringList("I") << QStringList("46"); + << QStringList("I") << QStringList("46") << QStringList(); QTest::newRow("forceshort_mixed") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-I45" << "-nn") - << (QStringList() << "I" << "nn") << QStringList("45"); + << (QStringList() << "I" << "nn") << QStringList("45") << QStringList(); } void tst_QCommandLineParser::testSingleDashWordOptionModes() @@ -487,6 +493,7 @@ void tst_QCommandLineParser::testSingleDashWordOptionModes() QFETCH(QStringList, commandLine); QFETCH(QStringList, expectedOptionNames); QFETCH(QStringList, expectedOptionValues); + QFETCH(QStringList, invalidOptionValues); commandLine.prepend("tst_QCommandLineParser"); @@ -503,14 +510,19 @@ void tst_QCommandLineParser::testSingleDashWordOptionModes() QVERIFY(parser.addOption(forceShort)); QVERIFY(parser.parse(commandLine)); QCOMPARE(parser.optionNames(), expectedOptionNames); - for (int i = 0; i < expectedOptionValues.size(); ++i) - QCOMPARE(parser.value(parser.optionNames().at(i)), expectedOptionValues.at(i)); + for (int i = 0; i < expectedOptionValues.size(); ++i) { + const QString option = parser.optionNames().at(i); + if (invalidOptionValues.contains(option)) { + QByteArray msg = QLatin1String("QCommandLineParser: option not expecting values: \"%1\"").arg(option).toLatin1(); + QTest::ignoreMessage(QtWarningMsg, msg.data()); + } + QCOMPARE(parser.value(option), expectedOptionValues.at(i)); + } QCOMPARE(parser.unknownOptionNames(), QStringList()); } void tst_QCommandLineParser::testCpp11StyleInitialization() { -#if defined(Q_COMPILER_UNIFORM_INIT) QCoreApplication app(empty_argc, empty_argv); QCommandLineParser parser; @@ -524,9 +536,6 @@ void tst_QCommandLineParser::testCpp11StyleInitialization() QVERIFY(parser.parse({"tst_QCommandLineParser", "-a", "-vvv", "--infile=in.txt"})); QCOMPARE(parser.optionNames(), (QStringList{"a", "v", "v", "v", "infile"})); QCOMPARE(parser.value("infile"), QString("in.txt")); -#else - QSKIP("This test requires C++11 uniform initialization support in the compiler."); -#endif } void tst_QCommandLineParser::testVersionOption() @@ -553,7 +562,7 @@ void tst_QCommandLineParser::testVersionOption() static const char expectedOptionsHelp[] = "Options:\n" " -h, --help Displays help on commandline options.\n" - " --help-all Displays help including Qt specific options.\n" + " --help-all Displays help, including generic Qt options.\n" " -v, --version Displays version information.\n" " --load <url> Load file from URL.\n" " -o, --output <file> Set output file.\n" |