From 99023627010bbfefb71e25a2b4d056de1cbd354e Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Thu, 21 Oct 2021 18:33:24 -0700 Subject: Support: Use sys::path::is_style_{posix,windows}() in a few places Use the new sys::path::is_style_posix() and is_style_windows() in a few places that need to detect the system's native path style. In llvm/lib/Support/Path.cpp, this patch removes most uses of the private `real_style()`, where is_style_posix() and is_style_windows() are just a little tidier. Elsewhere, this removes `_WIN32` macro checks. Added a FIXME to a FileManagerTest that seemed fishy, but maintained the existing behaviour. Differential Revision: https://reviews.llvm.org/D112289 --- clang/unittests/Tooling/RefactoringTest.cpp | 31 ++++++++++------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'clang/unittests/Tooling/RefactoringTest.cpp') diff --git a/clang/unittests/Tooling/RefactoringTest.cpp b/clang/unittests/Tooling/RefactoringTest.cpp index d239aba..c71a724 100644 --- a/clang/unittests/Tooling/RefactoringTest.cpp +++ b/clang/unittests/Tooling/RefactoringTest.cpp @@ -1031,18 +1031,17 @@ TEST_F(MergeReplacementsTest, OverlappingRanges) { toReplacements({{"", 0, 3, "cc"}, {"", 3, 3, "dd"}})); } +static constexpr bool usesWindowsPaths() { + return is_style_windows(llvm::sys::path::Style::native); +} + TEST(DeduplicateByFileTest, PathsWithDots) { std::map FileToReplaces; llvm::IntrusiveRefCntPtr VFS( new llvm::vfs::InMemoryFileSystem()); FileManager FileMgr(FileSystemOptions(), VFS); -#if !defined(_WIN32) - StringRef Path1 = "a/b/.././c.h"; - StringRef Path2 = "a/c.h"; -#else - StringRef Path1 = "a\\b\\..\\.\\c.h"; - StringRef Path2 = "a\\c.h"; -#endif + StringRef Path1 = usesWindowsPaths() ? "a\\b\\..\\.\\c.h" : "a/b/.././c.h"; + StringRef Path2 = usesWindowsPaths() ? "a\\c.h" : "a/c.h"; EXPECT_TRUE(VFS->addFile(Path1, 0, llvm::MemoryBuffer::getMemBuffer(""))); EXPECT_TRUE(VFS->addFile(Path2, 0, llvm::MemoryBuffer::getMemBuffer(""))); FileToReplaces[std::string(Path1)] = Replacements(); @@ -1057,13 +1056,8 @@ TEST(DeduplicateByFileTest, PathWithDotSlash) { llvm::IntrusiveRefCntPtr VFS( new llvm::vfs::InMemoryFileSystem()); FileManager FileMgr(FileSystemOptions(), VFS); -#if !defined(_WIN32) - StringRef Path1 = "./a/b/c.h"; - StringRef Path2 = "a/b/c.h"; -#else - StringRef Path1 = ".\\a\\b\\c.h"; - StringRef Path2 = "a\\b\\c.h"; -#endif + StringRef Path1 = usesWindowsPaths() ? ".\\a\\b\\c.h" : "./a/b/c.h"; + StringRef Path2 = usesWindowsPaths() ? "a\\b\\c.h" : "a/b/c.h"; EXPECT_TRUE(VFS->addFile(Path1, 0, llvm::MemoryBuffer::getMemBuffer(""))); EXPECT_TRUE(VFS->addFile(Path2, 0, llvm::MemoryBuffer::getMemBuffer(""))); FileToReplaces[std::string(Path1)] = Replacements(); @@ -1078,13 +1072,8 @@ TEST(DeduplicateByFileTest, NonExistingFilePath) { llvm::IntrusiveRefCntPtr VFS( new llvm::vfs::InMemoryFileSystem()); FileManager FileMgr(FileSystemOptions(), VFS); -#if !defined(_WIN32) - StringRef Path1 = "./a/b/c.h"; - StringRef Path2 = "a/b/c.h"; -#else - StringRef Path1 = ".\\a\\b\\c.h"; - StringRef Path2 = "a\\b\\c.h"; -#endif + StringRef Path1 = usesWindowsPaths() ? ".\\a\\b\\c.h" : "./a/b/c.h"; + StringRef Path2 = usesWindowsPaths() ? "a\\b\\c.h" : "a/b/c.h"; FileToReplaces[std::string(Path1)] = Replacements(); FileToReplaces[std::string(Path2)] = Replacements(); FileToReplaces = groupReplacementsByFile(FileMgr, FileToReplaces); -- cgit v1.1