#include "llvm/Support/CommandLine.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Config/config.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/TargetParser/Triple.h"
#include "llvm/Testing/Support/SupportHelpers.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <fstream>
#include <stdlib.h>
#include <string>
usingnamespacellvm;
TempDir;
TempFile;
namespace {
MATCHER(StringEquality, "Checks if two char* are equal as strings") { … }
class TempEnvVar { … };
template <typename T, typename Base = cl::opt<T>>
class StackOption : public Base {
public:
template <class... Ts>
explicit StackOption(Ts &&... Ms) : Base(std::forward<Ts>(Ms)...) { … }
~StackOption() override { … }
template <class DT> StackOption<T> &operator=(const DT &V) { … }
};
class StackSubCommand : public cl::SubCommand { … };
cl::OptionCategory TestCategory("Test Options", "Description");
TEST(CommandLineTest, ModifyExisitingOption) { … }
TEST(CommandLineTest, UseOptionCategory) { … }
TEST(CommandLineTest, UseMultipleCategories) { … }
ParserFunction;
void testCommandLineTokenizer(ParserFunction *parse, StringRef Input,
ArrayRef<const char *> Output,
bool MarkEOLs = false) { … }
TEST(CommandLineTest, TokenizeGNUCommandLine) { … }
TEST(CommandLineTest, TokenizeWindowsCommandLine1) { … }
TEST(CommandLineTest, TokenizeWindowsCommandLine2) { … }
TEST(CommandLineTest, TokenizeWindowsCommandLineQuotedLastArgument) { … }
TEST(CommandLineTest, TokenizeWindowsCommandLineExeName) { … }
TEST(CommandLineTest, TokenizeAndMarkEOLs) { … }
TEST(CommandLineTest, TokenizeConfigFile1) { … }
TEST(CommandLineTest, TokenizeConfigFile2) { … }
TEST(CommandLineTest, TokenizeConfigFile3) { … }
TEST(CommandLineTest, TokenizeConfigFile4) { … }
TEST(CommandLineTest, TokenizeConfigFile5) { … }
TEST(CommandLineTest, TokenizeConfigFile6) { … }
TEST(CommandLineTest, TokenizeConfigFile7) { … }
TEST(CommandLineTest, TokenizeConfigFile8) { … }
TEST(CommandLineTest, TokenizeConfigFile9) { … }
TEST(CommandLineTest, TokenizeConfigFile10) { … }
TEST(CommandLineTest, TokenizeConfigFile11) { … }
TEST(CommandLineTest, AliasesWithArguments) { … }
void testAliasRequired(int argc, const char *const *argv) { … }
TEST(CommandLineTest, AliasRequired) { … }
TEST(CommandLineTest, HideUnrelatedOptions) { … }
cl::OptionCategory TestCategory2("Test Options set 2", "Description");
TEST(CommandLineTest, HideUnrelatedOptionsMulti) { … }
TEST(CommandLineTest, SetMultiValues) { … }
TEST(CommandLineTest, SetValueInSubcategories) { … }
TEST(CommandLineTest, LookupFailsInWrongSubCommand) { … }
TEST(CommandLineTest, TopLevelOptInSubcommand) { … }
TEST(CommandLineTest, AddToAllSubCommands) { … }
TEST(CommandLineTest, ReparseCommandLineOptions) { … }
TEST(CommandLineTest, RemoveFromRegularSubCommand) { … }
TEST(CommandLineTest, RemoveFromTopLevelSubCommand) { … }
TEST(CommandLineTest, RemoveFromAllSubCommands) { … }
TEST(CommandLineTest, GetRegisteredSubcommands) { … }
TEST(CommandLineTest, DefaultOptions) { … }
TEST(CommandLineTest, ArgumentLimit) { … }
TEST(CommandLineTest, ArgumentLimitWindows) { … }
TEST(CommandLineTest, ResponseFileWindows) { … }
TEST(CommandLineTest, ResponseFiles) { … }
TEST(CommandLineTest, RecursiveResponseFiles) { … }
TEST(CommandLineTest, ResponseFilesAtArguments) { … }
TEST(CommandLineTest, ResponseFileRelativePath) { … }
TEST(CommandLineTest, ResponseFileEOLs) { … }
TEST(CommandLineTest, BadResponseFile) { … }
TEST(CommandLineTest, SetDefaultValue) { … }
TEST(CommandLineTest, ReadConfigFile) { … }
TEST(CommandLineTest, PositionalEatArgsError) { … }
#ifdef _WIN32
void checkSeparators(StringRef Path) {
char UndesiredSeparator = sys::path::get_separator()[0] == '/' ? '\\' : '/';
ASSERT_EQ(Path.find(UndesiredSeparator), StringRef::npos);
}
TEST(CommandLineTest, GetCommandLineArguments) {
int argc = __argc;
char **argv = __argv;
llvm::InitLLVM X(argc, argv);
EXPECT_EQ(llvm::sys::path::is_absolute(argv[0]),
llvm::sys::path::is_absolute(__argv[0]));
checkSeparators(argv[0]);
EXPECT_TRUE(
llvm::sys::path::filename(argv[0]).equals_insensitive("supporttests.exe"))
<< "Filename of test executable is "
<< llvm::sys::path::filename(argv[0]);
}
#endif
class OutputRedirector { … };
struct AutoDeleteFile { … };
static std::string interceptStdout(std::function<void()> F) { … }
template <void (*Func)(const cl::Option &)>
class PrintOptionTestBase : public ::testing::Test { … };
void printOptionInfo(const cl::Option &O) { … }
PrintOptionInfoTest;
TEST_F(PrintOptionInfoTest, PrintOptionInfoValueOptionalWithoutSentinel) { … }
TEST_F(PrintOptionInfoTest, PrintOptionInfoValueOptionalWithSentinel) { … }
TEST_F(PrintOptionInfoTest, PrintOptionInfoValueOptionalWithSentinelWithHelp) { … }
TEST_F(PrintOptionInfoTest, PrintOptionInfoValueRequiredWithEmptyValueName) { … }
TEST_F(PrintOptionInfoTest, PrintOptionInfoEmptyValueDescription) { … }
TEST_F(PrintOptionInfoTest, PrintOptionInfoMultilineValueDescription) { … }
void printOptionValue(const cl::Option &O) { … }
PrintOptionValueTest;
TEST_F(PrintOptionValueTest, PrintOptionDefaultValue) { … }
TEST_F(PrintOptionValueTest, PrintOptionNoDefaultValue) { … }
TEST_F(PrintOptionValueTest, PrintOptionUnknownValue) { … }
class GetOptionWidthTest : public ::testing::Test { … };
TEST_F(GetOptionWidthTest, GetOptionWidthArgNameLonger) { … }
TEST_F(GetOptionWidthTest, GetOptionWidthFirstOptionNameLonger) { … }
TEST_F(GetOptionWidthTest, GetOptionWidthSecondOptionNameLonger) { … }
TEST_F(GetOptionWidthTest, GetOptionWidthEmptyOptionNameLonger) { … }
TEST_F(GetOptionWidthTest,
GetOptionWidthValueOptionalEmptyOptionWithNoDescription) { … }
TEST_F(GetOptionWidthTest,
GetOptionWidthValueRequiredEmptyOptionWithNoDescription) { … }
TEST(CommandLineTest, PrefixOptions) { … }
TEST(CommandLineTest, GroupingWithValue) { … }
TEST(CommandLineTest, GroupingAndPrefix) { … }
TEST(CommandLineTest, LongOptions) { … }
TEST(CommandLineTest, OptionErrorMessage) { … }
TEST(CommandLineTest, OptionErrorMessageSuggest) { … }
TEST(CommandLineTest, OptionErrorMessageSuggestNoHidden) { … }
TEST(CommandLineTest, Callback) { … }
enum Enum { … };
static cl::bits<Enum> ExampleBits(
cl::desc("An example cl::bits to ensure it compiles"),
cl::values(
clEnumValN(Val1, "bits-val1", "The Val1 value"),
clEnumValN(Val1, "bits-val2", "The Val2 value")));
TEST(CommandLineTest, ConsumeAfterOnePositional) { … }
TEST(CommandLineTest, ConsumeAfterTwoPositionals) { … }
TEST(CommandLineTest, ResetAllOptionOccurrences) { … }
TEST(CommandLineTest, DefaultValue) { … }
TEST(CommandLineTest, HelpWithoutSubcommands) { … }
TEST(CommandLineTest, HelpWithSubcommands) { … }
TEST(CommandLineTest, UnknownCommands) { … }
TEST(CommandLineTest, SubCommandGroups) { … }
TEST(CommandLineTest, HelpWithEmptyCategory) { … }
}