diff options
author | Harlan Haskins <harlan@harlanhaskins.com> | 2019-08-01 21:31:56 +0000 |
---|---|---|
committer | Harlan Haskins <harlan@harlanhaskins.com> | 2019-08-01 21:31:56 +0000 |
commit | 43696f88090b4e80468c1f91161767a7a7c43db9 (patch) | |
tree | 30df11f21f724050a17521406fe5b3b57c16bc49 /unittests | |
parent | 2b41d1ddfc16bbd20185dd4a5847066b6299feeb (diff) | |
download | clang-43696f88090b4e80468c1f91161767a7a7c43db9.tar.gz |
[clang] Adopt new FileManager error-returning APIs
Update the callers of FileManager::getFile and FileManager::getDirectory to handle the new llvm::ErrorOr-returning methods.
Signed-off-by: Harlan Haskins <harlan@apple.com>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@367616 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Basic/FileManagerTest.cpp | 22 | ||||
-rw-r--r-- | unittests/Lex/HeaderSearchTest.cpp | 4 | ||||
-rw-r--r-- | unittests/Lex/PPCallbacksTest.cpp | 4 | ||||
-rw-r--r-- | unittests/Tooling/RefactoringTest.cpp | 7 | ||||
-rw-r--r-- | unittests/Tooling/RewriterTestContext.h | 12 |
5 files changed, 30 insertions, 19 deletions
diff --git a/unittests/Basic/FileManagerTest.cpp b/unittests/Basic/FileManagerTest.cpp index 3518325083..cff12c53ea 100644 --- a/unittests/Basic/FileManagerTest.cpp +++ b/unittests/Basic/FileManagerTest.cpp @@ -205,9 +205,9 @@ TEST_F(FileManagerTest, getFileReturnsDifferentFileEntriesForDifferentFiles) { EXPECT_NE(*fileFoo, *fileBar); } -// getFile() returns NULL if neither a real file nor a virtual file +// getFile() returns an error if neither a real file nor a virtual file // exists at the given path. -TEST_F(FileManagerTest, getFileReturnsNULLForNonexistentFile) { +TEST_F(FileManagerTest, getFileReturnsErrorForNonexistentFile) { // Inject a fake foo.cpp into the file system. auto statCache = llvm::make_unique<FakeStatCache>(); statCache->InjectDirectory(".", 41); @@ -219,6 +219,16 @@ TEST_F(FileManagerTest, getFileReturnsNULLForNonexistentFile) { auto file = manager.getFile("xyz.txt"); ASSERT_FALSE(file); + ASSERT_EQ(file.getError(), std::errc::no_such_file_or_directory); + + statCache->InjectDirectory("MyDirectory", 49); + auto readingDirAsFile = manager.getFile("MyDirectory"); + ASSERT_FALSE(readingDirAsFile); + ASSERT_EQ(readingDirAsFile.getError(), std::errc::is_a_directory); + + auto readingFileAsDir = manager.getDirectory("foo.cpp"); + ASSERT_FALSE(readingFileAsDir); + ASSERT_EQ(readingFileAsDir.getError(), std::errc::not_a_directory); } // The following tests apply to Unix-like system only. @@ -378,13 +388,13 @@ TEST_F(FileManagerTest, getFileDontOpenRealPath) { Manager.setStatCache(std::move(statCache)); // Check for real path. - const FileEntry *file = Manager.getFile("/tmp/test", /*OpenFile=*/false); - ASSERT_TRUE(file != nullptr); - ASSERT_TRUE(file->isValid()); + auto file = Manager.getFile("/tmp/test", /*OpenFile=*/false); + ASSERT_TRUE(file); + ASSERT_TRUE((*file)->isValid()); SmallString<64> ExpectedResult = CustomWorkingDir; llvm::sys::path::append(ExpectedResult, "tmp", "test"); - EXPECT_EQ(file->tryGetRealPathName(), ExpectedResult); + EXPECT_EQ((*file)->tryGetRealPathName(), ExpectedResult); } } // anonymous namespace diff --git a/unittests/Lex/HeaderSearchTest.cpp b/unittests/Lex/HeaderSearchTest.cpp index 626cfadb15..b013cac85f 100644 --- a/unittests/Lex/HeaderSearchTest.cpp +++ b/unittests/Lex/HeaderSearchTest.cpp @@ -39,9 +39,9 @@ protected: void addSearchDir(llvm::StringRef Dir) { VFS->addFile(Dir, 0, llvm::MemoryBuffer::getMemBuffer(""), /*User=*/None, /*Group=*/None, llvm::sys::fs::file_type::directory_file); - const DirectoryEntry *DE = FileMgr.getDirectory(Dir); + auto DE = FileMgr.getDirectory(Dir); assert(DE); - auto DL = DirectoryLookup(DE, SrcMgr::C_User, /*isFramework=*/false); + auto DL = DirectoryLookup(*DE, SrcMgr::C_User, /*isFramework=*/false); Search.AddSearchPath(DL, /*isAngled=*/false); } diff --git a/unittests/Lex/PPCallbacksTest.cpp b/unittests/Lex/PPCallbacksTest.cpp index 91765960c3..5de17103d9 100644 --- a/unittests/Lex/PPCallbacksTest.cpp +++ b/unittests/Lex/PPCallbacksTest.cpp @@ -145,8 +145,8 @@ protected: // Add header's parent path to search path. StringRef SearchPath = llvm::sys::path::parent_path(HeaderPath); - const DirectoryEntry *DE = FileMgr.getDirectory(SearchPath); - DirectoryLookup DL(DE, SrcMgr::C_User, false); + auto DE = FileMgr.getDirectory(SearchPath); + DirectoryLookup DL(*DE, SrcMgr::C_User, false); HeaderInfo.AddSearchPath(DL, IsSystemHeader); } diff --git a/unittests/Tooling/RefactoringTest.cpp b/unittests/Tooling/RefactoringTest.cpp index c51d738ba6..b04c9a91ef 100644 --- a/unittests/Tooling/RefactoringTest.cpp +++ b/unittests/Tooling/RefactoringTest.cpp @@ -608,14 +608,15 @@ public: llvm::raw_fd_ostream OutStream(FD, true); OutStream << Content; OutStream.close(); - const FileEntry *File = Context.Files.getFile(Path); - assert(File != nullptr); + auto File = Context.Files.getFile(Path); + assert(File); StringRef Found = TemporaryFiles.insert(std::make_pair(Name, Path.str())).first->second; assert(Found == Path); (void)Found; - return Context.Sources.createFileID(File, SourceLocation(), SrcMgr::C_User); + return Context.Sources.createFileID(*File, SourceLocation(), + SrcMgr::C_User); } std::string getFileContentFromDisk(llvm::StringRef Name) { diff --git a/unittests/Tooling/RewriterTestContext.h b/unittests/Tooling/RewriterTestContext.h index ba919d6472..cfe5577a04 100644 --- a/unittests/Tooling/RewriterTestContext.h +++ b/unittests/Tooling/RewriterTestContext.h @@ -56,9 +56,9 @@ class RewriterTestContext { llvm::MemoryBuffer::getMemBuffer(Content); InMemoryFileSystem->addFile(Name, 0, std::move(Source)); - const FileEntry *Entry = Files.getFile(Name); - assert(Entry != nullptr); - return Sources.createFileID(Entry, SourceLocation(), SrcMgr::C_User); + auto Entry = Files.getFile(Name); + assert(Entry); + return Sources.createFileID(*Entry, SourceLocation(), SrcMgr::C_User); } // FIXME: this code is mostly a duplicate of @@ -73,14 +73,14 @@ class RewriterTestContext { llvm::raw_fd_ostream OutStream(FD, true); OutStream << Content; OutStream.close(); - const FileEntry *File = Files.getFile(Path); - assert(File != nullptr); + auto File = Files.getFile(Path); + assert(File); StringRef Found = TemporaryFiles.insert(std::make_pair(Name, Path.str())).first->second; assert(Found == Path); (void)Found; - return Sources.createFileID(File, SourceLocation(), SrcMgr::C_User); + return Sources.createFileID(*File, SourceLocation(), SrcMgr::C_User); } SourceLocation getLocation(FileID ID, unsigned Line, unsigned Column) { |