This repository has been archived by the owner on Apr 2, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix PathMappingList for relative and empty paths after recent FileSpe…
…c normalization changes PathMappingList was broken for relative and empty paths after normalization changes in FileSpec. There were also no tests for PathMappingList so I added those. Changes include: Change PathMappingList::ReverseRemapPath() to take FileSpec objects instead of ConstString. The only client of this was doing work to convert to and from ConstString objects for no reason. Normalize all paths prefix and replacements that are added to the PathMappingList vector so they match the paths that have been already normalized in the debug info Unify code in the two forms of PathMappingList::RemapPath() so only one contains the actual functionality. Prior to this, there were two versions of this code. Use FileSpec::AppendPathComponent() and remove a long standing TODO so paths are correctly appended to each other. Added tests for absolute, relative and empty paths. Differential Revision: https://reviews.llvm.org/D47021 git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@332842 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Greg Clayton
committed
May 21, 2018
1 parent
8a615ff
commit 327df73
Showing
8 changed files
with
248 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
//===-- PathMappingListTest.cpp ---------------------------------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/ADT/ArrayRef.h" | ||
#include "lldb/Target/PathMappingList.h" | ||
#include "lldb/Utility/FileSpec.h" | ||
#include "gtest/gtest.h" | ||
#include <utility> | ||
|
||
using namespace lldb_private; | ||
|
||
namespace { | ||
struct Matches { | ||
ConstString original; | ||
ConstString remapped; | ||
Matches(const char *o, const char *r) : original(o), | ||
remapped(r) {} | ||
}; | ||
|
||
void TestPathMappings(const PathMappingList &map, | ||
llvm::ArrayRef<Matches> matches, | ||
llvm::ArrayRef<ConstString> fails) { | ||
ConstString actual_remapped; | ||
for (const auto &fail: fails) { | ||
EXPECT_FALSE(map.RemapPath(fail, actual_remapped)); | ||
} | ||
for (const auto &match: matches) { | ||
FileSpec orig_spec(match.original.GetStringRef(), false); | ||
std::string orig_normalized = orig_spec.GetPath(); | ||
EXPECT_TRUE(map.RemapPath(match.original, actual_remapped)); | ||
EXPECT_EQ(actual_remapped, match.remapped); | ||
FileSpec remapped_spec(match.remapped.GetStringRef(), false); | ||
FileSpec unmapped_spec; | ||
EXPECT_TRUE(map.ReverseRemapPath(remapped_spec, unmapped_spec)); | ||
std::string unmapped_path = unmapped_spec.GetPath(); | ||
EXPECT_EQ(unmapped_path, orig_normalized); | ||
} | ||
} | ||
} | ||
|
||
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[] = { | ||
ConstString("/a"), | ||
ConstString("/"), | ||
}; | ||
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); | ||
} |
Oops, something went wrong.