aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/CommandLineTest.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2013-07-30 19:03:20 +0000
committerRui Ueyama <ruiu@google.com>2013-07-30 19:03:20 +0000
commita2222b573b2bd3bb03936d1cad31d921ee42416c (patch)
tree216a142d6c23366c1c5ab8ed6c057c0637a76c21 /llvm/unittests/Support/CommandLineTest.cpp
parentb162939c1a3e360ce128997223acd1eadc696d83 (diff)
downloadllvm-a2222b573b2bd3bb03936d1cad31d921ee42416c.zip
llvm-a2222b573b2bd3bb03936d1cad31d921ee42416c.tar.gz
llvm-a2222b573b2bd3bb03936d1cad31d921ee42416c.tar.bz2
Implement TokenizeWindowsCommandLine.
This is a follow up patch for r187390 to implement the parser for the Windows-style command line. This should follow the rule as described at http://msdn.microsoft.com/en-us/library/windows/desktop/17w5ykft(v=vs.85).aspx Differential Revision: http://llvm-reviews.chandlerc.com/D1235 llvm-svn: 187430
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
-rw-r--r--llvm/unittests/Support/CommandLineTest.cpp37
1 files changed, 28 insertions, 9 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index 7a1c382..c54e1b9 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -125,21 +125,40 @@ class StrDupSaver : public cl::StringSaver {
}
};
-TEST(CommandLineTest, TokenizeGNUCommandLine) {
- const char *Input = "foo\\ bar \"foo bar\" \'foo bar\' 'foo\\\\bar' "
- "foo\"bar\"baz C:\\src\\foo.cpp \"C:\\src\\foo.cpp\"";
- const char *const Output[] = { "foo bar", "foo bar", "foo bar", "foo\\bar",
- "foobarbaz", "C:\\src\\foo.cpp",
- "C:\\src\\foo.cpp" };
+typedef void ParserFunction(StringRef Source, llvm::cl::StringSaver &Saver,
+ SmallVectorImpl<const char *> &NewArgv);
+
+
+void testCommandLineTokenizer(ParserFunction *parse, const char *Input,
+ const char *const Output[], size_t OutputSize) {
SmallVector<const char *, 0> Actual;
StrDupSaver Saver;
- cl::TokenizeGNUCommandLine(Input, Saver, Actual);
- EXPECT_EQ(array_lengthof(Output), Actual.size());
+ parse(Input, Saver, Actual);
+ EXPECT_EQ(OutputSize, Actual.size());
for (unsigned I = 0, E = Actual.size(); I != E; ++I) {
- if (I < array_lengthof(Output))
+ if (I < OutputSize)
EXPECT_STREQ(Output[I], Actual[I]);
free(const_cast<char *>(Actual[I]));
}
}
+TEST(CommandLineTest, TokenizeGNUCommandLine) {
+ const char *Input = "foo\\ bar \"foo bar\" \'foo bar\' 'foo\\\\bar' "
+ "foo\"bar\"baz C:\\src\\foo.cpp \"C:\\src\\foo.cpp\"";
+ const char *const Output[] = { "foo bar", "foo bar", "foo bar", "foo\\bar",
+ "foobarbaz", "C:\\src\\foo.cpp",
+ "C:\\src\\foo.cpp" };
+ testCommandLineTokenizer(cl::TokenizeGNUCommandLine, Input, Output,
+ array_lengthof(Output));
+}
+
+TEST(CommandLineTest, TokenizeWindowsCommandLine) {
+ const char *Input = "a\\b c\\\\d e\\\\\"f g\" h\\\"i j\\\\\\\"k \"lmn\" o pqr "
+ "\"st \\\"u\" \\v";
+ const char *const Output[] = { "a\\b", "c\\\\d", "e\\f g", "h\"i", "j\\\"k",
+ "lmn", "o", "pqr", "st \"u", "\\v" };
+ testCommandLineTokenizer(cl::TokenizeWindowsCommandLine, Input, Output,
+ array_lengthof(Output));
+}
+
} // anonymous namespace