diff options
Diffstat (limited to 'clang/unittests/Basic/VirtualFileSystemTest.cpp')
-rw-r--r-- | clang/unittests/Basic/VirtualFileSystemTest.cpp | 59 |
1 files changed, 10 insertions, 49 deletions
diff --git a/clang/unittests/Basic/VirtualFileSystemTest.cpp b/clang/unittests/Basic/VirtualFileSystemTest.cpp index a9b39b5b13f..c795be07acf 100644 --- a/clang/unittests/Basic/VirtualFileSystemTest.cpp +++ b/clang/unittests/Basic/VirtualFileSystemTest.cpp @@ -13,7 +13,6 @@ #include "llvm/Support/Errc.h" #include "llvm/Support/Host.h" #include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/Path.h" #include "llvm/Support/SourceMgr.h" #include "gtest/gtest.h" #include <map> @@ -152,13 +151,6 @@ public: addEntry(Path, S); } }; - -/// Replace back-slashes by front-slashes. -std::string getPosixPath(std::string S) { - SmallString<128> Result; - llvm::sys::path::native(S, Result, llvm::sys::path::Style::posix); - return Result.str(); -}; } // end anonymous namespace TEST(VirtualFileSystemTest, StatusQueries) { @@ -790,9 +782,7 @@ TEST_F(InMemoryFileSystemTest, DirectoryIteration) { I = FS.dir_begin("/b", EC); ASSERT_FALSE(EC); - // When on Windows, we end up with "/b\\c" as the name. Convert to Posix - // path for the sake of the comparison. - ASSERT_EQ("/b/c", getPosixPath(I->getName())); + ASSERT_EQ("/b/c", I->getName()); I.increment(EC); ASSERT_FALSE(EC); ASSERT_EQ(vfs::directory_iterator(), I); @@ -804,19 +794,23 @@ TEST_F(InMemoryFileSystemTest, WorkingDirectory) { auto Stat = FS.status("/b/c"); ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString(); - ASSERT_EQ("/b/c", Stat->getName()); + ASSERT_EQ("c", Stat->getName()); ASSERT_EQ("/b", *FS.getCurrentWorkingDirectory()); Stat = FS.status("c"); ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString(); + auto ReplaceBackslashes = [](std::string S) { + std::replace(S.begin(), S.end(), '\\', '/'); + return S; + }; NormalizedFS.setCurrentWorkingDirectory("/b/c"); NormalizedFS.setCurrentWorkingDirectory("."); - ASSERT_EQ("/b/c", - getPosixPath(NormalizedFS.getCurrentWorkingDirectory().get())); + ASSERT_EQ("/b/c", ReplaceBackslashes( + NormalizedFS.getCurrentWorkingDirectory().get())); NormalizedFS.setCurrentWorkingDirectory(".."); - ASSERT_EQ("/b", - getPosixPath(NormalizedFS.getCurrentWorkingDirectory().get())); + ASSERT_EQ("/b", ReplaceBackslashes( + NormalizedFS.getCurrentWorkingDirectory().get())); } #if !defined(_WIN32) @@ -925,39 +919,6 @@ TEST_F(InMemoryFileSystemTest, AddDirectoryThenAddChild) { ASSERT_TRUE(Stat->isRegularFile()); } -// Test that the name returned by status() is in the same form as the path that -// was requested (to match the behavior of RealFileSystem). -TEST_F(InMemoryFileSystemTest, StatusName) { - NormalizedFS.addFile("/a/b/c", 0, MemoryBuffer::getMemBuffer("abc"), - /*User=*/None, - /*Group=*/None, sys::fs::file_type::regular_file); - NormalizedFS.setCurrentWorkingDirectory("/a/b"); - - // Access using InMemoryFileSystem::status. - auto Stat = NormalizedFS.status("../b/c"); - ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" - << NormalizedFS.toString(); - ASSERT_TRUE(Stat->isRegularFile()); - ASSERT_EQ("../b/c", Stat->getName()); - - // Access using InMemoryFileAdaptor::status. - auto File = NormalizedFS.openFileForRead("../b/c"); - ASSERT_FALSE(File.getError()) << File.getError() << "\n" - << NormalizedFS.toString(); - Stat = (*File)->status(); - ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" - << NormalizedFS.toString(); - ASSERT_TRUE(Stat->isRegularFile()); - ASSERT_EQ("../b/c", Stat->getName()); - - // Access using a directory iterator. - std::error_code EC; - clang::vfs::directory_iterator It = NormalizedFS.dir_begin("../b", EC); - // When on Windows, we end up with "../b\\c" as the name. Convert to Posix - // path for the sake of the comparison. - ASSERT_EQ("../b/c", getPosixPath(It->getName())); -} - // NOTE: in the tests below, we use '//root/' as our root directory, since it is // a legal *absolute* path on Windows as well as *nix. class VFSFromYAMLTest : public ::testing::Test { |