diff options
Diffstat (limited to 'tests/auto/utils/commandline/tst_commandline.cpp')
-rw-r--r-- | tests/auto/utils/commandline/tst_commandline.cpp | 81 |
1 files changed, 79 insertions, 2 deletions
diff --git a/tests/auto/utils/commandline/tst_commandline.cpp b/tests/auto/utils/commandline/tst_commandline.cpp index 05357d2526e..2691b1e84ad 100644 --- a/tests/auto/utils/commandline/tst_commandline.cpp +++ b/tests/auto/utils/commandline/tst_commandline.cpp @@ -7,8 +7,9 @@ #include <utils/environment.h> #include <utils/hostosinfo.h> #include <utils/launcherinterface.h> +#include <utils/macroexpander.h> +#include <utils/process.h> #include <utils/processinterface.h> -#include <utils/qtcprocess.h> #include <utils/temporarydirectory.h> #include <QObject> @@ -29,7 +30,7 @@ private: QString run(const CommandLine &cmd) { - QtcProcess p; + Process p; p.setCommand(cmd); p.setEnvironment(testEnv); p.runBlocking(); @@ -123,6 +124,82 @@ private slots: QString actual = run(shell); QCOMPARE(actual, expected); } + + void testFromUserInput_data() + { + QTest::addColumn<QString>("input"); + QTest::addColumn<QString>("executable"); + QTest::addColumn<QString>("arguments"); + + QTest::newRow("empty") << "" + << "" + << ""; + QTest::newRow("command") << "command" + << "command" + << ""; + QTest::newRow("command-with-args") << "command and args" + << "command" + << "and args"; + + if (!HostOsInfo::isWindowsHost()) { + QTest::newRow("command-with-space-slash") << "command\\ with-space and args" + << "command with-space" + << "and args"; + QTest::newRow("command-with-space-single-quote") << "'command with-space' and args" + << "command with-space" + << "and args"; + } + QTest::newRow("command-with-space-double-quote") << "\"command with-space\" and args" + << "command with-space" + << "and args"; + + QTest::newRow("command-with-space-double-quote-in-name") + << "\"command\\\"with-quote\" and args" + << "command\"with-quote" + << "and args"; + + QTest::newRow("inside-space-quoted") << "command\" \"withspace args here" + << "command withspace" + << "args here"; + } + + void testFromUserInput() + { + QFETCH(QString, input); + QFETCH(QString, executable); + QFETCH(QString, arguments); + + CommandLine cmd = CommandLine::fromUserInput(input); + QCOMPARE(cmd.executable(), FilePath::fromUserInput(executable)); + QCOMPARE(cmd.arguments(), arguments); + } + + void testFromInputFails() + { + if (HostOsInfo::isWindowsHost()) + QSKIP("The test does not work on Windows."); + + CommandLine cmd = CommandLine::fromUserInput("command\\\\\\ with-space and args"); + QEXPECT_FAIL("", + "CommandLine::fromUserInput (and FilePath::fromUserInput) does not handle " + "backslashes correctly", + Continue); + QCOMPARE(cmd.executable().fileName(), "command\\ with-space"); + QCOMPARE(cmd.arguments(), "and args"); + } + + void testFromInputWithMacro() + { + MacroExpander expander; + expander.registerVariable("hello", "world var", [] { return "hello world"; }); + CommandLine cmd = CommandLine::fromUserInput("command macroarg: %{hello}", &expander); + QCOMPARE(cmd.executable(), "command"); + + if (HostOsInfo::isWindowsHost()) + QEXPECT_FAIL("", "Windows does not correctly quote macro arguments", Continue); + + QCOMPARE(cmd.arguments(), "macroarg: 'hello world'"); + } }; int main(int argc, char *argv[]) |