aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/runfiles/runfiles_test.cc
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2018-03-05 06:35:20 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-05 06:36:54 -0800
commit3bcad502164dd169e5bb0af88f406dea86e24109 (patch)
treef55bc72b869b085578af8e1be390cb00ec5be20b /src/tools/runfiles/runfiles_test.cc
parentb2ba2079ccba96c60203c7f23fb75ab1a3586d60 (diff)
runfiles,C++: create envvar list for subprocesses
Implement Runfiles::EnvVars so it's now possible to propagate runfiles to subprocesses via environment variables (RUNFILES_MANIFEST_FILE and RUNFILES_DIR). Subsequent commits will add more feataures: - automatic Runfiles creation based on argv[0] and the envvars of this process See https://github.com/bazelbuild/bazel/issues/4460 Change-Id: If9a37b1be13b9cbacf21a496305d60444fd660b2 PiperOrigin-RevId: 187858830
Diffstat (limited to 'src/tools/runfiles/runfiles_test.cc')
-rw-r--r--src/tools/runfiles/runfiles_test.cc53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/tools/runfiles/runfiles_test.cc b/src/tools/runfiles/runfiles_test.cc
index 408dfde2e1..71a9d1d413 100644
--- a/src/tools/runfiles/runfiles_test.cc
+++ b/src/tools/runfiles/runfiles_test.cc
@@ -172,6 +172,45 @@ TEST_F(RunfilesTest, DirectoryBasedRunfilesRlocation) {
EXPECT_EQ(r->Rlocation("c:\\Foo"), "c:\\Foo");
}
+TEST_F(RunfilesTest, ManifestBasedRunfilesEnvVars) {
+ const vector<string> suffixes({"/MANIFEST", ".runfiles_manifest",
+ "runfiles_manifest", ".runfiles", ".manifest",
+ ".txt"});
+ for (vector<string>::size_type i = 0; i < suffixes.size(); ++i) {
+ unique_ptr<MockFile> mf(
+ MockFile::Create(string("foo" LINE()) + suffixes[i]));
+ EXPECT_TRUE(mf != nullptr) << " (suffix=\"" << suffixes[i] << "\")";
+
+ string error;
+ unique_ptr<Runfiles> r(Runfiles::CreateManifestBased(mf->Path(), &error));
+ ASSERT_NE(r, nullptr) << " (suffix=\"" << suffixes[i] << "\")";
+ EXPECT_TRUE(error.empty());
+
+ // The object can compute the runfiles directory when i=0 and i=1, but not
+ // when i>1 because the manifest file's name doesn't end in a well-known
+ // way.
+ const string expected_runfiles_dir(
+ i < 2 ? mf->Path().substr(0, mf->Path().size() - 9 /* "_manifest" */)
+ : "");
+ vector<pair<string, string> > expected(
+ {{"RUNFILES_MANIFEST_FILE", mf->Path()},
+ {"JAVA_RUNFILES", expected_runfiles_dir}});
+ EXPECT_EQ(r->EnvVars(), expected) << " (suffix=\"" << suffixes[i] << "\")";
+ }
+}
+
+TEST_F(RunfilesTest, DirectoryBasedRunfilesEnvVars) {
+ string error;
+ unique_ptr<Runfiles> r(
+ Runfiles::CreateDirectoryBased("runfiles/dir", &error));
+ ASSERT_NE(r, nullptr);
+ EXPECT_TRUE(error.empty());
+
+ vector<pair<string, string> > expected(
+ {{"RUNFILES_DIR", "runfiles/dir"}, {"JAVA_RUNFILES", "runfiles/dir"}});
+ EXPECT_EQ(r->EnvVars(), expected);
+}
+
TEST_F(RunfilesTest, FailsToCreateManifestBasedBecauseManifestDoesNotExist) {
string error;
unique_ptr<Runfiles> r(
@@ -253,6 +292,20 @@ TEST_F(RunfilesTest, MockFileTest) {
}
}
+TEST_F(RunfilesTest, IsAbsolute) {
+ EXPECT_FALSE(TestOnly_IsAbsolute("foo"));
+ EXPECT_FALSE(TestOnly_IsAbsolute("foo/bar"));
+ EXPECT_FALSE(TestOnly_IsAbsolute("\\foo"));
+ EXPECT_TRUE(TestOnly_IsAbsolute("c:\\foo"));
+ EXPECT_TRUE(TestOnly_IsAbsolute("c:/foo"));
+ EXPECT_TRUE(TestOnly_IsAbsolute("/foo"));
+ EXPECT_TRUE(TestOnly_IsAbsolute("x:\\foo"));
+ EXPECT_FALSE(TestOnly_IsAbsolute("::\\foo"));
+ EXPECT_FALSE(TestOnly_IsAbsolute("x\\foo"));
+ EXPECT_FALSE(TestOnly_IsAbsolute("x:"));
+ EXPECT_TRUE(TestOnly_IsAbsolute("x:\\"));
+}
+
} // namespace
} // namespace runfiles
} // namespace bazel