aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/cpp/util/file_windows_test.cc
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2017-01-10 16:06:42 +0000
committerGravatar Marcel Hlopko <hlopko@google.com>2017-01-10 19:42:02 +0000
commit93faf597b35c0638a66dbb32da4db5aa831caecf (patch)
tree0f10a5a8add3f436e044f3335670a3f95322573e /src/test/cpp/util/file_windows_test.cc
parent2f23599dda8f580234fc5a97675561cc86127444 (diff)
Bazel client, Windows: implement IsDirectory
See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 144084379 MOS_MIGRATED_REVID=144084379
Diffstat (limited to 'src/test/cpp/util/file_windows_test.cc')
-rw-r--r--src/test/cpp/util/file_windows_test.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/test/cpp/util/file_windows_test.cc b/src/test/cpp/util/file_windows_test.cc
index 1cf49d88c5..5c2f68ee27 100644
--- a/src/test/cpp/util/file_windows_test.cc
+++ b/src/test/cpp/util/file_windows_test.cc
@@ -290,4 +290,40 @@ TEST(FileTest, TestPathExistsWindows) {
ASSERT_FALSE(PathExists(JoinPath(tmpdir, "junc2")));
}
+TEST(FileTest, TestIsDirectory) {
+ ASSERT_FALSE(IsDirectory(""));
+
+ string tmpdir(GetTestTmpDir());
+ ASSERT_LT(0, tmpdir.size());
+ ASSERT_TRUE(IsDirectory(tmpdir));
+ ASSERT_TRUE(IsDirectory("C:\\"));
+ ASSERT_TRUE(IsDirectory("C:/"));
+ ASSERT_TRUE(IsDirectory("/c"));
+
+ ASSERT_FALSE(IsDirectory("non.existent"));
+ // Create a directory under `tempdir`, verify that IsDirectory reports true.
+ // Call it msys_dir1 so we can also use it as a mock msys root.
+ string dir1(JoinPath(tmpdir, "msys_dir1"));
+ ASSERT_EQ(0, mkdir(dir1.c_str()));
+ ASSERT_TRUE(IsDirectory(dir1));
+
+ // Use dir1 as the mock msys root, verify that IsDirectory works for a MSYS
+ // path.
+ SetEnvironmentVariableA("BAZEL_SH", JoinPath(dir1, "bash.exe").c_str());
+ ResetMsysRootForTesting();
+ ASSERT_TRUE(IsDirectory("/"));
+
+ // Verify that IsDirectory works for a junction.
+ string junc1(JoinPath(tmpdir, "junc1"));
+ RunCommand(string("cmd.exe /C mklink /J \"") + junc1 + "\" \"" + dir1 +
+ "\" >NUL 2>NUL");
+ ASSERT_TRUE(IsDirectory(junc1));
+
+ ASSERT_EQ(0, rmdir(dir1.c_str()));
+ ASSERT_FALSE(IsDirectory(dir1));
+ ASSERT_FALSE(IsDirectory(junc1));
+
+ ASSERT_EQ(0, rmdir(junc1.c_str()));
+}
+
} // namespace blaze_util