diff options
Diffstat (limited to 'clang/unittests/Basic/FileManagerTest.cpp')
-rw-r--r-- | clang/unittests/Basic/FileManagerTest.cpp | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/clang/unittests/Basic/FileManagerTest.cpp b/clang/unittests/Basic/FileManagerTest.cpp index a122747..3c058a0 100644 --- a/clang/unittests/Basic/FileManagerTest.cpp +++ b/clang/unittests/Basic/FileManagerTest.cpp @@ -31,18 +31,18 @@ private: void InjectFileOrDirectory(const char *Path, ino_t INode, bool IsFile, const char *StatPath) { -#ifndef _WIN32 SmallString<128> NormalizedPath(Path); - llvm::sys::path::native(NormalizedPath); - Path = NormalizedPath.c_str(); - SmallString<128> NormalizedStatPath; - if (StatPath) { - NormalizedStatPath = StatPath; - llvm::sys::path::native(NormalizedStatPath); - StatPath = NormalizedStatPath.c_str(); + if (is_style_posix(llvm::sys::path::Style::native)) { + llvm::sys::path::native(NormalizedPath); + Path = NormalizedPath.c_str(); + + if (StatPath) { + NormalizedStatPath = StatPath; + llvm::sys::path::native(NormalizedStatPath); + StatPath = NormalizedStatPath.c_str(); + } } -#endif if (!StatPath) StatPath = Path; @@ -74,11 +74,11 @@ public: bool isFile, std::unique_ptr<llvm::vfs::File> *F, llvm::vfs::FileSystem &FS) override { -#ifndef _WIN32 SmallString<128> NormalizedPath(Path); - llvm::sys::path::native(NormalizedPath); - Path = NormalizedPath.c_str(); -#endif + if (is_style_posix(llvm::sys::path::Style::native)) { + llvm::sys::path::native(NormalizedPath); + Path = NormalizedPath.c_str(); + } if (StatCalls.count(Path) != 0) { Status = StatCalls[Path]; @@ -436,13 +436,16 @@ TEST_F(FileManagerTest, getVirtualFileWithDifferentName) { #endif // !_WIN32 +static StringRef getSystemRoot() { + return is_style_windows(llvm::sys::path::Style::native) ? "C:/" : "/"; +} + TEST_F(FileManagerTest, makeAbsoluteUsesVFS) { - SmallString<64> CustomWorkingDir; -#ifdef _WIN32 - CustomWorkingDir = "C:"; -#else - CustomWorkingDir = "/"; -#endif + // FIXME: Should this be using a root path / call getSystemRoot()? For now, + // avoiding that and leaving the test as-is. + SmallString<64> CustomWorkingDir = + is_style_windows(llvm::sys::path::Style::native) ? StringRef("C:") + : StringRef("/"); llvm::sys::path::append(CustomWorkingDir, "some", "weird", "path"); auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>( @@ -464,12 +467,7 @@ TEST_F(FileManagerTest, makeAbsoluteUsesVFS) { // getVirtualFile should always fill the real path. TEST_F(FileManagerTest, getVirtualFileFillsRealPathName) { - SmallString<64> CustomWorkingDir; -#ifdef _WIN32 - CustomWorkingDir = "C:/"; -#else - CustomWorkingDir = "/"; -#endif + SmallString<64> CustomWorkingDir = getSystemRoot(); auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>( new llvm::vfs::InMemoryFileSystem); @@ -497,12 +495,7 @@ TEST_F(FileManagerTest, getVirtualFileFillsRealPathName) { } TEST_F(FileManagerTest, getFileDontOpenRealPath) { - SmallString<64> CustomWorkingDir; -#ifdef _WIN32 - CustomWorkingDir = "C:/"; -#else - CustomWorkingDir = "/"; -#endif + SmallString<64> CustomWorkingDir = getSystemRoot(); auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>( new llvm::vfs::InMemoryFileSystem); |