2016-03-11 16:44:44 +08:00
|
|
|
//===-- FileSpecTest.cpp ----------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2017-03-23 02:40:07 +08:00
|
|
|
#include "lldb/Utility/FileSpec.h"
|
2016-03-11 16:44:44 +08:00
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
TEST(FileSpecTest, FileAndDirectoryComponents) {
|
|
|
|
FileSpec fs_posix("/foo/bar", false, FileSpec::ePathSyntaxPosix);
|
|
|
|
EXPECT_STREQ("/foo/bar", fs_posix.GetCString());
|
|
|
|
EXPECT_STREQ("/foo", fs_posix.GetDirectory().GetCString());
|
|
|
|
EXPECT_STREQ("bar", fs_posix.GetFilename().GetCString());
|
|
|
|
|
|
|
|
FileSpec fs_windows("F:\\bar", false, FileSpec::ePathSyntaxWindows);
|
|
|
|
EXPECT_STREQ("F:\\bar", fs_windows.GetCString());
|
|
|
|
// EXPECT_STREQ("F:\\", fs_windows.GetDirectory().GetCString()); // It returns
|
|
|
|
// "F:/"
|
|
|
|
EXPECT_STREQ("bar", fs_windows.GetFilename().GetCString());
|
|
|
|
|
|
|
|
FileSpec fs_posix_root("/", false, FileSpec::ePathSyntaxPosix);
|
|
|
|
EXPECT_STREQ("/", fs_posix_root.GetCString());
|
|
|
|
EXPECT_EQ(nullptr, fs_posix_root.GetDirectory().GetCString());
|
|
|
|
EXPECT_STREQ("/", fs_posix_root.GetFilename().GetCString());
|
|
|
|
|
|
|
|
FileSpec fs_windows_drive("F:", false, FileSpec::ePathSyntaxWindows);
|
|
|
|
EXPECT_STREQ("F:", fs_windows_drive.GetCString());
|
|
|
|
EXPECT_EQ(nullptr, fs_windows_drive.GetDirectory().GetCString());
|
|
|
|
EXPECT_STREQ("F:", fs_windows_drive.GetFilename().GetCString());
|
|
|
|
|
|
|
|
FileSpec fs_windows_root("F:\\", false, FileSpec::ePathSyntaxWindows);
|
|
|
|
EXPECT_STREQ("F:\\", fs_windows_root.GetCString());
|
|
|
|
EXPECT_STREQ("F:", fs_windows_root.GetDirectory().GetCString());
|
|
|
|
// EXPECT_STREQ("\\", fs_windows_root.GetFilename().GetCString()); // It
|
|
|
|
// returns "/"
|
|
|
|
|
|
|
|
FileSpec fs_posix_long("/foo/bar/baz", false, FileSpec::ePathSyntaxPosix);
|
|
|
|
EXPECT_STREQ("/foo/bar/baz", fs_posix_long.GetCString());
|
|
|
|
EXPECT_STREQ("/foo/bar", fs_posix_long.GetDirectory().GetCString());
|
|
|
|
EXPECT_STREQ("baz", fs_posix_long.GetFilename().GetCString());
|
|
|
|
|
|
|
|
FileSpec fs_windows_long("F:\\bar\\baz", false, FileSpec::ePathSyntaxWindows);
|
|
|
|
EXPECT_STREQ("F:\\bar\\baz", fs_windows_long.GetCString());
|
|
|
|
// EXPECT_STREQ("F:\\bar", fs_windows_long.GetDirectory().GetCString()); // It
|
|
|
|
// returns "F:/bar"
|
|
|
|
EXPECT_STREQ("baz", fs_windows_long.GetFilename().GetCString());
|
|
|
|
|
|
|
|
FileSpec fs_posix_trailing_slash("/foo/bar/", false,
|
|
|
|
FileSpec::ePathSyntaxPosix);
|
2018-04-27 23:45:58 +08:00
|
|
|
EXPECT_STREQ("/foo/bar", fs_posix_trailing_slash.GetCString());
|
|
|
|
EXPECT_STREQ("/foo", fs_posix_trailing_slash.GetDirectory().GetCString());
|
|
|
|
EXPECT_STREQ("bar", fs_posix_trailing_slash.GetFilename().GetCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
FileSpec fs_windows_trailing_slash("F:\\bar\\", false,
|
|
|
|
FileSpec::ePathSyntaxWindows);
|
2018-04-27 23:45:58 +08:00
|
|
|
EXPECT_STREQ("F:\\bar", fs_windows_trailing_slash.GetCString());
|
|
|
|
EXPECT_STREQ("bar", fs_windows_trailing_slash.GetFilename().GetCString());
|
2016-03-11 16:44:44 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
TEST(FileSpecTest, AppendPathComponent) {
|
|
|
|
FileSpec fs_posix("/foo", false, FileSpec::ePathSyntaxPosix);
|
|
|
|
fs_posix.AppendPathComponent("bar");
|
|
|
|
EXPECT_STREQ("/foo/bar", fs_posix.GetCString());
|
|
|
|
EXPECT_STREQ("/foo", fs_posix.GetDirectory().GetCString());
|
|
|
|
EXPECT_STREQ("bar", fs_posix.GetFilename().GetCString());
|
|
|
|
|
|
|
|
FileSpec fs_posix_2("/foo", false, FileSpec::ePathSyntaxPosix);
|
|
|
|
fs_posix_2.AppendPathComponent("//bar/baz");
|
|
|
|
EXPECT_STREQ("/foo/bar/baz", fs_posix_2.GetCString());
|
|
|
|
EXPECT_STREQ("/foo/bar", fs_posix_2.GetDirectory().GetCString());
|
|
|
|
EXPECT_STREQ("baz", fs_posix_2.GetFilename().GetCString());
|
|
|
|
|
|
|
|
FileSpec fs_windows("F:\\bar", false, FileSpec::ePathSyntaxWindows);
|
|
|
|
fs_windows.AppendPathComponent("baz");
|
|
|
|
EXPECT_STREQ("F:\\bar\\baz", fs_windows.GetCString());
|
|
|
|
// EXPECT_STREQ("F:\\bar", fs_windows.GetDirectory().GetCString()); // It
|
|
|
|
// returns "F:/bar"
|
|
|
|
EXPECT_STREQ("baz", fs_windows.GetFilename().GetCString());
|
|
|
|
|
|
|
|
FileSpec fs_posix_root("/", false, FileSpec::ePathSyntaxPosix);
|
|
|
|
fs_posix_root.AppendPathComponent("bar");
|
|
|
|
EXPECT_STREQ("/bar", fs_posix_root.GetCString());
|
|
|
|
EXPECT_STREQ("/", fs_posix_root.GetDirectory().GetCString());
|
|
|
|
EXPECT_STREQ("bar", fs_posix_root.GetFilename().GetCString());
|
|
|
|
|
|
|
|
FileSpec fs_windows_root("F:\\", false, FileSpec::ePathSyntaxWindows);
|
|
|
|
fs_windows_root.AppendPathComponent("bar");
|
|
|
|
EXPECT_STREQ("F:\\bar", fs_windows_root.GetCString());
|
|
|
|
// EXPECT_STREQ("F:\\", fs_windows_root.GetDirectory().GetCString()); // It
|
|
|
|
// returns "F:/"
|
|
|
|
EXPECT_STREQ("bar", fs_windows_root.GetFilename().GetCString());
|
2016-03-11 16:44:44 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
TEST(FileSpecTest, CopyByAppendingPathComponent) {
|
|
|
|
FileSpec fs = FileSpec("/foo", false, FileSpec::ePathSyntaxPosix)
|
|
|
|
.CopyByAppendingPathComponent("bar");
|
|
|
|
EXPECT_STREQ("/foo/bar", fs.GetCString());
|
|
|
|
EXPECT_STREQ("/foo", fs.GetDirectory().GetCString());
|
|
|
|
EXPECT_STREQ("bar", fs.GetFilename().GetCString());
|
2016-03-11 16:44:44 +08:00
|
|
|
}
|
2016-04-14 17:38:06 +08:00
|
|
|
|
2017-01-16 18:07:02 +08:00
|
|
|
TEST(FileSpecTest, PrependPathComponent) {
|
|
|
|
FileSpec fs_posix("foo", false, FileSpec::ePathSyntaxPosix);
|
|
|
|
fs_posix.PrependPathComponent("/bar");
|
|
|
|
EXPECT_STREQ("/bar/foo", fs_posix.GetCString());
|
|
|
|
|
|
|
|
FileSpec fs_posix_2("foo/bar", false, FileSpec::ePathSyntaxPosix);
|
|
|
|
fs_posix_2.PrependPathComponent("/baz");
|
|
|
|
EXPECT_STREQ("/baz/foo/bar", fs_posix_2.GetCString());
|
|
|
|
|
|
|
|
FileSpec fs_windows("baz", false, FileSpec::ePathSyntaxWindows);
|
|
|
|
fs_windows.PrependPathComponent("F:\\bar");
|
|
|
|
EXPECT_STREQ("F:\\bar\\baz", fs_windows.GetCString());
|
|
|
|
|
|
|
|
FileSpec fs_posix_root("bar", false, FileSpec::ePathSyntaxPosix);
|
|
|
|
fs_posix_root.PrependPathComponent("/");
|
|
|
|
EXPECT_STREQ("/bar", fs_posix_root.GetCString());
|
|
|
|
|
|
|
|
FileSpec fs_windows_root("bar", false, FileSpec::ePathSyntaxWindows);
|
|
|
|
fs_windows_root.PrependPathComponent("F:\\");
|
|
|
|
EXPECT_STREQ("F:\\bar", fs_windows_root.GetCString());
|
|
|
|
}
|
|
|
|
|
2016-10-28 19:28:01 +08:00
|
|
|
TEST(FileSpecTest, EqualSeparator) {
|
2016-09-07 04:57:50 +08:00
|
|
|
FileSpec backward("C:\\foo\\bar", false, FileSpec::ePathSyntaxWindows);
|
|
|
|
FileSpec forward("C:/foo/bar", false, FileSpec::ePathSyntaxWindows);
|
|
|
|
EXPECT_EQ(forward, backward);
|
2016-10-28 19:28:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FileSpecTest, EqualDotsWindows) {
|
|
|
|
std::pair<const char *, const char *> tests[] = {
|
|
|
|
{R"(C:\foo\bar\baz)", R"(C:\foo\foo\..\bar\baz)"},
|
|
|
|
{R"(C:\bar\baz)", R"(C:\foo\..\bar\baz)"},
|
|
|
|
{R"(C:\bar\baz)", R"(C:/foo/../bar/baz)"},
|
|
|
|
{R"(C:/bar/baz)", R"(C:\foo\..\bar\baz)"},
|
|
|
|
{R"(C:\bar)", R"(C:\foo\..\bar)"},
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
{R"(C:\foo\bar)", R"(C:\foo\.\bar)"},
|
2017-03-28 03:12:25 +08:00
|
|
|
{R"(C:\foo\bar)", R"(C:\foo\bar\.)"},
|
2016-10-28 19:28:01 +08:00
|
|
|
};
|
|
|
|
|
2018-04-20 16:27:27 +08:00
|
|
|
for (const auto &test : tests) {
|
2016-10-28 19:28:01 +08:00
|
|
|
FileSpec one(test.first, false, FileSpec::ePathSyntaxWindows);
|
|
|
|
FileSpec two(test.second, false, FileSpec::ePathSyntaxWindows);
|
2018-04-27 23:45:58 +08:00
|
|
|
EXPECT_EQ(one, two);
|
2016-10-28 19:28:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FileSpecTest, EqualDotsPosix) {
|
|
|
|
std::pair<const char *, const char *> tests[] = {
|
|
|
|
{R"(/foo/bar/baz)", R"(/foo/foo/../bar/baz)"},
|
|
|
|
{R"(/bar/baz)", R"(/foo/../bar/baz)"},
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
{R"(/bar)", R"(/foo/../bar)"},
|
|
|
|
{R"(/foo/bar)", R"(/foo/./bar)"},
|
2017-03-28 03:12:25 +08:00
|
|
|
{R"(/foo/bar)", R"(/foo/bar/.)"},
|
2016-10-28 19:28:01 +08:00
|
|
|
};
|
|
|
|
|
2018-04-20 16:27:27 +08:00
|
|
|
for (const auto &test : tests) {
|
2016-10-28 19:28:01 +08:00
|
|
|
FileSpec one(test.first, false, FileSpec::ePathSyntaxPosix);
|
|
|
|
FileSpec two(test.second, false, FileSpec::ePathSyntaxPosix);
|
2018-04-27 23:45:58 +08:00
|
|
|
EXPECT_EQ(one, two);
|
2016-10-28 19:28:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FileSpecTest, EqualDotsPosixRoot) {
|
|
|
|
std::pair<const char *, const char *> tests[] = {
|
2018-04-20 16:27:27 +08:00
|
|
|
{R"(/)", R"(/..)"},
|
|
|
|
{R"(/)", R"(/.)"},
|
|
|
|
{R"(/)", R"(/foo/..)"},
|
2016-10-28 19:28:01 +08:00
|
|
|
};
|
|
|
|
|
2018-04-20 16:27:27 +08:00
|
|
|
for (const auto &test : tests) {
|
2016-10-28 19:28:01 +08:00
|
|
|
FileSpec one(test.first, false, FileSpec::ePathSyntaxPosix);
|
|
|
|
FileSpec two(test.second, false, FileSpec::ePathSyntaxPosix);
|
2018-04-27 23:45:58 +08:00
|
|
|
EXPECT_EQ(one, two);
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FileSpecTest, GetNormalizedPath) {
|
|
|
|
std::pair<const char *, const char *> posix_tests[] = {
|
2016-11-04 09:47:59 +08:00
|
|
|
{"/foo/.././bar", "/bar"},
|
|
|
|
{"/foo/./../bar", "/bar"},
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
{"/foo/../bar", "/bar"},
|
|
|
|
{"/foo/./bar", "/foo/bar"},
|
|
|
|
{"/foo/..", "/"},
|
|
|
|
{"/foo/.", "/foo"},
|
2016-12-01 00:08:45 +08:00
|
|
|
{"/foo//bar", "/foo/bar"},
|
|
|
|
{"/foo//bar/baz", "/foo/bar/baz"},
|
|
|
|
{"/foo//bar/./baz", "/foo/bar/baz"},
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
{"/./foo", "/foo"},
|
|
|
|
{"/", "/"},
|
2018-05-11 19:55:34 +08:00
|
|
|
{"//", "/"},
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
{"//net", "//net"},
|
|
|
|
{"/..", "/"},
|
|
|
|
{"/.", "/"},
|
|
|
|
{"..", ".."},
|
2018-04-27 23:45:58 +08:00
|
|
|
{".", ""},
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
{"../..", "../.."},
|
2018-04-27 23:45:58 +08:00
|
|
|
{"foo/..", ""},
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
{"foo/../bar", "bar"},
|
|
|
|
{"../foo/..", ".."},
|
|
|
|
{"./foo", "foo"},
|
2018-04-27 23:45:58 +08:00
|
|
|
{"././foo", "foo"},
|
|
|
|
{"../foo", "../foo"},
|
|
|
|
{"../../foo", "../../foo"},
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
};
|
|
|
|
for (auto test : posix_tests) {
|
2018-05-11 19:55:34 +08:00
|
|
|
SCOPED_TRACE(llvm::Twine("test.first = ") + test.first);
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
EXPECT_EQ(test.second,
|
|
|
|
FileSpec(test.first, false, FileSpec::ePathSyntaxPosix)
|
|
|
|
.GetPath());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<const char *, const char *> windows_tests[] = {
|
|
|
|
{R"(c:\bar\..\bar)", R"(c:\bar)"},
|
|
|
|
{R"(c:\bar\.\bar)", R"(c:\bar\bar)"},
|
|
|
|
{R"(c:\bar\..)", R"(c:\)"},
|
|
|
|
{R"(c:\bar\.)", R"(c:\bar)"},
|
|
|
|
{R"(c:\.\bar)", R"(c:\bar)"},
|
|
|
|
{R"(\)", R"(\)"},
|
2018-05-11 19:55:34 +08:00
|
|
|
{R"(\\)", R"(\)"},
|
|
|
|
{R"(\\net)", R"(\\net)"},
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
{R"(c:\..)", R"(c:\)"},
|
|
|
|
{R"(c:\.)", R"(c:\)"},
|
2018-04-27 23:45:58 +08:00
|
|
|
// TODO: fix llvm::sys::path::remove_dots() to return "\" below.
|
|
|
|
{R"(\..)", R"(\..)"},
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
// {R"(c:..)", R"(c:..)"},
|
|
|
|
{R"(..)", R"(..)"},
|
2018-04-27 23:45:58 +08:00
|
|
|
{R"(.)", R"()"},
|
|
|
|
// TODO: fix llvm::sys::path::remove_dots() to return "c:\" below.
|
|
|
|
{R"(c:..\..)", R"(c:\..\..)"},
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
{R"(..\..)", R"(..\..)"},
|
2018-04-27 23:45:58 +08:00
|
|
|
{R"(foo\..)", R"()"},
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
{R"(foo\..\bar)", R"(bar)"},
|
|
|
|
{R"(..\foo\..)", R"(..)"},
|
|
|
|
{R"(.\foo)", R"(foo)"},
|
2018-04-27 23:45:58 +08:00
|
|
|
{R"(.\.\foo)", R"(foo)"},
|
|
|
|
{R"(..\foo)", R"(..\foo)"},
|
|
|
|
{R"(..\..\foo)", R"(..\..\foo)"},
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
};
|
|
|
|
for (auto test : windows_tests) {
|
|
|
|
EXPECT_EQ(test.second,
|
|
|
|
FileSpec(test.first, false, FileSpec::ePathSyntaxWindows)
|
|
|
|
.GetPath())
|
|
|
|
<< "Original path: " << test.first;
|
2016-10-28 19:28:01 +08:00
|
|
|
}
|
2016-04-14 17:38:06 +08:00
|
|
|
}
|
2016-12-16 12:27:00 +08:00
|
|
|
|
|
|
|
TEST(FileSpecTest, FormatFileSpec) {
|
|
|
|
auto win = FileSpec::ePathSyntaxWindows;
|
|
|
|
|
|
|
|
FileSpec F;
|
|
|
|
EXPECT_EQ("(empty)", llvm::formatv("{0}", F).str());
|
|
|
|
EXPECT_EQ("(empty)", llvm::formatv("{0:D}", F).str());
|
|
|
|
EXPECT_EQ("(empty)", llvm::formatv("{0:F}", F).str());
|
|
|
|
|
|
|
|
F = FileSpec("C:\\foo\\bar.txt", false, win);
|
|
|
|
EXPECT_EQ("C:\\foo\\bar.txt", llvm::formatv("{0}", F).str());
|
|
|
|
EXPECT_EQ("C:\\foo\\", llvm::formatv("{0:D}", F).str());
|
|
|
|
EXPECT_EQ("bar.txt", llvm::formatv("{0:F}", F).str());
|
|
|
|
|
|
|
|
F = FileSpec("foo\\bar.txt", false, win);
|
|
|
|
EXPECT_EQ("foo\\bar.txt", llvm::formatv("{0}", F).str());
|
|
|
|
EXPECT_EQ("foo\\", llvm::formatv("{0:D}", F).str());
|
|
|
|
EXPECT_EQ("bar.txt", llvm::formatv("{0:F}", F).str());
|
|
|
|
|
|
|
|
F = FileSpec("foo", false, win);
|
|
|
|
EXPECT_EQ("foo", llvm::formatv("{0}", F).str());
|
|
|
|
EXPECT_EQ("foo", llvm::formatv("{0:F}", F).str());
|
|
|
|
EXPECT_EQ("(empty)", llvm::formatv("{0:D}", F).str());
|
2017-01-16 18:07:02 +08:00
|
|
|
}
|
2018-04-27 23:45:58 +08:00
|
|
|
|