diff options
author | Stephen Hines <srhines@google.com> | 2013-08-07 15:07:10 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2013-08-07 15:07:10 -0700 |
commit | fab2daa4a1127ecb217abe2b07c1769122b6fee1 (patch) | |
tree | 268ebfd1963fd98ba412e76819afdf95a7d4267b /unittests/Support/CommandLineTest.cpp | |
parent | 8197ac1c1a0a91baa70c4dea8cb488f254ef974c (diff) | |
parent | 10251753b6897adcd22cc981c0cc42f348c109de (diff) | |
download | external_llvm-fab2daa4a1127ecb217abe2b07c1769122b6fee1.zip external_llvm-fab2daa4a1127ecb217abe2b07c1769122b6fee1.tar.gz external_llvm-fab2daa4a1127ecb217abe2b07c1769122b6fee1.tar.bz2 |
Merge commit '10251753b6897adcd22cc981c0cc42f348c109de' into merge-20130807
Conflicts:
lib/Archive/ArchiveReader.cpp
lib/Support/Unix/PathV2.inc
Change-Id: I29d8c1e321a4a380b6013f00bac6a8e4b593cc4e
Diffstat (limited to 'unittests/Support/CommandLineTest.cpp')
-rw-r--r-- | unittests/Support/CommandLineTest.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/unittests/Support/CommandLineTest.cpp b/unittests/Support/CommandLineTest.cpp index cd235d2..c54e1b9 100644 --- a/unittests/Support/CommandLineTest.cpp +++ b/unittests/Support/CommandLineTest.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/STLExtras.h" #include "llvm/Support/CommandLine.h" #include "llvm/Config/config.h" #include "gtest/gtest.h" @@ -118,4 +119,46 @@ TEST(CommandLineTest, UseOptionCategory) { "Category."; } +class StrDupSaver : public cl::StringSaver { + const char *SaveString(const char *Str) LLVM_OVERRIDE { + return strdup(Str); + } +}; + +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; + parse(Input, Saver, Actual); + EXPECT_EQ(OutputSize, Actual.size()); + for (unsigned I = 0, E = Actual.size(); I != E; ++I) { + 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 |