[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
|
|
|
//===-- PathMappingListTest.cpp -------------------------------------------===//
|
2018-05-21 22:14:36 +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
|
2018-05-21 22:14:36 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Target/PathMappingList.h"
|
|
|
|
#include "lldb/Utility/FileSpec.h"
|
2021-06-30 06:24:36 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2018-05-21 22:14:36 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
namespace {
|
2018-05-23 18:32:05 +08:00
|
|
|
struct Matches {
|
|
|
|
FileSpec original;
|
|
|
|
FileSpec remapped;
|
2018-11-02 05:05:36 +08:00
|
|
|
Matches(const char *o, const char *r) : original(o), remapped(r) {}
|
2021-06-30 06:24:36 +08:00
|
|
|
Matches(const char *o, llvm::sys::path::Style style, const char *r)
|
|
|
|
: original(o, style), remapped(r) {}
|
2018-05-23 18:32:05 +08:00
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
static void TestPathMappings(const PathMappingList &map,
|
|
|
|
llvm::ArrayRef<Matches> matches,
|
|
|
|
llvm::ArrayRef<ConstString> fails) {
|
|
|
|
ConstString actual_remapped;
|
|
|
|
for (const auto &fail : fails) {
|
2018-06-14 18:31:06 +08:00
|
|
|
SCOPED_TRACE(fail.GetCString());
|
|
|
|
EXPECT_FALSE(map.RemapPath(fail, actual_remapped))
|
|
|
|
<< "actual_remapped: " << actual_remapped.GetCString();
|
2018-05-23 18:32:05 +08:00
|
|
|
}
|
|
|
|
for (const auto &match : matches) {
|
2018-06-14 18:31:06 +08:00
|
|
|
SCOPED_TRACE(match.original.GetPath() + " -> " + match.remapped.GetPath());
|
2018-05-23 18:32:05 +08:00
|
|
|
std::string orig_normalized = match.original.GetPath();
|
|
|
|
EXPECT_TRUE(
|
|
|
|
map.RemapPath(ConstString(match.original.GetPath()), actual_remapped));
|
2018-11-02 05:05:36 +08:00
|
|
|
EXPECT_EQ(FileSpec(actual_remapped.GetStringRef()), match.remapped);
|
2018-05-23 18:32:05 +08:00
|
|
|
FileSpec unmapped_spec;
|
|
|
|
EXPECT_TRUE(map.ReverseRemapPath(match.remapped, unmapped_spec));
|
|
|
|
std::string unmapped_path = unmapped_spec.GetPath();
|
|
|
|
EXPECT_EQ(unmapped_path, orig_normalized);
|
2018-05-21 22:14:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(PathMappingListTest, RelativeTests) {
|
|
|
|
Matches matches[] = {
|
|
|
|
{".", "/tmp"},
|
|
|
|
{"./", "/tmp"},
|
|
|
|
{"./////", "/tmp"},
|
|
|
|
{"./foo.c", "/tmp/foo.c"},
|
|
|
|
{"foo.c", "/tmp/foo.c"},
|
|
|
|
{"./bar/foo.c", "/tmp/bar/foo.c"},
|
|
|
|
{"bar/foo.c", "/tmp/bar/foo.c"},
|
|
|
|
};
|
|
|
|
ConstString fails[] = {
|
2018-06-14 18:31:06 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
ConstString("C:\\"),
|
|
|
|
ConstString("C:\\a"),
|
|
|
|
#else
|
|
|
|
ConstString("/a"),
|
|
|
|
ConstString("/"),
|
|
|
|
#endif
|
2018-05-21 22:14:36 +08:00
|
|
|
};
|
|
|
|
PathMappingList map;
|
|
|
|
map.Append(ConstString("."), ConstString("/tmp"), false);
|
|
|
|
TestPathMappings(map, matches, fails);
|
|
|
|
PathMappingList map2;
|
|
|
|
map2.Append(ConstString(""), ConstString("/tmp"), false);
|
|
|
|
TestPathMappings(map, matches, fails);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(PathMappingListTest, AbsoluteTests) {
|
|
|
|
PathMappingList map;
|
|
|
|
map.Append(ConstString("/old"), ConstString("/new"), false);
|
|
|
|
Matches matches[] = {
|
|
|
|
{"/old", "/new"},
|
|
|
|
{"/old/", "/new"},
|
|
|
|
{"/old/foo/.", "/new/foo"},
|
|
|
|
{"/old/foo.c", "/new/foo.c"},
|
|
|
|
{"/old/foo.c/.", "/new/foo.c"},
|
|
|
|
{"/old/./foo.c", "/new/foo.c"},
|
|
|
|
};
|
|
|
|
ConstString fails[] = {
|
|
|
|
ConstString("/foo"),
|
|
|
|
ConstString("/"),
|
|
|
|
ConstString("foo.c"),
|
|
|
|
ConstString("./foo.c"),
|
|
|
|
ConstString("../foo.c"),
|
|
|
|
ConstString("../bar/foo.c"),
|
|
|
|
};
|
|
|
|
TestPathMappings(map, matches, fails);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(PathMappingListTest, RemapRoot) {
|
|
|
|
PathMappingList map;
|
|
|
|
map.Append(ConstString("/"), ConstString("/new"), false);
|
|
|
|
Matches matches[] = {
|
|
|
|
{"/old", "/new/old"},
|
|
|
|
{"/old/", "/new/old"},
|
|
|
|
{"/old/foo/.", "/new/old/foo"},
|
|
|
|
{"/old/foo.c", "/new/old/foo.c"},
|
|
|
|
{"/old/foo.c/.", "/new/old/foo.c"},
|
|
|
|
{"/old/./foo.c", "/new/old/foo.c"},
|
|
|
|
};
|
|
|
|
ConstString fails[] = {
|
|
|
|
ConstString("foo.c"),
|
|
|
|
ConstString("./foo.c"),
|
|
|
|
ConstString("../foo.c"),
|
|
|
|
ConstString("../bar/foo.c"),
|
|
|
|
};
|
|
|
|
TestPathMappings(map, matches, fails);
|
|
|
|
}
|
2021-06-30 06:24:36 +08:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
TEST(PathMappingListTest, CrossPlatformTests) {
|
|
|
|
PathMappingList map;
|
|
|
|
map.Append(ConstString(R"(C:\old)"), ConstString("/new"), false);
|
|
|
|
Matches matches[] = {
|
|
|
|
{R"(C:\old)", llvm::sys::path::Style::windows, "/new"},
|
|
|
|
{R"(C:\old\)", llvm::sys::path::Style::windows, "/new"},
|
|
|
|
{R"(C:\old\foo\.)", llvm::sys::path::Style::windows, "/new/foo"},
|
|
|
|
{R"(C:\old\foo.c)", llvm::sys::path::Style::windows, "/new/foo.c"},
|
|
|
|
{R"(C:\old\foo.c\.)", llvm::sys::path::Style::windows, "/new/foo.c"},
|
|
|
|
{R"(C:\old\.\foo.c)", llvm::sys::path::Style::windows, "/new/foo.c"},
|
|
|
|
};
|
|
|
|
ConstString fails[] = {
|
|
|
|
ConstString("/foo"),
|
|
|
|
ConstString("/"),
|
|
|
|
ConstString("foo.c"),
|
|
|
|
ConstString("./foo.c"),
|
|
|
|
ConstString("../foo.c"),
|
|
|
|
ConstString("../bar/foo.c"),
|
|
|
|
};
|
|
|
|
TestPathMappings(map, matches, fails);
|
|
|
|
}
|
|
|
|
#endif
|