diff options
| author | 2017-10-04 20:27:34 +0000 | |
|---|---|---|
| committer | 2017-10-04 20:27:34 +0000 | |
| commit | 31eb748944903b7f4f38afda9851951ca9dfc1ae (patch) | |
| tree | 9b95b6ea45d0874d75eb05b90c0840e191416439 /gnu/llvm/unittests/Support/CommandLineTest.cpp | |
| parent | Don't try to handle IPv4-compatible IPv6 addresses (diff) | |
| download | wireguard-openbsd-31eb748944903b7f4f38afda9851951ca9dfc1ae.tar.xz wireguard-openbsd-31eb748944903b7f4f38afda9851951ca9dfc1ae.zip | |
Import LLVM 5.0.0 release including clang, lld and lldb.
Diffstat (limited to 'gnu/llvm/unittests/Support/CommandLineTest.cpp')
| -rw-r--r-- | gnu/llvm/unittests/Support/CommandLineTest.cpp | 95 |
1 files changed, 69 insertions, 26 deletions
diff --git a/gnu/llvm/unittests/Support/CommandLineTest.cpp b/gnu/llvm/unittests/Support/CommandLineTest.cpp index 945eb1d4e1c..660df11446a 100644 --- a/gnu/llvm/unittests/Support/CommandLineTest.cpp +++ b/gnu/llvm/unittests/Support/CommandLineTest.cpp @@ -7,12 +7,13 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/SmallString.h" +#include "llvm/Support/CommandLine.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallString.h" #include "llvm/Config/config.h" -#include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" +#include "llvm/Support/Program.h" #include "llvm/Support/StringSaver.h" #include "gtest/gtest.h" #include <fstream> @@ -180,8 +181,9 @@ void testCommandLineTokenizer(ParserFunction *parse, StringRef Input, parse(Input, Saver, Actual, /*MarkEOLs=*/false); EXPECT_EQ(OutputSize, Actual.size()); for (unsigned I = 0, E = Actual.size(); I != E; ++I) { - if (I < OutputSize) + if (I < OutputSize) { EXPECT_STREQ(Output[I], Actual[I]); + } } } @@ -303,7 +305,8 @@ TEST(CommandLineTest, SetValueInSubcategories) { EXPECT_FALSE(SC1Opt); EXPECT_FALSE(SC2Opt); const char *args[] = {"prog", "-top-level"}; - EXPECT_TRUE(cl::ParseCommandLineOptions(2, args, StringRef(), true)); + EXPECT_TRUE( + cl::ParseCommandLineOptions(2, args, StringRef(), &llvm::nulls())); EXPECT_TRUE(TopLevelOpt); EXPECT_FALSE(SC1Opt); EXPECT_FALSE(SC2Opt); @@ -315,7 +318,8 @@ TEST(CommandLineTest, SetValueInSubcategories) { EXPECT_FALSE(SC1Opt); EXPECT_FALSE(SC2Opt); const char *args2[] = {"prog", "sc1", "-sc1"}; - EXPECT_TRUE(cl::ParseCommandLineOptions(3, args2, StringRef(), true)); + EXPECT_TRUE( + cl::ParseCommandLineOptions(3, args2, StringRef(), &llvm::nulls())); EXPECT_FALSE(TopLevelOpt); EXPECT_TRUE(SC1Opt); EXPECT_FALSE(SC2Opt); @@ -327,7 +331,8 @@ TEST(CommandLineTest, SetValueInSubcategories) { EXPECT_FALSE(SC1Opt); EXPECT_FALSE(SC2Opt); const char *args3[] = {"prog", "sc2", "-sc2"}; - EXPECT_TRUE(cl::ParseCommandLineOptions(3, args3, StringRef(), true)); + EXPECT_TRUE( + cl::ParseCommandLineOptions(3, args3, StringRef(), &llvm::nulls())); EXPECT_FALSE(TopLevelOpt); EXPECT_FALSE(SC1Opt); EXPECT_TRUE(SC2Opt); @@ -342,8 +347,13 @@ TEST(CommandLineTest, LookupFailsInWrongSubCommand) { StackOption<bool> SC1Opt("sc1", cl::sub(SC1), cl::init(false)); StackOption<bool> SC2Opt("sc2", cl::sub(SC2), cl::init(false)); + std::string Errs; + raw_string_ostream OS(Errs); + const char *args[] = {"prog", "sc1", "-sc2"}; - EXPECT_FALSE(cl::ParseCommandLineOptions(3, args, StringRef(), true)); + EXPECT_FALSE(cl::ParseCommandLineOptions(3, args, StringRef(), &OS)); + OS.flush(); + EXPECT_FALSE(Errs.empty()); } TEST(CommandLineTest, AddToAllSubCommands) { @@ -358,23 +368,30 @@ TEST(CommandLineTest, AddToAllSubCommands) { const char *args2[] = {"prog", "sc1", "-everywhere"}; const char *args3[] = {"prog", "sc2", "-everywhere"}; + std::string Errs; + raw_string_ostream OS(Errs); + EXPECT_FALSE(AllOpt); - EXPECT_TRUE(cl::ParseCommandLineOptions(2, args, StringRef(), true)); + EXPECT_TRUE(cl::ParseCommandLineOptions(2, args, StringRef(), &OS)); EXPECT_TRUE(AllOpt); AllOpt = false; cl::ResetAllOptionOccurrences(); EXPECT_FALSE(AllOpt); - EXPECT_TRUE(cl::ParseCommandLineOptions(3, args2, StringRef(), true)); + EXPECT_TRUE(cl::ParseCommandLineOptions(3, args2, StringRef(), &OS)); EXPECT_TRUE(AllOpt); AllOpt = false; cl::ResetAllOptionOccurrences(); EXPECT_FALSE(AllOpt); - EXPECT_TRUE(cl::ParseCommandLineOptions(3, args3, StringRef(), true)); + EXPECT_TRUE(cl::ParseCommandLineOptions(3, args3, StringRef(), &OS)); EXPECT_TRUE(AllOpt); + + // Since all parsing succeeded, the error message should be empty. + OS.flush(); + EXPECT_TRUE(Errs.empty()); } TEST(CommandLineTest, ReparseCommandLineOptions) { @@ -386,14 +403,16 @@ TEST(CommandLineTest, ReparseCommandLineOptions) { const char *args[] = {"prog", "-top-level"}; EXPECT_FALSE(TopLevelOpt); - EXPECT_TRUE(cl::ParseCommandLineOptions(2, args, StringRef(), true)); + EXPECT_TRUE( + cl::ParseCommandLineOptions(2, args, StringRef(), &llvm::nulls())); EXPECT_TRUE(TopLevelOpt); TopLevelOpt = false; cl::ResetAllOptionOccurrences(); EXPECT_FALSE(TopLevelOpt); - EXPECT_TRUE(cl::ParseCommandLineOptions(2, args, StringRef(), true)); + EXPECT_TRUE( + cl::ParseCommandLineOptions(2, args, StringRef(), &llvm::nulls())); EXPECT_TRUE(TopLevelOpt); } @@ -406,14 +425,21 @@ TEST(CommandLineTest, RemoveFromRegularSubCommand) { const char *args[] = {"prog", "sc", "-remove-option"}; + std::string Errs; + raw_string_ostream OS(Errs); + EXPECT_FALSE(RemoveOption); - EXPECT_TRUE(cl::ParseCommandLineOptions(3, args, StringRef(), true)); + EXPECT_TRUE(cl::ParseCommandLineOptions(3, args, StringRef(), &OS)); EXPECT_TRUE(RemoveOption); + OS.flush(); + EXPECT_TRUE(Errs.empty()); RemoveOption.removeArgument(); cl::ResetAllOptionOccurrences(); - EXPECT_FALSE(cl::ParseCommandLineOptions(3, args, StringRef(), true)); + EXPECT_FALSE(cl::ParseCommandLineOptions(3, args, StringRef(), &OS)); + OS.flush(); + EXPECT_FALSE(Errs.empty()); } TEST(CommandLineTest, RemoveFromTopLevelSubCommand) { @@ -427,13 +453,15 @@ TEST(CommandLineTest, RemoveFromTopLevelSubCommand) { const char *args[] = {"prog", "-top-level-remove"}; EXPECT_FALSE(TopLevelRemove); - EXPECT_TRUE(cl::ParseCommandLineOptions(2, args, StringRef(), true)); + EXPECT_TRUE( + cl::ParseCommandLineOptions(2, args, StringRef(), &llvm::nulls())); EXPECT_TRUE(TopLevelRemove); TopLevelRemove.removeArgument(); cl::ResetAllOptionOccurrences(); - EXPECT_FALSE(cl::ParseCommandLineOptions(2, args, StringRef(), true)); + EXPECT_FALSE( + cl::ParseCommandLineOptions(2, args, StringRef(), &llvm::nulls())); } TEST(CommandLineTest, RemoveFromAllSubCommands) { @@ -452,32 +480,38 @@ TEST(CommandLineTest, RemoveFromAllSubCommands) { // It should work for all subcommands including the top-level. EXPECT_FALSE(RemoveOption); - EXPECT_TRUE(cl::ParseCommandLineOptions(2, args0, StringRef(), true)); + EXPECT_TRUE( + cl::ParseCommandLineOptions(2, args0, StringRef(), &llvm::nulls())); EXPECT_TRUE(RemoveOption); RemoveOption = false; cl::ResetAllOptionOccurrences(); EXPECT_FALSE(RemoveOption); - EXPECT_TRUE(cl::ParseCommandLineOptions(3, args1, StringRef(), true)); + EXPECT_TRUE( + cl::ParseCommandLineOptions(3, args1, StringRef(), &llvm::nulls())); EXPECT_TRUE(RemoveOption); RemoveOption = false; cl::ResetAllOptionOccurrences(); EXPECT_FALSE(RemoveOption); - EXPECT_TRUE(cl::ParseCommandLineOptions(3, args2, StringRef(), true)); + EXPECT_TRUE( + cl::ParseCommandLineOptions(3, args2, StringRef(), &llvm::nulls())); EXPECT_TRUE(RemoveOption); RemoveOption.removeArgument(); // It should not work for any subcommands including the top-level. cl::ResetAllOptionOccurrences(); - EXPECT_FALSE(cl::ParseCommandLineOptions(2, args0, StringRef(), true)); + EXPECT_FALSE( + cl::ParseCommandLineOptions(2, args0, StringRef(), &llvm::nulls())); cl::ResetAllOptionOccurrences(); - EXPECT_FALSE(cl::ParseCommandLineOptions(3, args1, StringRef(), true)); + EXPECT_FALSE( + cl::ParseCommandLineOptions(3, args1, StringRef(), &llvm::nulls())); cl::ResetAllOptionOccurrences(); - EXPECT_FALSE(cl::ParseCommandLineOptions(3, args2, StringRef(), true)); + EXPECT_FALSE( + cl::ParseCommandLineOptions(3, args2, StringRef(), &llvm::nulls())); } TEST(CommandLineTest, GetRegisteredSubcommands) { @@ -491,24 +525,33 @@ TEST(CommandLineTest, GetRegisteredSubcommands) { const char *args0[] = {"prog", "sc1"}; const char *args1[] = {"prog", "sc2"}; - EXPECT_TRUE(cl::ParseCommandLineOptions(2, args0, StringRef(), true)); + EXPECT_TRUE( + cl::ParseCommandLineOptions(2, args0, StringRef(), &llvm::nulls())); EXPECT_FALSE(Opt1); EXPECT_FALSE(Opt2); for (auto *S : cl::getRegisteredSubcommands()) { - if (*S) + if (*S) { EXPECT_EQ("sc1", S->getName()); + } } cl::ResetAllOptionOccurrences(); - EXPECT_TRUE(cl::ParseCommandLineOptions(2, args1, StringRef(), true)); + EXPECT_TRUE( + cl::ParseCommandLineOptions(2, args1, StringRef(), &llvm::nulls())); EXPECT_FALSE(Opt1); EXPECT_FALSE(Opt2); for (auto *S : cl::getRegisteredSubcommands()) { - if (*S) + if (*S) { EXPECT_EQ("sc2", S->getName()); + } } } +TEST(CommandLineTest, ArgumentLimit) { + std::string args(32 * 4096, 'a'); + EXPECT_FALSE(llvm::sys::commandLineFitsWithinSystemLimits("cl", args.data())); +} + TEST(CommandLineTest, ResponseFiles) { llvm::SmallString<128> TestDir; std::error_code EC = |
