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.
@@ -78,6 +78,19 @@ class OptionProcessorTest : public ::testing::Test {
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 @@ TEST_F(OptionProcessorTest, CanParseOptions) {
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 @@ TEST_F(OptionProcessorTest, CanParseHelpArgs) {
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;
