diff options
author | ccalvarin <ccalvarin@google.com> | 2018-06-20 11:02:36 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-06-20 11:04:09 -0700 |
commit | 83545c37f506434d527b577589bebadf96146b22 (patch) | |
tree | d7ca75c51752750d1d7e3d45e95f4eba4231dda1 /src/test/cpp | |
parent | 07460fc320b774cbd6def67dad983932f7cad1a7 (diff) |
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
Diffstat (limited to 'src/test/cpp')
-rw-r--r-- | src/test/cpp/option_processor_test.cc | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/test/cpp/option_processor_test.cc b/src/test/cpp/option_processor_test.cc index d963fbb98d..6048b80b00 100644 --- a/src/test/cpp/option_processor_test.cc +++ b/src/test/cpp/option_processor_test.cc @@ -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; |