diff options
author | 2017-01-18 10:58:17 +0000 | |
---|---|---|
committer | 2017-01-18 11:02:24 +0000 | |
commit | a669557945cf610317307c770a76ed4c53a53f58 (patch) | |
tree | 5e711577a1f2c2a5623fc35975f9c5764331dd14 /src/test/cpp/util/file_windows_test.cc | |
parent | af0b670d9906e96ae41f55bb3b9b8698d425a1dc (diff) |
Bazel client, Windows: use CreateFileW
Use CreateFileW in blaze_util_windows.cc when
opening the "jvm.out" file. This allows supporting
long paths.
Also use AsWindowsPathWithUncPrefix instead of
just AsWindowsPath plus manually adding the UNC
prefix.
Also fix a compilation error in
file_windows_test.cc, I'm surprised the CI system
didn't catch this, maybe we aren't running this
test there.
See https://github.com/bazelbuild/bazel/issues/2107
See https://github.com/bazelbuild/bazel/issues/2181
--
PiperOrigin-RevId: 144813245
MOS_MIGRATED_REVID=144813245
Diffstat (limited to 'src/test/cpp/util/file_windows_test.cc')
-rw-r--r-- | src/test/cpp/util/file_windows_test.cc | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/test/cpp/util/file_windows_test.cc b/src/test/cpp/util/file_windows_test.cc index 5d9f0092cc..76af446f31 100644 --- a/src/test/cpp/util/file_windows_test.cc +++ b/src/test/cpp/util/file_windows_test.cc @@ -29,15 +29,18 @@ using std::string; using std::wstring; // Methods defined in file_windows.cc that are only visible for testing. +bool AsWindowsPath(const string& path, wstring* result); void ResetMsysRootForTesting(); string NormalizeWindowsPath(string path); -static void GetTestTmpDir(string* result) { - char buf[MAX_PATH] = {0}; - DWORD len = GetEnvironmentVariableA("TEST_TMPDIR", buf, MAX_PATH); - result->assign(buf); - ASSERT_LT(0, result->size()); -} +// This is a macro so the assertions will have the correct line number. +#define GET_TEST_TMPDIR(/* string& */ result) \ + { \ + char buf[MAX_PATH] = {0}; \ + DWORD len = ::GetEnvironmentVariableA("TEST_TMPDIR", buf, MAX_PATH); \ + result = buf; \ + ASSERT_GT(result.size(), 0); \ + } TEST(FileTest, TestNormalizeWindowsPath) { ASSERT_EQ(string(""), NormalizeWindowsPath("")); @@ -194,7 +197,7 @@ TEST(FileTest, TestAsShortWindowsPath) { ASSERT_EQ(string("NUL"), actual); string tmpdir; - GetTestTmpDir(&tmpdir); + GET_TEST_TMPDIR(tmpdir); string short_tmpdir; ASSERT_TRUE(AsShortWindowsPath(tmpdir, &short_tmpdir)); ASSERT_LT(0, short_tmpdir.size()); @@ -267,7 +270,7 @@ TEST(FileTest, TestPathExistsWindows) { ASSERT_TRUE(PathExists("Nul")); string tmpdir; - GetTestTmpDir(&tmpdir); + GET_TEST_TMPDIR(tmpdir); ASSERT_TRUE(PathExists(tmpdir)); // Create a fake msys root. We'll also use it as a junction target. @@ -310,7 +313,7 @@ TEST(FileTest, TestIsDirectory) { ASSERT_FALSE(IsDirectory("Nul")); string tmpdir; - GetTestTmpDir(&tmpdir); + GET_TEST_TMPDIR(tmpdir); ASSERT_TRUE(IsDirectory(tmpdir)); ASSERT_TRUE(IsDirectory("C:\\")); ASSERT_TRUE(IsDirectory("C:/")); @@ -347,7 +350,7 @@ TEST(FileTest, TestUnlinkPath) { ASSERT_FALSE(UnlinkPath("Nul")); string tmpdir; - GetTestTmpDir(&tmpdir); + GET_TEST_TMPDIR(tmpdir); // Create a directory under `tempdir`, a file inside it, and a junction // pointing to it. @@ -376,7 +379,8 @@ TEST(FileTest, TestUnlinkPath) { } TEST(FileTest, TestMakeDirectories) { - string tmpdir(GetTestTmpDir()); + string tmpdir; + GET_TEST_TMPDIR(tmpdir); ASSERT_LT(0, tmpdir.size()); SetEnvironmentVariableA( @@ -417,7 +421,7 @@ TEST(FileTest, CanAccess) { ASSERT_FALSE(CanAccessDirectory("non.existent")); string tmpdir; - GetTestTmpDir(&tmpdir); + GET_TEST_TMPDIR(tmpdir); string dir(JoinPath(tmpdir, "canaccesstest")); ASSERT_EQ(0, mkdir(dir.c_str())); |