aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/tools/tst_tools.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@digia.com>2012-10-09 15:04:27 +0200
committerJoerg Bornemann <joerg.bornemann@digia.com>2012-10-10 09:49:18 +0200
commit1a20a07bf12dbe684d919e0b2a17247d93794d91 (patch)
tree3947f662f693bdf98a0bd16f080db61dc6c5e7a2 /tests/auto/tools/tst_tools.cpp
parent9c9475a816383f0eeccaaf6d6dcca591eabafb39 (diff)
Rework command line parsing.
- Allow combined short options, e.g. "-vkj 3" meaning "-v -k -j 3". - For options taking list arguments, expect these lists as comma- - Refactor command line parsing. It should now be easier to understand what is going on, which is necessary for adding new options. Change-Id: Ic4af05edeb435e693c667714517dfdb571cc8c46 Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'tests/auto/tools/tst_tools.cpp')
-rw-r--r--tests/auto/tools/tst_tools.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/tests/auto/tools/tst_tools.cpp b/tests/auto/tools/tst_tools.cpp
index 49e3e47c7..8a57ddc0f 100644
--- a/tests/auto/tools/tst_tools.cpp
+++ b/tests/auto/tools/tst_tools.cpp
@@ -37,18 +37,34 @@ class TestFileInfo : public QObject
{
Q_OBJECT
private slots:
- void testCommandLineOptions()
+ void testValidCommandLine()
{
QStringList args;
- args.append("-vvv");
- args.append("-k");
+ args.append("-vvk");
+ args.append("-v");
+ args << "--products" << "blubb";
+ args << "--changed-files" << "foo,bar";
qbs::CommandLineOptions options;
options.parseCommandLine(args);
QCOMPARE(qbs::Logger::instance().level(), qbs::LoggerDebug);
QCOMPARE(options.command(), qbs::CommandLineOptions::BuildCommand);
+ QCOMPARE(options.selectedProductNames(), QStringList() << "blubb");
+ QCOMPARE(options.changedFiles(), QStringList() << "foo" << "bar");
QVERIFY(options.isKeepGoingSet());
}
+ void testInvalidCommandLine()
+ {
+ qbs::CommandLineOptions options;
+ QVERIFY(!options.parseCommandLine(QStringList() << "-x")); // Unknown short option.
+ QVERIFY(!options.parseCommandLine(QStringList() << "--xyz")); // Unknown long option.
+ QVERIFY(!options.parseCommandLine(QStringList() << "-vjv")); // Invalid position.
+ QVERIFY(!options.parseCommandLine(QStringList() << "-j")); // Missing argument.
+ QVERIFY(!options.parseCommandLine(QStringList() << "-j" << "0")); // Wrong argument.
+ QVERIFY(!options.parseCommandLine(QStringList() << "--products")); // Missing argument.
+ QVERIFY(!options.parseCommandLine(QStringList() << "--changed-files" << ",")); // Wrong argument.
+ }
+
void testFileInfo()
{
QCOMPARE(qbs::FileInfo::fileName("C:/waffl/copter.exe"), QString("copter.exe"));