aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Option/OptionParsingTest.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2013-08-27 23:47:01 +0000
committerRui Ueyama <ruiu@google.com>2013-08-27 23:47:01 +0000
commit7159bd9dcbca57580abe04289fa61a6ae0af0a6d (patch)
treef57ceb8f63a4ec7887927889f1ecb22314642f95 /llvm/unittests/Option/OptionParsingTest.cpp
parentdba67a226f3a65f6046d7bf77729452a179dc1a5 (diff)
downloadllvm-7159bd9dcbca57580abe04289fa61a6ae0af0a6d.zip
llvm-7159bd9dcbca57580abe04289fa61a6ae0af0a6d.tar.gz
llvm-7159bd9dcbca57580abe04289fa61a6ae0af0a6d.tar.bz2
Option parsing: support case-insensitive option matching.
Link.exe's command line options are case-insensitive. This patch adds a new attribute to OptTable to let the option parser to compare options, ignoring case. Command lines are generally case-insensitive on Windows. CL.exe is an exception. So this new attribute should be useful for other commands running on Windows. Differential Revision: http://llvm-reviews.chandlerc.com/D1485 llvm-svn: 189416
Diffstat (limited to 'llvm/unittests/Option/OptionParsingTest.cpp')
-rw-r--r--llvm/unittests/Option/OptionParsingTest.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/llvm/unittests/Option/OptionParsingTest.cpp b/llvm/unittests/Option/OptionParsingTest.cpp
index 86286d1..11d6d1e 100644
--- a/llvm/unittests/Option/OptionParsingTest.cpp
+++ b/llvm/unittests/Option/OptionParsingTest.cpp
@@ -20,7 +20,7 @@ using namespace llvm::opt;
enum ID {
OPT_INVALID = 0, // This is not an option ID.
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
- HELPTEXT, METAVAR) OPT_##ID,
+ HELPTEXT, METAVAR) OPT_##ID,
#include "Opts.inc"
LastOption
#undef OPTION
@@ -48,8 +48,8 @@ static const OptTable::Info InfoTable[] = {
namespace {
class TestOptTable : public OptTable {
public:
- TestOptTable()
- : OptTable(InfoTable, array_lengthof(InfoTable)) {}
+ TestOptTable(bool IgnoreCase = false)
+ : OptTable(InfoTable, array_lengthof(InfoTable), IgnoreCase) {}
};
}
@@ -157,6 +157,26 @@ TEST(Option, AliasArgs) {
EXPECT_EQ(AL->getAllArgValues(OPT_B)[1], "bar");
}
+TEST(Option, IgnoreCase) {
+ TestOptTable T(true);
+ unsigned MAI, MAC;
+
+ const char *MyArgs[] = { "-a", "-joo" };
+ OwningPtr<InputArgList> AL(T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
+ EXPECT_TRUE(AL->hasArg(OPT_A));
+ EXPECT_TRUE(AL->hasArg(OPT_B));
+}
+
+TEST(Option, DoNotIgnoreCase) {
+ TestOptTable T;
+ unsigned MAI, MAC;
+
+ const char *MyArgs[] = { "-a", "-joo" };
+ OwningPtr<InputArgList> AL(T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
+ EXPECT_FALSE(AL->hasArg(OPT_A));
+ EXPECT_FALSE(AL->hasArg(OPT_B));
+}
+
TEST(Option, SlurpEmpty) {
TestOptTable T;
unsigned MAI, MAC;