diff options
author | Sylvain Audi <sylvain.audi@ubisoft.com> | 2020-04-29 12:50:37 -0400 |
---|---|---|
committer | Sylvain Audi <sylvain.audi@ubisoft.com> | 2020-05-13 13:49:14 -0400 |
commit | 7a8edcb2124b60941ef6ea4bb4b38a9eb0d70137 (patch) | |
tree | 6e6e17e69e14eed67c2f745cd6153e9571571284 /llvm/unittests/Support/Path.cpp | |
parent | 33d96bf7b9b2add1c45bf1c60195dc7ca961393e (diff) | |
download | llvm-7a8edcb2124b60941ef6ea4bb4b38a9eb0d70137.zip llvm-7a8edcb2124b60941ef6ea4bb4b38a9eb0d70137.tar.gz llvm-7a8edcb2124b60941ef6ea4bb4b38a9eb0d70137.tar.bz2 |
[Clang] Restore replace_path_prefix instead of startswith
In D49466, sys::path::replace_path_prefix was used instead startswith for -f[macro/debug/file]-prefix-map options.
However those were reverted later (commit rG3bb24bf25767ef5bbcef958b484e7a06d8689204) due to broken Windows tests.
This patch restores those replace_path_prefix calls.
It also modifies the prefix matching to be case-insensitive under Windows.
Differential Revision : https://reviews.llvm.org/D76869
Diffstat (limited to 'llvm/unittests/Support/Path.cpp')
-rw-r--r-- | llvm/unittests/Support/Path.cpp | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index a577f1b..8e842a9 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -1311,48 +1311,73 @@ TEST(Support, ReplacePathPrefix) { SmallString<64> Path1("/foo"); SmallString<64> Path2("/old/foo"); SmallString<64> Path3("/oldnew/foo"); + SmallString<64> Path4("C:\\old/foo\\bar"); SmallString<64> OldPrefix("/old"); SmallString<64> OldPrefixSep("/old/"); + SmallString<64> OldPrefixWin("c:/oLD/F"); SmallString<64> NewPrefix("/new"); SmallString<64> NewPrefix2("/longernew"); SmallString<64> EmptyPrefix(""); + bool Found; SmallString<64> Path = Path1; - path::replace_path_prefix(Path, OldPrefix, NewPrefix); + Found = path::replace_path_prefix(Path, OldPrefix, NewPrefix); + EXPECT_FALSE(Found); EXPECT_EQ(Path, "/foo"); Path = Path2; - path::replace_path_prefix(Path, OldPrefix, NewPrefix); + Found = path::replace_path_prefix(Path, OldPrefix, NewPrefix); + EXPECT_TRUE(Found); EXPECT_EQ(Path, "/new/foo"); Path = Path2; - path::replace_path_prefix(Path, OldPrefix, NewPrefix2); + Found = path::replace_path_prefix(Path, OldPrefix, NewPrefix2); + EXPECT_TRUE(Found); EXPECT_EQ(Path, "/longernew/foo"); Path = Path1; - path::replace_path_prefix(Path, EmptyPrefix, NewPrefix); + Found = path::replace_path_prefix(Path, EmptyPrefix, NewPrefix); + EXPECT_TRUE(Found); EXPECT_EQ(Path, "/new/foo"); Path = Path2; - path::replace_path_prefix(Path, OldPrefix, EmptyPrefix); + Found = path::replace_path_prefix(Path, OldPrefix, EmptyPrefix); + EXPECT_TRUE(Found); EXPECT_EQ(Path, "/foo"); Path = Path2; - path::replace_path_prefix(Path, OldPrefixSep, EmptyPrefix); + Found = path::replace_path_prefix(Path, OldPrefixSep, EmptyPrefix); + EXPECT_TRUE(Found); EXPECT_EQ(Path, "foo"); Path = Path3; - path::replace_path_prefix(Path, OldPrefix, NewPrefix); + Found = path::replace_path_prefix(Path, OldPrefix, NewPrefix); + EXPECT_TRUE(Found); EXPECT_EQ(Path, "/newnew/foo"); Path = Path3; - path::replace_path_prefix(Path, OldPrefix, NewPrefix2); + Found = path::replace_path_prefix(Path, OldPrefix, NewPrefix2); + EXPECT_TRUE(Found); EXPECT_EQ(Path, "/longernewnew/foo"); Path = Path1; - path::replace_path_prefix(Path, EmptyPrefix, NewPrefix); + Found = path::replace_path_prefix(Path, EmptyPrefix, NewPrefix); + EXPECT_TRUE(Found); EXPECT_EQ(Path, "/new/foo"); Path = OldPrefix; - path::replace_path_prefix(Path, OldPrefix, NewPrefix); + Found = path::replace_path_prefix(Path, OldPrefix, NewPrefix); + EXPECT_TRUE(Found); EXPECT_EQ(Path, "/new"); Path = OldPrefixSep; - path::replace_path_prefix(Path, OldPrefix, NewPrefix); + Found = path::replace_path_prefix(Path, OldPrefix, NewPrefix); + EXPECT_TRUE(Found); EXPECT_EQ(Path, "/new/"); Path = OldPrefix; - path::replace_path_prefix(Path, OldPrefixSep, NewPrefix); + Found = path::replace_path_prefix(Path, OldPrefixSep, NewPrefix); + EXPECT_FALSE(Found); EXPECT_EQ(Path, "/old"); + Path = Path4; + Found = path::replace_path_prefix(Path, OldPrefixWin, NewPrefix, + path::Style::windows); + EXPECT_TRUE(Found); + EXPECT_EQ(Path, "/newoo\\bar"); + Path = Path4; + Found = path::replace_path_prefix(Path, OldPrefixWin, NewPrefix, + path::Style::posix); + EXPECT_FALSE(Found); + EXPECT_EQ(Path, "C:\\old/foo\\bar"); } TEST_F(FileSystemTest, OpenFileForRead) { |