From 1cbe62a09b37f2db76e11ebb18fb46616076ef87 Mon Sep 17 00:00:00 2001 From: ccalvarin Date: Mon, 14 Aug 2017 21:09:07 +0200 Subject: Send Bazel startup options to server. Send the startup options tagged with their origin so that the server has correct information about the command line as the client received it. Removes the unconditional stderr printing of all bazelrc startup options in the bazel client. Instead, the startup options are sent to the server and the same informational printing is gated on the --announce_rc option. This avoids unconditional log spam to stderr early in startup. If the server is unreachable or there are errors parsing startup options, the message is still printed to stderr. Fixes https://github.com/bazelbuild/bazel/issues/2530. RELNOTES: --announce_rc now controls whether bazelrc startup options are printed to stderr. PiperOrigin-RevId: 165211007 --- src/test/cpp/startup_options_test.cc | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'src/test/cpp/startup_options_test.cc') diff --git a/src/test/cpp/startup_options_test.cc b/src/test/cpp/startup_options_test.cc index 164bdc3c90..a4c52a2621 100644 --- a/src/test/cpp/startup_options_test.cc +++ b/src/test/cpp/startup_options_test.cc @@ -155,4 +155,77 @@ TEST_F(StartupOptionsTest, ValidStartupFlagsTest) { SuccessfulIsUnaryTest("output_user_root"); } +TEST_F(StartupOptionsTest, ProcessSpaceSeparatedArgsTest) { + std::string error; + const std::vector flags{ + RcStartupFlag("somewhere", "--max_idle_secs"), + RcStartupFlag("somewhere", "42")}; + + const blaze_exit_code::ExitCode ec = + startup_options_->ProcessArgs(flags, &error); + ASSERT_EQ(blaze_exit_code::SUCCESS, ec) + << "ProcessArgs failed with error " << error; + EXPECT_EQ(42, startup_options_->max_idle_secs); + + EXPECT_EQ("somewhere", startup_options_->original_startup_options_[0].source); + EXPECT_EQ("--max_idle_secs=42", + startup_options_->original_startup_options_[0].value); +} + +TEST_F(StartupOptionsTest, ProcessEqualsSeparatedArgsTest) { + std::string error; + const std::vector flags{ + RcStartupFlag("somewhere", "--max_idle_secs=36")}; + + const blaze_exit_code::ExitCode ec = + startup_options_->ProcessArgs(flags, &error); + ASSERT_EQ(ec, blaze_exit_code::SUCCESS) + << "ProcessArgs failed with error " << error; + EXPECT_EQ(36, startup_options_->max_idle_secs); + + EXPECT_EQ("somewhere", startup_options_->original_startup_options_[0].source); + EXPECT_EQ("--max_idle_secs=36", + startup_options_->original_startup_options_[0].value); +} + +TEST_F(StartupOptionsTest, ProcessIncorrectArgValueTest) { + std::string error; + const std::vector flags{ + RcStartupFlag("somewhere", "--max_idle_secs=notANumber")}; + + const blaze_exit_code::ExitCode ec = + startup_options_->ProcessArgs(flags, &error); + ASSERT_EQ(blaze_exit_code::BAD_ARGV, ec) + << "ProcessArgs failed with the wrong error " << error; + + // Even for a failing args processing step, expect the original value + // to be stored. + EXPECT_EQ("somewhere", startup_options_->original_startup_options_[0].source); + EXPECT_EQ("--max_idle_secs=notANumber", + startup_options_->original_startup_options_[0].value); +} + +TEST_F(StartupOptionsTest, ProcessArgsWithMultipleArgstest) { + const std::vector flags{ + RcStartupFlag("somewhere", "--max_idle_secs=36"), + RcStartupFlag("somewhereElse", "--nowrite_command_log")}; + + std::string error; + const blaze_exit_code::ExitCode ec = + startup_options_->ProcessArgs(flags, &error); + ASSERT_EQ(ec, blaze_exit_code::SUCCESS) + << "ProcessArgs failed with error " << error; + EXPECT_EQ(36, startup_options_->max_idle_secs); + EXPECT_FALSE(startup_options_->write_command_log); + + EXPECT_EQ("somewhere", startup_options_->original_startup_options_[0].source); + EXPECT_EQ("--max_idle_secs=36", + startup_options_->original_startup_options_[0].value); + + EXPECT_EQ("somewhereElse", + startup_options_->original_startup_options_[1].source); + EXPECT_EQ("--nowrite_command_log", + startup_options_->original_startup_options_[1].value); +} + } // namespace blaze -- cgit v1.2.3