• Home
  • Raw
  • Download

Lines Matching +full:test +full:- +full:cl

1 //===- llvm/unittest/Support/CommandLineTest.cpp - CommandLine tests ------===//
8 //===----------------------------------------------------------------------===//
40 (void)name; // Suppress -Wunused-private-field. in ~TempEnvVar()
49 class StackOption : public cl::opt<T> {
50 typedef cl::opt<T> Base;
69 ~StackOption() override { this->removeArgument(); } in ~StackOption()
72 this->setValue(V); in operator =()
77 class StackSubCommand : public cl::SubCommand {
89 cl::OptionCategory TestCategory("Test Options", "Description");
90 TEST(CommandLineTest, ModifyExisitingOption) { in TEST() function
91 StackOption<int> TestOption("test-option", cl::desc("old description")); in TEST()
94 const char ArgString[] = "new-test-option"; in TEST()
97 StringMap<cl::Option *> &Map = in TEST()
98 cl::getRegisteredOptions(*cl::TopLevelSubCommand); in TEST()
100 ASSERT_TRUE(Map.count("test-option") == 1) << in TEST()
103 cl::Option *Retrieved = Map["test-option"]; in TEST()
106 ASSERT_EQ(&cl::GeneralCategory,Retrieved->Category) << in TEST()
109 Retrieved->setCategory(TestCategory); in TEST()
110 ASSERT_EQ(&TestCategory,Retrieved->Category) << in TEST()
113 Retrieved->setDescription(Description); in TEST()
114 ASSERT_STREQ(Retrieved->HelpStr.data(), Description) in TEST()
117 Retrieved->setArgStr(ArgString); in TEST()
118 ASSERT_STREQ(ArgString, Retrieved->ArgStr.data()) in TEST()
121 Retrieved->setValueStr(ValueString); in TEST()
122 ASSERT_STREQ(Retrieved->ValueStr.data(), ValueString) in TEST()
125 Retrieved->setHiddenFlag(cl::Hidden); in TEST()
126 ASSERT_EQ(cl::Hidden, TestOption.getOptionHiddenFlag()) << in TEST()
133 cl::opt<std::string> EnvironmentTestOption("env-test-opt");
134 TEST(CommandLineTest, ParseEnvironment) { in TEST() function
135 TempEnvVar TEV(test_env_var, "-env-test-opt=hello"); in TEST()
137 cl::ParseEnvironmentOptions("CommandLineTest", test_env_var); in TEST()
141 // This test used to make valgrind complain
146 // SEGFAULT. This can occur because the cl::opt in the test below is declared
147 // on the stack which will be destroyed after the test completes but the
148 // command line system will still hold a pointer to a deallocated cl::Option.
149 TEST(CommandLineTest, ParseEnvironmentToLocalVar) { in TEST() function
150 // Put cl::opt on stack to check for proper initialization of fields. in TEST()
151 StackOption<std::string> EnvironmentTestOptionLocal("env-test-opt-local"); in TEST()
152 TempEnvVar TEV(test_env_var, "-env-test-opt-local=hello-local"); in TEST()
154 cl::ParseEnvironmentOptions("CommandLineTest", test_env_var); in TEST()
155 EXPECT_EQ("hello-local", EnvironmentTestOptionLocal); in TEST()
160 TEST(CommandLineTest, UseOptionCategory) { in TEST() function
161 StackOption<int> TestOption2("test-option", cl::cat(TestCategory)); in TEST()
184 TEST(CommandLineTest, TokenizeGNUCommandLine) { in TEST() function
186 "foo\\ bar \"foo bar\" \'foo bar\' 'foo\\\\bar' -DFOO=bar\\(\\) " in TEST()
190 "-DFOO=bar()", "foobarbaz", "C:\\src\\foo.cpp", "C:srcfoo.cpp"}; in TEST()
191 testCommandLineTokenizer(cl::TokenizeGNUCommandLine, Input, Output, in TEST()
195 TEST(CommandLineTest, TokenizeWindowsCommandLine) { in TEST() function
200 testCommandLineTokenizer(cl::TokenizeWindowsCommandLine, Input, Output, in TEST()
204 TEST(CommandLineTest, AliasesWithArguments) { in TEST() function
207 { "-tool", "-actual=x", "-extra" }, in TEST()
208 { "-tool", "-actual", "x" }, in TEST()
209 { "-tool", "-alias=x", "-extra" }, in TEST()
210 { "-tool", "-alias", "x" } in TEST()
216 StackOption<std::string> Input(cl::Positional); in TEST()
218 cl::alias Alias("alias", llvm::cl::aliasopt(Actual)); in TEST()
220 cl::ParseCommandLineOptions(ARGC, Inputs[i]); in TEST()
229 StackOption<std::string> Option("option", cl::Required); in testAliasRequired()
230 cl::alias Alias("o", llvm::cl::aliasopt(Option)); in testAliasRequired()
232 cl::ParseCommandLineOptions(argc, argv); in testAliasRequired()
239 TEST(CommandLineTest, AliasRequired) { in TEST() function
240 const char *opts1[] = { "-tool", "-option=x" }; in TEST()
241 const char *opts2[] = { "-tool", "-o", "x" }; in TEST()
246 TEST(CommandLineTest, HideUnrelatedOptions) { in TEST() function
247 StackOption<int> TestOption1("hide-option-1"); in TEST()
248 StackOption<int> TestOption2("hide-option-2", cl::cat(TestCategory)); in TEST()
250 cl::HideUnrelatedOptions(TestCategory); in TEST()
252 ASSERT_EQ(cl::ReallyHidden, TestOption1.getOptionHiddenFlag()) in TEST()
254 ASSERT_EQ(cl::NotHidden, TestOption2.getOptionHiddenFlag()) in TEST()
257 StringMap<cl::Option *> &Map = in TEST()
258 cl::getRegisteredOptions(*cl::TopLevelSubCommand); in TEST()
259 ASSERT_EQ(cl::NotHidden, Map["help"]->getOptionHiddenFlag()) in TEST()
263 cl::OptionCategory TestCategory2("Test Options set 2", "Description");
265 TEST(CommandLineTest, HideUnrelatedOptionsMulti) { in TEST() function
266 StackOption<int> TestOption1("multi-hide-option-1"); in TEST()
267 StackOption<int> TestOption2("multi-hide-option-2", cl::cat(TestCategory)); in TEST()
268 StackOption<int> TestOption3("multi-hide-option-3", cl::cat(TestCategory2)); in TEST()
270 const cl::OptionCategory *VisibleCategories[] = {&TestCategory, in TEST()
273 cl::HideUnrelatedOptions(makeArrayRef(VisibleCategories)); in TEST()
275 ASSERT_EQ(cl::ReallyHidden, TestOption1.getOptionHiddenFlag()) in TEST()
277 ASSERT_EQ(cl::NotHidden, TestOption2.getOptionHiddenFlag()) in TEST()
279 ASSERT_EQ(cl::NotHidden, TestOption3.getOptionHiddenFlag()) in TEST()
282 StringMap<cl::Option *> &Map = in TEST()
283 cl::getRegisteredOptions(*cl::TopLevelSubCommand); in TEST()
284 ASSERT_EQ(cl::NotHidden, Map["help"]->getOptionHiddenFlag()) in TEST()
288 TEST(CommandLineTest, SetValueInSubcategories) { in TEST() function
289 cl::ResetCommandLineParser(); in TEST()
294 StackOption<bool> TopLevelOpt("top-level", cl::init(false)); in TEST()
295 StackOption<bool> SC1Opt("sc1", cl::sub(SC1), cl::init(false)); in TEST()
296 StackOption<bool> SC2Opt("sc2", cl::sub(SC2), cl::init(false)); in TEST()
301 const char *args[] = {"prog", "-top-level"}; in TEST()
302 EXPECT_TRUE(cl::ParseCommandLineOptions(2, args, nullptr, true)); in TEST()
309 cl::ResetAllOptionOccurrences(); in TEST()
313 const char *args2[] = {"prog", "sc1", "-sc1"}; in TEST()
314 EXPECT_TRUE(cl::ParseCommandLineOptions(3, args2, nullptr, true)); in TEST()
321 cl::ResetAllOptionOccurrences(); in TEST()
325 const char *args3[] = {"prog", "sc2", "-sc2"}; in TEST()
326 EXPECT_TRUE(cl::ParseCommandLineOptions(3, args3, nullptr, true)); in TEST()
332 TEST(CommandLineTest, LookupFailsInWrongSubCommand) { in TEST() function
333 cl::ResetCommandLineParser(); in TEST()
338 StackOption<bool> SC1Opt("sc1", cl::sub(SC1), cl::init(false)); in TEST()
339 StackOption<bool> SC2Opt("sc2", cl::sub(SC2), cl::init(false)); in TEST()
341 const char *args[] = {"prog", "sc1", "-sc2"}; in TEST()
342 EXPECT_FALSE(cl::ParseCommandLineOptions(3, args, nullptr, true)); in TEST()
345 TEST(CommandLineTest, AddToAllSubCommands) { in TEST() function
346 cl::ResetCommandLineParser(); in TEST()
349 StackOption<bool> AllOpt("everywhere", cl::sub(*cl::AllSubCommands), in TEST()
350 cl::init(false)); in TEST()
353 const char *args[] = {"prog", "-everywhere"}; in TEST()
354 const char *args2[] = {"prog", "sc1", "-everywhere"}; in TEST()
355 const char *args3[] = {"prog", "sc2", "-everywhere"}; in TEST()
358 EXPECT_TRUE(cl::ParseCommandLineOptions(2, args, nullptr, true)); in TEST()
363 cl::ResetAllOptionOccurrences(); in TEST()
365 EXPECT_TRUE(cl::ParseCommandLineOptions(3, args2, nullptr, true)); in TEST()
370 cl::ResetAllOptionOccurrences(); in TEST()
372 EXPECT_TRUE(cl::ParseCommandLineOptions(3, args3, nullptr, true)); in TEST()
376 TEST(CommandLineTest, ReparseCommandLineOptions) { in TEST() function
377 cl::ResetCommandLineParser(); in TEST()
379 StackOption<bool> TopLevelOpt("top-level", cl::sub(*cl::TopLevelSubCommand), in TEST()
380 cl::init(false)); in TEST()
382 const char *args[] = {"prog", "-top-level"}; in TEST()
385 EXPECT_TRUE(cl::ParseCommandLineOptions(2, args, nullptr, true)); in TEST()
390 cl::ResetAllOptionOccurrences(); in TEST()
392 EXPECT_TRUE(cl::ParseCommandLineOptions(2, args, nullptr, true)); in TEST()
396 TEST(CommandLineTest, RemoveFromRegularSubCommand) { in TEST() function
397 cl::ResetCommandLineParser(); in TEST()
400 StackOption<bool> RemoveOption("remove-option", cl::sub(SC), cl::init(false)); in TEST()
401 StackOption<bool> KeepOption("keep-option", cl::sub(SC), cl::init(false)); in TEST()
403 const char *args[] = {"prog", "sc", "-remove-option"}; in TEST()
406 EXPECT_TRUE(cl::ParseCommandLineOptions(3, args, nullptr, true)); in TEST()
411 cl::ResetAllOptionOccurrences(); in TEST()
412 EXPECT_FALSE(cl::ParseCommandLineOptions(3, args, nullptr, true)); in TEST()
415 TEST(CommandLineTest, RemoveFromTopLevelSubCommand) { in TEST() function
416 cl::ResetCommandLineParser(); in TEST()
419 "top-level-remove", cl::sub(*cl::TopLevelSubCommand), cl::init(false)); in TEST()
421 "top-level-keep", cl::sub(*cl::TopLevelSubCommand), cl::init(false)); in TEST()
423 const char *args[] = {"prog", "-top-level-remove"}; in TEST()
426 EXPECT_TRUE(cl::ParseCommandLineOptions(2, args, nullptr, true)); in TEST()
431 cl::ResetAllOptionOccurrences(); in TEST()
432 EXPECT_FALSE(cl::ParseCommandLineOptions(2, args, nullptr, true)); in TEST()
435 TEST(CommandLineTest, RemoveFromAllSubCommands) { in TEST() function
436 cl::ResetCommandLineParser(); in TEST()
440 StackOption<bool> RemoveOption("remove-option", cl::sub(*cl::AllSubCommands), in TEST()
441 cl::init(false)); in TEST()
442 StackOption<bool> KeepOption("keep-option", cl::sub(*cl::AllSubCommands), in TEST()
443 cl::init(false)); in TEST()
445 const char *args0[] = {"prog", "-remove-option"}; in TEST()
446 const char *args1[] = {"prog", "sc1", "-remove-option"}; in TEST()
447 const char *args2[] = {"prog", "sc2", "-remove-option"}; in TEST()
449 // It should work for all subcommands including the top-level. in TEST()
451 EXPECT_TRUE(cl::ParseCommandLineOptions(2, args0, nullptr, true)); in TEST()
456 cl::ResetAllOptionOccurrences(); in TEST()
458 EXPECT_TRUE(cl::ParseCommandLineOptions(3, args1, nullptr, true)); in TEST()
463 cl::ResetAllOptionOccurrences(); in TEST()
465 EXPECT_TRUE(cl::ParseCommandLineOptions(3, args2, nullptr, true)); in TEST()
470 // It should not work for any subcommands including the top-level. in TEST()
471 cl::ResetAllOptionOccurrences(); in TEST()
472 EXPECT_FALSE(cl::ParseCommandLineOptions(2, args0, nullptr, true)); in TEST()
473 cl::ResetAllOptionOccurrences(); in TEST()
474 EXPECT_FALSE(cl::ParseCommandLineOptions(3, args1, nullptr, true)); in TEST()
475 cl::ResetAllOptionOccurrences(); in TEST()
476 EXPECT_FALSE(cl::ParseCommandLineOptions(3, args2, nullptr, true)); in TEST()