diff options
author | 2016-12-21 11:25:50 +0000 | |
---|---|---|
committer | 2016-12-21 12:59:36 +0000 | |
commit | 108a6d5194fd0ac69eac7dceb9b7c3c8108e2180 (patch) | |
tree | f87f45e71ab65ea41c806addaa8ae0fa74448b6a /src/test/cpp/util | |
parent | e9c123a0b45c29f0cf9138a8398a160cd9d9ad77 (diff) |
Bazel client; implement NormalizePath
This method can normalize paths with "." and ".."
and multiple "/" characters.
E.g. normalize("../foo/./bar/../baz") = "foo/baz"
This method enables us implementing PathExists on
Windows. If the path to check is too long, we need
to prefix it with "\\?\" for the Windows API
functions to work, but then the path must be
fully normalized and in Windows format. We already
have functions to convert a path to Windows format
but that doesn't normalize; with this function we
can finally convert paths like "/c/foo/../bar" to
L"\\?\c:\foo" and check if it exists.
See https://github.com/bazelbuild/bazel/issues/2107
See https://github.com/bazelbuild/bazel/issues/2181
--
PiperOrigin-RevId: 142648194
MOS_MIGRATED_REVID=142648194
Diffstat (limited to 'src/test/cpp/util')
-rw-r--r-- | src/test/cpp/util/file_test.cc | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/test/cpp/util/file_test.cc b/src/test/cpp/util/file_test.cc index fa379f567d..f98ed9975a 100644 --- a/src/test/cpp/util/file_test.cc +++ b/src/test/cpp/util/file_test.cc @@ -22,6 +22,22 @@ namespace blaze_util { +TEST(FileTest, TestNormalizePath) { + ASSERT_EQ(string(""), NormalizePath("")); + ASSERT_EQ(string(""), NormalizePath(".")); + ASSERT_EQ(string("/"), NormalizePath("/")); + ASSERT_EQ(string("/"), NormalizePath("//")); + ASSERT_EQ(string("foo"), NormalizePath("foo")); + ASSERT_EQ(string("foo"), NormalizePath("foo/")); + ASSERT_EQ(string("foo/bar"), NormalizePath("foo//bar")); + ASSERT_EQ(string("foo/bar"), NormalizePath("../..//foo//bar")); + ASSERT_EQ(string("/foo"), NormalizePath("/foo")); + ASSERT_EQ(string("/foo"), NormalizePath("/foo/")); + ASSERT_EQ(string("/foo/bar"), NormalizePath("/foo/./bar/")); + ASSERT_EQ(string("foo/bar"), NormalizePath("../foo/baz/../bar")); + ASSERT_EQ(string("foo/bar"), NormalizePath("../foo//./baz/../bar///")); +} + TEST(FileTest, TestSingleThreadedPipe) { std::unique_ptr<IPipe> pipe(CreatePipe()); char buffer[50] = {0}; |