diff options
author | Taewook Oh <twoh@fb.com> | 2016-06-13 15:54:56 +0000 |
---|---|---|
committer | Taewook Oh <twoh@fb.com> | 2016-06-13 15:54:56 +0000 |
commit | 4133ef3efbd1c571c6a57f8876ac58d0e38566df (patch) | |
tree | bd51f133b7c3b8dbcc2ec5e3b339b481800bab88 /unittests | |
parent | 8cd24fa64405074faa3e60ebbf0f8c4c5289420f (diff) |
In openFileForRead, attempt to fetch the actual name of the file on disk -- including case -- so that clang can later warn about non-portable #include and #import directives.
Differential Revision: http://reviews.llvm.org/D19842
Corresponding clang patch: http://reviews.llvm.org/D19843
Re-commit after addressing issues with of generating too many warnings for Windows and asan test failures
Patch by Eric Niebler
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272555 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Support/Path.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp index ad2267d596c..705a90bd0a3 100644 --- a/unittests/Support/Path.cpp +++ b/unittests/Support/Path.cpp @@ -995,4 +995,61 @@ TEST(Support, ReplacePathPrefix) { path::replace_path_prefix(Path, OldPrefix, EmptyPrefix); EXPECT_EQ(Path, "/foo"); } + +TEST_F(FileSystemTest, PathFromFD) { + // Create a temp file. + int FileDescriptor; + SmallString<64> TempPath; + ASSERT_NO_ERROR( + fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath)); + + // Make sure it exists. + ASSERT_TRUE(sys::fs::exists(Twine(TempPath))); + + // Try to get the path from the file descriptor + SmallString<64> ResultPath; + std::error_code ErrorCode = + fs::getPathFromOpenFD(FileDescriptor, ResultPath); + + // If we succeeded, check that the paths are the same (modulo case): + if (!ErrorCode) { + // The paths returned by createTemporaryFile and getPathFromOpenFD + // should reference the same file on disk. + fs::UniqueID D1, D2; + ASSERT_NO_ERROR(fs::getUniqueID(Twine(TempPath), D1)); + ASSERT_NO_ERROR(fs::getUniqueID(Twine(ResultPath), D2)); + ASSERT_EQ(D1, D2); + } + + ::close(FileDescriptor); +} + +TEST_F(FileSystemTest, OpenFileForRead) { + // Create a temp file. + int FileDescriptor; + SmallString<64> TempPath; + ASSERT_NO_ERROR( + fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath)); + + // Make sure it exists. + ASSERT_TRUE(sys::fs::exists(Twine(TempPath))); + + // Open the file for read + int FileDescriptor2; + SmallString<64> ResultPath; + ASSERT_NO_ERROR( + fs::openFileForRead(Twine(TempPath), FileDescriptor2, &ResultPath)) + + // If we succeeded, check that the paths are the same (modulo case): + if (!ResultPath.empty()) { + // The paths returned by createTemporaryFile and getPathFromOpenFD + // should reference the same file on disk. + fs::UniqueID D1, D2; + ASSERT_NO_ERROR(fs::getUniqueID(Twine(TempPath), D1)); + ASSERT_NO_ERROR(fs::getUniqueID(Twine(ResultPath), D2)); + ASSERT_EQ(D1, D2); + } + + ::close(FileDescriptor); +} } // anonymous namespace |