aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/CommandLineTest.cpp
diff options
context:
space:
mode:
authorReid Kleckner <reid@kleckner.net>2013-07-18 16:52:05 +0000
committerReid Kleckner <reid@kleckner.net>2013-07-18 16:52:05 +0000
commita73c7781bda66b6a179b39429a22f600593cde77 (patch)
treec498d09dcbb6299d6b613ddeeea5676e6e2943a5 /llvm/unittests/Support/CommandLineTest.cpp
parent047435e0bf9d40df89847b8286ea6c6cf2658baa (diff)
downloadllvm-a73c7781bda66b6a179b39429a22f600593cde77.zip
llvm-a73c7781bda66b6a179b39429a22f600593cde77.tar.gz
llvm-a73c7781bda66b6a179b39429a22f600593cde77.tar.bz2
[Support] Beef up and expose the response file parsing in llvm::cl
The plan is to use it for clang and lld. Major behavior changes: - We can now parse UTF-16 files that have a byte order mark. - PR16209: Don't drop backslashes on the floor if they don't escape anything. The actual parsing loop was based on code from Clang's driver.cpp, although it's been rewritten to track its state with control flow rather than state variables. Reviewers: hans Differential Revision: http://llvm-reviews.chandlerc.com/D1170 llvm-svn: 186587
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
-rw-r--r--llvm/unittests/Support/CommandLineTest.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index cd235d2..7a1c382 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/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,27 @@ TEST(CommandLineTest, UseOptionCategory) {
"Category.";
}
+class StrDupSaver : public cl::StringSaver {
+ const char *SaveString(const char *Str) LLVM_OVERRIDE {
+ return strdup(Str);
+ }
+};
+
+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" };
+ SmallVector<const char *, 0> Actual;
+ StrDupSaver Saver;
+ cl::TokenizeGNUCommandLine(Input, Saver, Actual);
+ EXPECT_EQ(array_lengthof(Output), Actual.size());
+ for (unsigned I = 0, E = Actual.size(); I != E; ++I) {
+ if (I < array_lengthof(Output))
+ EXPECT_STREQ(Output[I], Actual[I]);
+ free(const_cast<char *>(Actual[I]));
+ }
+}
+
} // anonymous namespace