[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- FileSpecTest.cpp --------------------------------------------------===//
|
2016-03-11 16:44:44 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-03-11 16:44:44 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
2019-11-28 20:30:39 +08:00
|
|
|
static FileSpec PosixSpec(llvm::StringRef path) {
|
|
|
|
return FileSpec(path, FileSpec::Style::posix);
|
|
|
|
}
|
|
|
|
|
|
|
|
static FileSpec WindowsSpec(llvm::StringRef path) {
|
|
|
|
return FileSpec(path, FileSpec::Style::windows);
|
|
|
|
}
|
|
|
|
|
2016-03-11 16:44:44 +08:00
|
|
|
TEST(FileSpecTest, FileAndDirectoryComponents) {
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_posix("/foo/bar", FileSpec::Style::posix);
|
2016-03-11 16:44:44 +08:00
|
|
|
EXPECT_STREQ("/foo/bar", fs_posix.GetCString());
|
|
|
|
EXPECT_STREQ("/foo", fs_posix.GetDirectory().GetCString());
|
|
|
|
EXPECT_STREQ("bar", fs_posix.GetFilename().GetCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_windows("F:\\bar", FileSpec::Style::windows);
|
2016-03-11 16:44:44 +08:00
|
|
|
EXPECT_STREQ("F:\\bar", fs_windows.GetCString());
|
2016-04-14 17:38:06 +08:00
|
|
|
// EXPECT_STREQ("F:\\", fs_windows.GetDirectory().GetCString()); // It returns
|
|
|
|
// "F:/"
|
2016-03-11 16:44:44 +08:00
|
|
|
EXPECT_STREQ("bar", fs_windows.GetFilename().GetCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_posix_root("/", FileSpec::Style::posix);
|
2016-03-11 16:44:44 +08:00
|
|
|
EXPECT_STREQ("/", fs_posix_root.GetCString());
|
|
|
|
EXPECT_EQ(nullptr, fs_posix_root.GetDirectory().GetCString());
|
|
|
|
EXPECT_STREQ("/", fs_posix_root.GetFilename().GetCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_net_drive("//net", FileSpec::Style::posix);
|
2018-06-14 00:23:21 +08:00
|
|
|
EXPECT_STREQ("//net", fs_net_drive.GetCString());
|
|
|
|
EXPECT_EQ(nullptr, fs_net_drive.GetDirectory().GetCString());
|
|
|
|
EXPECT_STREQ("//net", fs_net_drive.GetFilename().GetCString());
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_net_root("//net/", FileSpec::Style::posix);
|
2018-06-14 00:23:21 +08:00
|
|
|
EXPECT_STREQ("//net/", fs_net_root.GetCString());
|
|
|
|
EXPECT_STREQ("//net", fs_net_root.GetDirectory().GetCString());
|
|
|
|
EXPECT_STREQ("/", fs_net_root.GetFilename().GetCString());
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_windows_drive("F:", FileSpec::Style::windows);
|
2016-04-04 22:39:12 +08:00
|
|
|
EXPECT_STREQ("F:", fs_windows_drive.GetCString());
|
|
|
|
EXPECT_EQ(nullptr, fs_windows_drive.GetDirectory().GetCString());
|
|
|
|
EXPECT_STREQ("F:", fs_windows_drive.GetFilename().GetCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_windows_root("F:\\", FileSpec::Style::windows);
|
2016-04-04 22:39:12 +08:00
|
|
|
EXPECT_STREQ("F:\\", fs_windows_root.GetCString());
|
|
|
|
EXPECT_STREQ("F:", fs_windows_root.GetDirectory().GetCString());
|
2016-04-14 17:38:06 +08:00
|
|
|
// EXPECT_STREQ("\\", fs_windows_root.GetFilename().GetCString()); // It
|
|
|
|
// returns "/"
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_posix_long("/foo/bar/baz", FileSpec::Style::posix);
|
2016-03-11 16:44:44 +08:00
|
|
|
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());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_windows_long("F:\\bar\\baz", FileSpec::Style::windows);
|
2016-03-11 16:44:44 +08:00
|
|
|
EXPECT_STREQ("F:\\bar\\baz", fs_windows_long.GetCString());
|
2016-04-14 17:38:06 +08:00
|
|
|
// EXPECT_STREQ("F:\\bar", fs_windows_long.GetDirectory().GetCString()); // It
|
|
|
|
// returns "F:/bar"
|
2016-03-11 16:44:44 +08:00
|
|
|
EXPECT_STREQ("baz", fs_windows_long.GetFilename().GetCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_posix_trailing_slash("/foo/bar/", FileSpec::Style::posix);
|
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
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_windows_trailing_slash("F:\\bar\\", FileSpec::Style::windows);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FileSpecTest, AppendPathComponent) {
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_posix("/foo", FileSpec::Style::posix);
|
2016-03-11 16:44:44 +08:00
|
|
|
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());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_posix_2("/foo", FileSpec::Style::posix);
|
2016-08-24 01:13:33 +08:00
|
|
|
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());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_windows("F:\\bar", FileSpec::Style::windows);
|
2016-04-04 22:39:12 +08:00
|
|
|
fs_windows.AppendPathComponent("baz");
|
|
|
|
EXPECT_STREQ("F:\\bar\\baz", fs_windows.GetCString());
|
2016-04-14 17:38:06 +08:00
|
|
|
// EXPECT_STREQ("F:\\bar", fs_windows.GetDirectory().GetCString()); // It
|
|
|
|
// returns "F:/bar"
|
2016-04-04 22:39:12 +08:00
|
|
|
EXPECT_STREQ("baz", fs_windows.GetFilename().GetCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_posix_root("/", FileSpec::Style::posix);
|
2016-03-11 16:44:44 +08:00
|
|
|
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());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_windows_root("F:\\", FileSpec::Style::windows);
|
2016-03-11 16:44:44 +08:00
|
|
|
fs_windows_root.AppendPathComponent("bar");
|
|
|
|
EXPECT_STREQ("F:\\bar", fs_windows_root.GetCString());
|
2016-04-14 17:38:06 +08:00
|
|
|
// EXPECT_STREQ("F:\\", fs_windows_root.GetDirectory().GetCString()); // It
|
|
|
|
// returns "F:/"
|
2016-03-11 16:44:44 +08:00
|
|
|
EXPECT_STREQ("bar", fs_windows_root.GetFilename().GetCString());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FileSpecTest, CopyByAppendingPathComponent) {
|
2019-11-28 20:30:39 +08:00
|
|
|
FileSpec fs = PosixSpec("/foo").CopyByAppendingPathComponent("bar");
|
2016-03-11 16:44:44 +08:00
|
|
|
EXPECT_STREQ("/foo/bar", fs.GetCString());
|
|
|
|
EXPECT_STREQ("/foo", fs.GetDirectory().GetCString());
|
|
|
|
EXPECT_STREQ("bar", fs.GetFilename().GetCString());
|
|
|
|
}
|
2016-04-14 17:38:06 +08:00
|
|
|
|
2017-01-16 18:07:02 +08:00
|
|
|
TEST(FileSpecTest, PrependPathComponent) {
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_posix("foo", FileSpec::Style::posix);
|
2017-01-16 18:07:02 +08:00
|
|
|
fs_posix.PrependPathComponent("/bar");
|
|
|
|
EXPECT_STREQ("/bar/foo", fs_posix.GetCString());
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_posix_2("foo/bar", FileSpec::Style::posix);
|
2017-01-16 18:07:02 +08:00
|
|
|
fs_posix_2.PrependPathComponent("/baz");
|
|
|
|
EXPECT_STREQ("/baz/foo/bar", fs_posix_2.GetCString());
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_windows("baz", FileSpec::Style::windows);
|
2017-01-16 18:07:02 +08:00
|
|
|
fs_windows.PrependPathComponent("F:\\bar");
|
|
|
|
EXPECT_STREQ("F:\\bar\\baz", fs_windows.GetCString());
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_posix_root("bar", FileSpec::Style::posix);
|
2017-01-16 18:07:02 +08:00
|
|
|
fs_posix_root.PrependPathComponent("/");
|
|
|
|
EXPECT_STREQ("/bar", fs_posix_root.GetCString());
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_windows_root("bar", FileSpec::Style::windows);
|
2017-01-16 18:07:02 +08:00
|
|
|
fs_windows_root.PrependPathComponent("F:\\");
|
|
|
|
EXPECT_STREQ("F:\\bar", fs_windows_root.GetCString());
|
|
|
|
}
|
|
|
|
|
2016-10-28 19:28:01 +08:00
|
|
|
TEST(FileSpecTest, EqualSeparator) {
|
2019-11-28 20:30:39 +08:00
|
|
|
EXPECT_EQ(WindowsSpec("C:\\foo\\bar"), WindowsSpec("C:/foo/bar"));
|
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) {
|
2019-11-28 20:30:39 +08:00
|
|
|
SCOPED_TRACE(llvm::Twine(test.first) + " <=> " + test.second);
|
|
|
|
EXPECT_EQ(WindowsSpec(test.first), WindowsSpec(test.second));
|
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) {
|
2019-11-28 20:30:39 +08:00
|
|
|
SCOPED_TRACE(llvm::Twine(test.first) + " <=> " + test.second);
|
|
|
|
EXPECT_EQ(PosixSpec(test.first), PosixSpec(test.second));
|
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) {
|
2019-11-28 20:30:39 +08:00
|
|
|
SCOPED_TRACE(llvm::Twine(test.first) + " <=> " + test.second);
|
|
|
|
EXPECT_EQ(PosixSpec(test.first), PosixSpec(test.second));
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-11 22:11:00 +08:00
|
|
|
TEST(FileSpecTest, GuessPathStyle) {
|
|
|
|
EXPECT_EQ(FileSpec::Style::posix, FileSpec::GuessPathStyle("/foo/bar.txt"));
|
|
|
|
EXPECT_EQ(FileSpec::Style::posix, FileSpec::GuessPathStyle("//net/bar.txt"));
|
|
|
|
EXPECT_EQ(FileSpec::Style::windows,
|
|
|
|
FileSpec::GuessPathStyle(R"(C:\foo.txt)"));
|
|
|
|
EXPECT_EQ(FileSpec::Style::windows,
|
|
|
|
FileSpec::GuessPathStyle(R"(\\net\foo.txt)"));
|
|
|
|
EXPECT_EQ(llvm::None, FileSpec::GuessPathStyle("foo.txt"));
|
|
|
|
EXPECT_EQ(llvm::None, FileSpec::GuessPathStyle("foo/bar.txt"));
|
|
|
|
}
|
|
|
|
|
2019-11-28 20:30:39 +08:00
|
|
|
TEST(FileSpecTest, GetPath) {
|
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
|
|
|
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-05-18 00:12:38 +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-05-18 00:12:38 +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);
|
2019-11-28 20:30:39 +08:00
|
|
|
EXPECT_EQ(test.second, PosixSpec(test.first).GetPath());
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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:\)"},
|
2020-05-05 08:24:59 +08:00
|
|
|
{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-05-18 00:12:38 +08:00
|
|
|
{R"(.)", R"(.)"},
|
2020-05-05 08:24:59 +08:00
|
|
|
{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-05-18 00:12:38 +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) {
|
2019-11-28 20:30:39 +08:00
|
|
|
SCOPED_TRACE(llvm::Twine("test.first = ") + test.first);
|
|
|
|
EXPECT_EQ(test.second, WindowsSpec(test.first).GetPath());
|
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) {
|
2018-05-14 22:52:47 +08:00
|
|
|
auto win = FileSpec::Style::windows;
|
2016-12-16 12:27:00 +08:00
|
|
|
|
|
|
|
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());
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
F = FileSpec("C:\\foo\\bar.txt", win);
|
2016-12-16 12:27:00 +08:00
|
|
|
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());
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
F = FileSpec("foo\\bar.txt", win);
|
2016-12-16 12:27:00 +08:00
|
|
|
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());
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
F = FileSpec("foo", win);
|
2016-12-16 12:27:00 +08:00
|
|
|
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
|
|
|
|
2018-05-21 22:14:36 +08:00
|
|
|
TEST(FileSpecTest, IsRelative) {
|
|
|
|
llvm::StringRef not_relative[] = {
|
|
|
|
"/",
|
|
|
|
"/a",
|
|
|
|
"/a/",
|
|
|
|
"/a/b",
|
|
|
|
"/a/b/",
|
|
|
|
"//",
|
|
|
|
"//a/",
|
|
|
|
"//a/b",
|
|
|
|
"//a/b/",
|
|
|
|
"~",
|
|
|
|
"~/",
|
|
|
|
"~/a",
|
|
|
|
"~/a/",
|
2021-04-15 16:02:51 +08:00
|
|
|
"~/a/b",
|
2018-05-21 22:14:36 +08:00
|
|
|
"~/a/b/",
|
|
|
|
"/foo/.",
|
|
|
|
"/foo/..",
|
|
|
|
"/foo/../",
|
|
|
|
"/foo/../.",
|
|
|
|
};
|
|
|
|
for (const auto &path: not_relative) {
|
2019-11-28 20:30:39 +08:00
|
|
|
SCOPED_TRACE(path);
|
|
|
|
EXPECT_FALSE(PosixSpec(path).IsRelative());
|
2018-05-21 22:14:36 +08:00
|
|
|
}
|
|
|
|
llvm::StringRef is_relative[] = {
|
|
|
|
".",
|
|
|
|
"./",
|
|
|
|
".///",
|
|
|
|
"a",
|
|
|
|
"./a",
|
|
|
|
"./a/",
|
|
|
|
"./a/",
|
|
|
|
"./a/b",
|
|
|
|
"./a/b/",
|
|
|
|
"../foo",
|
|
|
|
"foo/bar.c",
|
|
|
|
"./foo/bar.c"
|
|
|
|
};
|
|
|
|
for (const auto &path: is_relative) {
|
2019-11-28 20:30:39 +08:00
|
|
|
SCOPED_TRACE(path);
|
|
|
|
EXPECT_TRUE(PosixSpec(path).IsRelative());
|
2018-05-21 22:14:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-30 21:03:16 +08:00
|
|
|
TEST(FileSpecTest, RemoveLastPathComponent) {
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_posix("/foo/bar/baz", FileSpec::Style::posix);
|
2018-05-30 21:03:16 +08:00
|
|
|
EXPECT_STREQ("/foo/bar/baz", fs_posix.GetCString());
|
|
|
|
EXPECT_TRUE(fs_posix.RemoveLastPathComponent());
|
|
|
|
EXPECT_STREQ("/foo/bar", fs_posix.GetCString());
|
|
|
|
EXPECT_TRUE(fs_posix.RemoveLastPathComponent());
|
|
|
|
EXPECT_STREQ("/foo", fs_posix.GetCString());
|
|
|
|
EXPECT_TRUE(fs_posix.RemoveLastPathComponent());
|
|
|
|
EXPECT_STREQ("/", fs_posix.GetCString());
|
|
|
|
EXPECT_FALSE(fs_posix.RemoveLastPathComponent());
|
|
|
|
EXPECT_STREQ("/", fs_posix.GetCString());
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_posix_relative("./foo/bar/baz", FileSpec::Style::posix);
|
2018-05-30 21:03:16 +08:00
|
|
|
EXPECT_STREQ("foo/bar/baz", fs_posix_relative.GetCString());
|
|
|
|
EXPECT_TRUE(fs_posix_relative.RemoveLastPathComponent());
|
|
|
|
EXPECT_STREQ("foo/bar", fs_posix_relative.GetCString());
|
|
|
|
EXPECT_TRUE(fs_posix_relative.RemoveLastPathComponent());
|
|
|
|
EXPECT_STREQ("foo", fs_posix_relative.GetCString());
|
|
|
|
EXPECT_FALSE(fs_posix_relative.RemoveLastPathComponent());
|
|
|
|
EXPECT_STREQ("foo", fs_posix_relative.GetCString());
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_posix_relative2("./", FileSpec::Style::posix);
|
2018-05-30 21:03:16 +08:00
|
|
|
EXPECT_STREQ(".", fs_posix_relative2.GetCString());
|
|
|
|
EXPECT_FALSE(fs_posix_relative2.RemoveLastPathComponent());
|
|
|
|
EXPECT_STREQ(".", fs_posix_relative2.GetCString());
|
|
|
|
EXPECT_FALSE(fs_posix_relative.RemoveLastPathComponent());
|
|
|
|
EXPECT_STREQ(".", fs_posix_relative2.GetCString());
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec fs_windows("C:\\foo\\bar\\baz", FileSpec::Style::windows);
|
2018-05-30 21:03:16 +08:00
|
|
|
EXPECT_STREQ("C:\\foo\\bar\\baz", fs_windows.GetCString());
|
|
|
|
EXPECT_TRUE(fs_windows.RemoveLastPathComponent());
|
|
|
|
EXPECT_STREQ("C:\\foo\\bar", fs_windows.GetCString());
|
|
|
|
EXPECT_TRUE(fs_windows.RemoveLastPathComponent());
|
|
|
|
EXPECT_STREQ("C:\\foo", fs_windows.GetCString());
|
|
|
|
EXPECT_TRUE(fs_windows.RemoveLastPathComponent());
|
|
|
|
EXPECT_STREQ("C:\\", fs_windows.GetCString());
|
|
|
|
EXPECT_TRUE(fs_windows.RemoveLastPathComponent());
|
|
|
|
EXPECT_STREQ("C:", fs_windows.GetCString());
|
|
|
|
EXPECT_FALSE(fs_windows.RemoveLastPathComponent());
|
|
|
|
EXPECT_STREQ("C:", fs_windows.GetCString());
|
|
|
|
}
|
2019-11-28 20:47:58 +08:00
|
|
|
|
|
|
|
TEST(FileSpecTest, Equal) {
|
|
|
|
auto Eq = [](const char *a, const char *b, bool full) {
|
|
|
|
return FileSpec::Equal(PosixSpec(a), PosixSpec(b), full);
|
|
|
|
};
|
|
|
|
EXPECT_TRUE(Eq("/foo/bar", "/foo/bar", true));
|
|
|
|
EXPECT_TRUE(Eq("/foo/bar", "/foo/bar", false));
|
|
|
|
|
|
|
|
EXPECT_FALSE(Eq("/foo/bar", "/foo/baz", true));
|
|
|
|
EXPECT_FALSE(Eq("/foo/bar", "/foo/baz", false));
|
|
|
|
|
|
|
|
EXPECT_FALSE(Eq("/bar/foo", "/baz/foo", true));
|
|
|
|
EXPECT_FALSE(Eq("/bar/foo", "/baz/foo", false));
|
|
|
|
|
|
|
|
EXPECT_FALSE(Eq("/bar/foo", "foo", true));
|
|
|
|
EXPECT_TRUE(Eq("/bar/foo", "foo", false));
|
|
|
|
|
|
|
|
EXPECT_FALSE(Eq("foo", "/bar/foo", true));
|
|
|
|
EXPECT_TRUE(Eq("foo", "/bar/foo", false));
|
|
|
|
}
|
[lldb] s/FileSpec::Equal/FileSpec::Match
Summary:
The FileSpec class is often used as a sort of a pattern -- one specifies
a bare file name to search, and we check if in matches the full file
name of an existing module (for example).
These comparisons used FileSpec::Equal, which had some support for it
(via the full=false argument), but it was not a good fit for this job.
For one, it did a symmetric comparison, which makes sense for a function
called "equal", but not for typical searches (when searching for
"/foo/bar.so", we don't want to find a module whose name is just
"bar.so"). This resulted in patterns like:
if (FileSpec::Equal(pattern, file, pattern.GetDirectory()))
which would request a "full" match only if the pattern really contained
a directory. This worked, but the intended behavior was very unobvious.
On top of that, a lot of the code wanted to handle the case of an
"empty" pattern, and treat it as matching everything. This resulted in
conditions like:
if (pattern && !FileSpec::Equal(pattern, file, pattern.GetDirectory())
which are nearly impossible to decipher.
This patch introduces a FileSpec::Match function, which does exactly
what most of FileSpec::Equal callers want, an asymmetric match between a
"pattern" FileSpec and a an actual FileSpec. Empty paterns match
everything, filename-only patterns match only the filename component.
I've tried to update all callers of FileSpec::Equal to use a simpler
interface. Those that hardcoded full=true have been changed to use
operator==. Those passing full=pattern.GetDirectory() have been changed
to use FileSpec::Match.
There was also a handful of places which hardcoded full=false. I've
changed these to use FileSpec::Match too. This is a slight change in
semantics, but it does not look like that was ever intended, and it was
more likely a result of a misunderstanding of the "proper" way to use
FileSpec::Equal.
[In an ideal world a "FileSpec" and a "FileSpec pattern" would be two
different types, but given how widespread FileSpec is, it is unlikely
we'll get there in one go. This at least provides a good starting point
by centralizing all matching behavior.]
Reviewers: teemperor, JDevlieghere, jdoerfert
Subscribers: emaste, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D70851
2019-11-29 18:31:00 +08:00
|
|
|
|
|
|
|
TEST(FileSpecTest, Match) {
|
|
|
|
auto Match = [](const char *pattern, const char *file) {
|
|
|
|
return FileSpec::Match(PosixSpec(pattern), PosixSpec(file));
|
|
|
|
};
|
|
|
|
EXPECT_TRUE(Match("/foo/bar", "/foo/bar"));
|
|
|
|
EXPECT_FALSE(Match("/foo/bar", "/oof/bar"));
|
|
|
|
EXPECT_FALSE(Match("/foo/bar", "/foo/baz"));
|
|
|
|
EXPECT_FALSE(Match("/foo/bar", "bar"));
|
|
|
|
EXPECT_FALSE(Match("/foo/bar", ""));
|
|
|
|
|
|
|
|
EXPECT_TRUE(Match("bar", "/foo/bar"));
|
|
|
|
EXPECT_FALSE(Match("bar", "/foo/baz"));
|
|
|
|
EXPECT_TRUE(Match("bar", "bar"));
|
|
|
|
EXPECT_FALSE(Match("bar", "baz"));
|
|
|
|
EXPECT_FALSE(Match("bar", ""));
|
|
|
|
|
|
|
|
EXPECT_TRUE(Match("", "/foo/bar"));
|
|
|
|
EXPECT_TRUE(Match("", ""));
|
|
|
|
|
|
|
|
}
|
2020-03-13 00:51:59 +08:00
|
|
|
|
|
|
|
TEST(FileSpecTest, Yaml) {
|
|
|
|
std::string buffer;
|
|
|
|
llvm::raw_string_ostream os(buffer);
|
|
|
|
|
|
|
|
// Serialize.
|
|
|
|
FileSpec fs_windows("F:\\bar", FileSpec::Style::windows);
|
|
|
|
llvm::yaml::Output yout(os);
|
|
|
|
yout << fs_windows;
|
|
|
|
os.flush();
|
|
|
|
|
|
|
|
// Deserialize.
|
|
|
|
FileSpec deserialized;
|
|
|
|
llvm::yaml::Input yin(buffer);
|
|
|
|
yin >> deserialized;
|
|
|
|
|
|
|
|
EXPECT_EQ(deserialized.GetPathStyle(), fs_windows.GetPathStyle());
|
|
|
|
EXPECT_EQ(deserialized.GetFilename(), fs_windows.GetFilename());
|
|
|
|
EXPECT_EQ(deserialized.GetDirectory(), fs_windows.GetDirectory());
|
|
|
|
EXPECT_EQ(deserialized, fs_windows);
|
|
|
|
}
|
2020-03-19 05:59:54 +08:00
|
|
|
|
|
|
|
TEST(FileSpecTest, OperatorBool) {
|
|
|
|
EXPECT_FALSE(FileSpec());
|
|
|
|
EXPECT_FALSE(FileSpec(""));
|
|
|
|
EXPECT_TRUE(FileSpec("/foo/bar"));
|
|
|
|
}
|