X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=unittests%2FSupport%2FCommandLineTest.cpp;h=e0fbf5b09e5787f030beedc8957e586db6cbdede;hb=9561506e34f1f6f358202944167416a450a711f6;hp=750559341cf80c22b213f1357393113168379731;hpb=f96362358fa60eefabed395a309d57c65af0270f;p=oota-llvm.git diff --git a/unittests/Support/CommandLineTest.cpp b/unittests/Support/CommandLineTest.cpp index 750559341cf..e0fbf5b09e5 100644 --- a/unittests/Support/CommandLineTest.cpp +++ b/unittests/Support/CommandLineTest.cpp @@ -10,6 +10,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/Config/config.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/StringSaver.h" #include "gtest/gtest.h" #include #include @@ -35,6 +36,8 @@ class TempEnvVar { #if HAVE_SETENV // Assume setenv and unsetenv come together. unsetenv(name); +#else + (void)name; // Suppress -Wunused-private-field. #endif } @@ -63,21 +66,19 @@ public: StackOption(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) : Base(M0, M1, M2, M3) {} - ~StackOption() { - this->removeArgument(); - } + ~StackOption() override { this->removeArgument(); } }; cl::OptionCategory TestCategory("Test Options", "Description"); -cl::opt TestOption("test-option", cl::desc("old description")); TEST(CommandLineTest, ModifyExisitingOption) { + StackOption TestOption("test-option", cl::desc("old description")); + const char Description[] = "New description"; const char ArgString[] = "new-test-option"; const char ValueString[] = "Integer"; - StringMap Map; - cl::getRegisteredOptions(Map); + StringMap &Map = cl::getRegisteredOptions(); ASSERT_TRUE(Map.count("test-option") == 1) << "Could not find option in map."; @@ -146,26 +147,20 @@ TEST(CommandLineTest, UseOptionCategory) { "Category."; } -class StrDupSaver : public cl::StringSaver { - const char *SaveString(const char *Str) override { - return strdup(Str); - } -}; - -typedef void ParserFunction(StringRef Source, llvm::cl::StringSaver &Saver, +typedef void ParserFunction(StringRef Source, StringSaver &Saver, SmallVectorImpl &NewArgv, bool MarkEOLs); void testCommandLineTokenizer(ParserFunction *parse, const char *Input, const char *const Output[], size_t OutputSize) { SmallVector Actual; - StrDupSaver Saver; + BumpPtrAllocator A; + BumpPtrStringSaver Saver(A); parse(Input, Saver, Actual, /*MarkEOLs=*/false); 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(Actual[I])); } } @@ -231,8 +226,8 @@ TEST(CommandLineTest, AliasRequired) { } TEST(CommandLineTest, HideUnrelatedOptions) { - cl::opt TestOption1("test-option-1"); - cl::opt TestOption2("test-option-2", cl::cat(TestCategory)); + StackOption TestOption1("hide-option-1"); + StackOption TestOption2("hide-option-2", cl::cat(TestCategory)); cl::HideUnrelatedOptions(TestCategory); @@ -241,8 +236,7 @@ TEST(CommandLineTest, HideUnrelatedOptions) { ASSERT_EQ(cl::NotHidden, TestOption2.getOptionHiddenFlag()) << "Hid extra option that should be visable."; - StringMap Map; - cl::getRegisteredOptions(Map); + StringMap &Map = cl::getRegisteredOptions(); ASSERT_EQ(cl::NotHidden, Map["help"]->getOptionHiddenFlag()) << "Hid default option that should be visable."; } @@ -250,11 +244,12 @@ TEST(CommandLineTest, HideUnrelatedOptions) { cl::OptionCategory TestCategory2("Test Options set 2", "Description"); TEST(CommandLineTest, HideUnrelatedOptionsMulti) { - cl::opt TestOption1("test-option-1"); - cl::opt TestOption2("test-option-2", cl::cat(TestCategory)); - cl::opt TestOption3("test-option-3", cl::cat(TestCategory2)); + StackOption TestOption1("multi-hide-option-1"); + StackOption TestOption2("multi-hide-option-2", cl::cat(TestCategory)); + StackOption TestOption3("multi-hide-option-3", cl::cat(TestCategory2)); - cl::OptionCategory *VisibleCategories[] = {&TestCategory, &TestCategory2}; + const cl::OptionCategory *VisibleCategories[] = {&TestCategory, + &TestCategory2}; cl::HideUnrelatedOptions(makeArrayRef(VisibleCategories)); @@ -265,8 +260,7 @@ TEST(CommandLineTest, HideUnrelatedOptionsMulti) { ASSERT_EQ(cl::NotHidden, TestOption3.getOptionHiddenFlag()) << "Hid extra option that should be visable."; - StringMap Map; - cl::getRegisteredOptions(Map); + StringMap &Map = cl::getRegisteredOptions(); ASSERT_EQ(cl::NotHidden, Map["help"]->getOptionHiddenFlag()) << "Hid default option that should be visable."; }