aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/cpp
diff options
context:
space:
mode:
authorGravatar ccalvarin <ccalvarin@google.com>2018-04-19 08:47:28 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-19 08:49:16 -0700
commitd8dfd7882585fafc2be60d42ae996a4a536ac469 (patch)
treefc536b0521b0443ce2f6fd067ef0030a7d79199f /src/test/cpp
parent3b644d6ba753350165841feadf12a1f401329ee1 (diff)
Refactor where rc files are controlled.
In preparation for https://github.com/bazelbuild/bazel/issues/4502, make OptionProcessor::GetRcFiles contain the logic for both the user bazelrcs and the master bazelrcs. RELNOTES: None PiperOrigin-RevId: 193521683
Diffstat (limited to 'src/test/cpp')
-rw-r--r--src/test/cpp/BUILD1
-rw-r--r--src/test/cpp/option_processor_test.cc41
-rw-r--r--src/test/cpp/workspace_layout_test.cc27
3 files changed, 42 insertions, 27 deletions
diff --git a/src/test/cpp/BUILD b/src/test/cpp/BUILD
index 782d1814b0..09bb3b1b0b 100644
--- a/src/test/cpp/BUILD
+++ b/src/test/cpp/BUILD
@@ -34,6 +34,7 @@ cc_test(
deps = [
"//src/main/cpp:blaze_util",
"//src/main/cpp:option_processor",
+ "//src/main/cpp:rc_file",
"//src/main/cpp:workspace_layout",
"//src/main/cpp/util",
"@com_google_googletest//:gtest_main",
diff --git a/src/test/cpp/option_processor_test.cc b/src/test/cpp/option_processor_test.cc
index 9f64e5213a..19c5d34e4d 100644
--- a/src/test/cpp/option_processor_test.cc
+++ b/src/test/cpp/option_processor_test.cc
@@ -17,6 +17,7 @@
#include "src/main/cpp/blaze_util.h"
#include "src/main/cpp/blaze_util_platform.h"
#include "src/main/cpp/option_processor-internal.h"
+#include "src/main/cpp/rc_file.h"
#include "src/main/cpp/util/file.h"
#include "src/main/cpp/util/file_platform.h"
#include "src/main/cpp/workspace_layout.h"
@@ -168,6 +169,46 @@ TEST_F(OptionProcessorTest, CanParseDifferentStartupArgs) {
option_processor_->GetExplicitCommandArguments());
}
+TEST_F(OptionProcessorTest, GetRcFilesLoadsAllMasterBazelrcs) {
+ // We only test 2 of the 3 master bazelrc locations in this test. The third
+ // masterrc that should be loaded is the system wide blazerc path,
+ // /etc/bazel.bazelrc, which we do not mock within this test because it is not
+ // within the sandbox. It may or may not exist on the system running the test,
+ // so we do not check for it.
+ // TODO(#4502): Make the system-wide master bazelrc location configurable and
+ // add test coverage for it.
+ const std::string binary_dir = blaze_util::JoinPath(workspace_, "bazeldir");
+ const std::string tools_dir = blaze_util::JoinPath(workspace_, "tools");
+ const std::string workspace_rc_path =
+ blaze_util::JoinPath(tools_dir, "bazel.rc");
+ const std::string binary_rc_path =
+ blaze_util::JoinPath(binary_dir, "bazel.bazelrc");
+ const std::string binary_path = blaze_util::JoinPath(binary_dir, "bazel");
+ ASSERT_TRUE(blaze_util::MakeDirectories(binary_dir, 0755));
+ ASSERT_TRUE(blaze_util::MakeDirectories(tools_dir, 0755));
+ ASSERT_TRUE(blaze_util::WriteFile("", workspace_rc_path, 0755));
+ ASSERT_TRUE(blaze_util::WriteFile("", binary_rc_path, 0755));
+
+ const CommandLine cmd_line =
+ CommandLine(binary_path, {"--bazelrc=/dev/null"}, "build", {});
+ std::string error = "check that this string is not modified";
+ std::vector<std::unique_ptr<RcFile>> parsed_rcs;
+ const blaze_exit_code::ExitCode exit_code =
+ option_processor_->GetRcFiles(workspace_layout_.get(), workspace_, cwd_,
+ &cmd_line, &parsed_rcs, &error);
+ EXPECT_EQ(blaze_exit_code::SUCCESS, exit_code);
+ EXPECT_EQ("check that this string is not modified", error);
+
+ // There should be 3-4 rc files, "/dev/null" does in some sense count as a
+ // file, and there's an optional /etc/ file the test environment cannot
+ // control. The first 2 rcs parsed should be the two rc files we expect.
+ ASSERT_LT(2, parsed_rcs.size());
+ const std::deque<std::string> expected_workspace_src = {workspace_rc_path};
+ const std::deque<std::string> expected_binary_src = {binary_rc_path};
+ EXPECT_EQ(expected_workspace_src, parsed_rcs[0].get()->sources());
+ EXPECT_EQ(expected_binary_src, parsed_rcs[1].get()->sources());
+}
+
TEST_F(OptionProcessorTest, CommandLineBazelrcTest) {
const std::string cmdline_rc_path =
blaze_util::JoinPath(workspace_, "mybazelrc");
diff --git a/src/test/cpp/workspace_layout_test.cc b/src/test/cpp/workspace_layout_test.cc
index 98e157b0dd..8ac4fcb94a 100644
--- a/src/test/cpp/workspace_layout_test.cc
+++ b/src/test/cpp/workspace_layout_test.cc
@@ -67,31 +67,4 @@ TEST_F(WorkspaceLayoutTest, GetWorkspace) {
ASSERT_EQ(build_root_, workspace_layout_->GetWorkspace(cwd));
}
-TEST_F(WorkspaceLayoutTest, FindCandidateBlazercPaths) {
- const std::string binary_dir = blaze_util::JoinPath(build_root_, "bazeldir");
- const std::string tools_dir = blaze_util::JoinPath(build_root_, "tools");
- const std::string workspace_rc_path =
- blaze_util::JoinPath(build_root_, "tools/bazel.rc");
- const std::string binary_rc_path =
- blaze_util::JoinPath(binary_dir, "bazel.bazelrc");
- ASSERT_TRUE(blaze_util::MakeDirectories(binary_dir, 0755));
- ASSERT_TRUE(blaze_util::MakeDirectories(tools_dir, 0755));
- ASSERT_TRUE(blaze_util::WriteFile("", workspace_rc_path, 0755));
- ASSERT_TRUE(blaze_util::WriteFile("", binary_rc_path, 0755));
-
- std::vector<std::string> expected = {workspace_rc_path, binary_rc_path};
- std::vector<std::string> actual =
- workspace_layout_->FindCandidateBlazercPaths(
- build_root_, build_root_, "bazeldir/bazel", {});
- // The third entry is the system wide blazerc path, /etc/bazel.bazelrc, which
- // we do not mock within this test because it is not within the sandbox. It
- // may or may not exist on the system running the test, so we do not check for
- // it.
- // TODO(https://github.com/bazelbuild/bazel/issues/4502): Make the system-wide
- // master bazelrc location configurable and add test coverage for it.
- std::vector<std::string> actual_first_two_entries(actual.begin(),
- actual.begin() + 2);
- ASSERT_EQ(expected, actual_first_two_entries);
-}
-
} // namespace blaze