aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/cpp
diff options
context:
space:
mode:
authorGravatar laszlocsomor <laszlocsomor@google.com>2017-07-21 13:18:13 +0200
committerGravatar Jakob Buchgraber <buchgr@google.com>2017-07-24 09:51:01 +0200
commitb69acfaa1c281ac2e8fd7450f07bb3735d24ae23 (patch)
treebc6eb5f65d44fc8a29bcaba197f1e87ba7ab1a1a /src/test/cpp
parent1920dd98491fdb00daf6187beed58c8ff06d4fd6 (diff)
Windows: add blaze_util::AsAbsoluteWindowsPath
Replace blaze_util::AsWindowsPathWithUncPrefix with AsAbsoluteWindowsPath, which always returns an absolute path. Fixes https://github.com/bazelbuild/bazel/issues/2935 RELNOTES: none PiperOrigin-RevId: 162727218
Diffstat (limited to 'src/test/cpp')
-rw-r--r--src/test/cpp/util/file_windows_test.cc26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/test/cpp/util/file_windows_test.cc b/src/test/cpp/util/file_windows_test.cc
index cab1947ba4..496c24d02f 100644
--- a/src/test/cpp/util/file_windows_test.cc
+++ b/src/test/cpp/util/file_windows_test.cc
@@ -23,6 +23,7 @@
#include "src/main/cpp/util/file.h"
#include "src/main/cpp/util/file_platform.h"
#include "src/main/native/windows/file.h"
+#include "src/main/native/windows/util.h"
#include "src/test/cpp/util/test_util.h"
#include "src/test/cpp/util/windows_test_util.h"
@@ -244,6 +245,29 @@ TEST_F(FileWindowsTest, TestAsWindowsPath) {
ASSERT_EQ(wlongpath, actual);
}
+TEST_F(FileWindowsTest, TestAsAbsoluteWindowsPath) {
+ SetEnvironmentVariableA("BAZEL_SH", "c:\\some\\long/path\\bin\\bash.exe");
+ ResetMsysRootForTesting();
+ wstring actual;
+
+ ASSERT_TRUE(AsAbsoluteWindowsPath("c:/", &actual));
+ ASSERT_EQ(L"\\\\?\\c:\\", actual);
+
+ ASSERT_TRUE(AsAbsoluteWindowsPath("c:/..\\non-existent//", &actual));
+ ASSERT_EQ(L"\\\\?\\c:\\non-existent", actual);
+
+ WCHAR cwd[MAX_PATH];
+ ASSERT_TRUE(::GetCurrentDirectoryW(MAX_PATH, cwd));
+ ASSERT_FALSE(bazel::windows::HasUncPrefix(cwd));
+ wstring cwdw(cwd);
+ ASSERT_EQ(cwdw.find_first_of(L'/'), wstring::npos);
+ wstring expected =
+ wstring(L"\\\\?\\") + cwdw +
+ ((cwdw.back() == L'\\') ? L"non-existent" : L"\\non-existent");
+ ASSERT_TRUE(AsAbsoluteWindowsPath("non-existent", &actual));
+ ASSERT_EQ(expected, actual);
+}
+
TEST_F(FileWindowsTest, TestAsShortWindowsPath) {
string actual;
ASSERT_TRUE(AsShortWindowsPath("/dev/null", &actual));
@@ -516,7 +540,7 @@ TEST_F(FileWindowsTest, TestMakeCanonical) {
// Create a dummy file: $TEST_TMPDIR/directory/subdirectory/foo.txt
string foo(JoinPath(dir2, "foo.txt"));
wstring wfoo;
- EXPECT_TRUE(AsWindowsPathWithUncPrefix(foo, &wfoo));
+ EXPECT_TRUE(AsAbsoluteWindowsPath(foo, &wfoo));
EXPECT_TRUE(CreateDummyFile(wfoo));
EXPECT_TRUE(CanReadFile(foo));
// Create junctions next to directory and subdirectory, pointing to them.