diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2016-03-17 12:48:38 +0100 |
---|---|---|
committer | Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> | 2016-03-23 01:08:28 +0000 |
commit | 63274c95a3d78fbed8f511690cf7b248a6231273 (patch) | |
tree | 1e3beac941dad6057e5d8c1e3b3b3051e97b77e8 /tests | |
parent | 17d3825874b1333a0aa50ba1b8fe1c51d9c9a8db (diff) |
Add QCommandLineOption::Flags containing HiddenFromHelp and ShortOptionStyle
This patch adds a new option, QCommandLineOption::ShortOptionStyle, which helps
applications (such as compilers, so moc and now qdoc) which need to mix long-style
and short flags.
[ChangeLog][QtCore][QCommandLineOption] Added flags() and setFlags() methods.
Added ShortOptionStyle and HiddenFromHelp flags.
Change-Id: I944ce56aff2b28ecd6bb9d2d23c4e726e9d06647
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp | 6 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp | 11 |
2 files changed, 16 insertions, 1 deletions
diff --git a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp index 36bc8621d2..30c7b1bf69 100644 --- a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp +++ b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp @@ -71,8 +71,12 @@ int main(int argc, char *argv[]) // A hidden option QCommandLineOption hiddenOption(QStringList() << QStringLiteral("hidden")); hiddenOption.setDescription(QStringLiteral("THIS SHOULD NEVER APPEAR")); - hiddenOption.setHidden(true); + hiddenOption.setFlags(QCommandLineOption::HiddenFromHelp); parser.addOption(hiddenOption); + QCommandLineOption hiddenOption2(QStringList() << QStringLiteral("hidden2")); + hiddenOption2.setDescription(QStringLiteral("NEITHER SHOULD THIS")); + hiddenOption2.setHidden(true); + parser.addOption(hiddenOption2); // This program supports different options depending on the "command" (first argument). // Call parse() to find out the positional arguments. diff --git a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp index f3f335cb92..fd835daa3a 100644 --- a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp +++ b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp @@ -450,6 +450,13 @@ void tst_QCommandLineParser::testSingleDashWordOptionModes_data() << QStringList("abc") << QStringList("val"); QTest::newRow("implicitlylong_with_space") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "-c" << "val") << QStringList("c") << QStringList("val"); + + QTest::newRow("forceshort_detached") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-I" << "45") + << QStringList("I") << QStringList("45"); + QTest::newRow("forceshort_attached") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-I46") + << QStringList("I") << QStringList("46"); + QTest::newRow("forceshort_mixed") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-I45" << "-nn") + << (QStringList() << "I" << "nn") << QStringList("45"); } void tst_QCommandLineParser::testSingleDashWordOptionModes() @@ -468,6 +475,10 @@ void tst_QCommandLineParser::testSingleDashWordOptionModes() parser.addOption(QCommandLineOption("b", QStringLiteral("b option."))); parser.addOption(QCommandLineOption(QStringList() << "c" << "abc", QStringLiteral("c option."), QStringLiteral("value"))); parser.addOption(QCommandLineOption("nn", QStringLiteral("nn option."))); + QCommandLineOption forceShort(QStringLiteral("I"), QStringLiteral("always short option"), + QStringLiteral("path"), QStringLiteral("default")); + forceShort.setFlags(QCommandLineOption::ShortOptionStyle); + parser.addOption(forceShort); QVERIFY(parser.parse(commandLine)); QCOMPARE(parser.optionNames(), expectedOptionNames); for (int i = 0; i < expectedOptionValues.count(); ++i) |