Add better tests for the -h and -help accepted values. It looks like this test was intended to add coverage for these option-like values that we accept as commands, but it did not actually test this. RELNOTES: None. PiperOrigin-RevId: 201380534
diff --git a/src/test/cpp/option_processor_test.cc b/src/test/cpp/option_processor_test.cc index d963fbb..6048b80 100644 --- a/src/test/cpp/option_processor_test.cc +++ b/src/test/cpp/option_processor_test.cc
@@ -78,6 +78,19 @@ EXPECT_EQ(expected.command_args, result->command_args); } + void HelpArgIsInterpretedAsACommand(const std::string& arg) { + const std::vector<std::string> args = {"bazel", arg}; + std::string error; + ASSERT_EQ(blaze_exit_code::SUCCESS, + option_processor_->ParseOptions(args, workspace_, cwd_, &error)) + << error; + ASSERT_EQ("", error); + + EXPECT_EQ(arg, option_processor_->GetCommand()); + EXPECT_EQ(std::vector<std::string>({}), + option_processor_->GetExplicitCommandArguments()); + } + const std::string workspace_; const std::string cwd_; const std::unique_ptr<WorkspaceLayout> workspace_layout_; @@ -108,7 +121,7 @@ option_processor_->GetExplicitCommandArguments()); } -TEST_F(OptionProcessorTest, CanParseHelpArgs) { +TEST_F(OptionProcessorTest, CanParseHelpCommandSurroundedByOtherArgs) { const std::vector<std::string> args = {"bazel", "--host_jvm_args=MyParam", "--nobatch", @@ -132,6 +145,18 @@ option_processor_->GetExplicitCommandArguments()); } +TEST_F(OptionProcessorTest, CanParseHelpCommand) { + HelpArgIsInterpretedAsACommand("help"); +} + +TEST_F(OptionProcessorTest, CanParseHelpShortFlag) { + HelpArgIsInterpretedAsACommand("-h"); +} + +TEST_F(OptionProcessorTest, CanParseHelpFlag) { + HelpArgIsInterpretedAsACommand("-help"); +} + TEST_F(OptionProcessorTest, CanParseEmptyArgs) { const std::vector<std::string> args = {"bazel"}; std::string error;