diff options
author | Rui Ueyama <ruiu@google.com> | 2013-08-27 23:47:01 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2013-08-27 23:47:01 +0000 |
commit | 055f4e99ffb32462db6fc62f9a306f2865acacb0 (patch) | |
tree | a3981efdb6d873eebe2916e5eeb789fb0c344f54 /unittests | |
parent | 587e1939fa1bd2bcce764c6dc53263f9faa44ab9 (diff) | |
download | external_llvm-055f4e99ffb32462db6fc62f9a306f2865acacb0.zip external_llvm-055f4e99ffb32462db6fc62f9a306f2865acacb0.tar.gz external_llvm-055f4e99ffb32462db6fc62f9a306f2865acacb0.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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189416 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Option/OptionParsingTest.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/unittests/Option/OptionParsingTest.cpp b/unittests/Option/OptionParsingTest.cpp index 86286d1..11d6d1e 100644 --- a/unittests/Option/OptionParsingTest.cpp +++ b/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; |