aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/cpp
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2016-12-20 09:38:53 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-12-20 09:41:46 +0000
commitd6297fb8b924dda41111356c0c32d4a5a297a11b (patch)
tree717f4d9ba8e430f7289e3e0dd8fed350f48879c5 /src/test/cpp
parent332b61f416855eb5938a226eed7787473487a268 (diff)
Bazel client, Windows: implement AsWindowsPath
This method converts MSYS paths to Windows path. It uses the BAZEL_SH envvar to obtain the MSYS root directory, to which all Unix paths (except for mounts) are relative. We cannot handle mounts because we don't want to read /etc/mtab every time there's a file operation so we simply apply a heuristic similar to https://github.com/bazelbuild/bazel/blob/cd4cc09fa6ef96380a3d0888f825dfd1dbada651/src/main/java/com/google/devtools/build/lib/vfs/WindowsFileSystem.java#L52-L63 Also clean up the #ifdefs surrounding SyncFile. See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 142531986 MOS_MIGRATED_REVID=142531986
Diffstat (limited to 'src/test/cpp')
-rw-r--r--src/test/cpp/util/file_windows_test.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/cpp/util/file_windows_test.cc b/src/test/cpp/util/file_windows_test.cc
index 00486d4fa9..048d13b510 100644
--- a/src/test/cpp/util/file_windows_test.cc
+++ b/src/test/cpp/util/file_windows_test.cc
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string.h>
+#include <windows.h> // SetEnvironmentVariableA
#include "src/main/cpp/util/file.h"
#include "src/main/cpp/util/file_platform.h"
@@ -93,4 +94,44 @@ TEST(FileTest, IsRootDirectory) {
ASSERT_FALSE(IsRootDirectory("\\\\?\\c:\\foo"));
}
+TEST(FileTest, TestAsWindowsPath) {
+ SetEnvironmentVariableA("BAZEL_SH", "c:\\dummy\\msys\\bin\\bash.exe");
+ std::wstring actual;
+
+ ASSERT_TRUE(AsWindowsPath("", &actual));
+ ASSERT_EQ(std::wstring(L""), actual);
+
+ ASSERT_TRUE(AsWindowsPath("", &actual));
+ ASSERT_EQ(std::wstring(L""), actual);
+
+ ASSERT_TRUE(AsWindowsPath("foo/bar", &actual));
+ ASSERT_EQ(std::wstring(L"foo\\bar"), actual);
+
+ ASSERT_TRUE(AsWindowsPath("/c", &actual));
+ ASSERT_EQ(std::wstring(L"c:\\"), actual);
+
+ ASSERT_TRUE(AsWindowsPath("/c/", &actual));
+ ASSERT_EQ(std::wstring(L"c:\\"), actual);
+
+ ASSERT_TRUE(AsWindowsPath("/c/blah", &actual));
+ ASSERT_EQ(std::wstring(L"c:\\blah"), actual);
+
+ ASSERT_TRUE(AsWindowsPath("/d/progra~1/micros~1", &actual));
+ ASSERT_EQ(std::wstring(L"d:\\progra~1\\micros~1"), actual);
+
+ ASSERT_TRUE(AsWindowsPath("/foo", &actual));
+ ASSERT_EQ(std::wstring(L"c:\\dummy\\msys\\foo"), actual);
+
+ std::wstring wlongpath(L"dummy_long_path\\");
+ std::string longpath("dummy_long_path/");
+ while (longpath.size() <= MAX_PATH) {
+ wlongpath += wlongpath;
+ longpath += longpath;
+ }
+ wlongpath = std::wstring(L"c:\\") + wlongpath;
+ longpath = std::string("/c/") + longpath;
+ ASSERT_TRUE(AsWindowsPath(longpath, &actual));
+ ASSERT_EQ(wlongpath, actual);
+}
+
} // namespace blaze_util