summaryrefslogtreecommitdiffstats
path: root/unittests/Basic
diff options
context:
space:
mode:
authorJordan Rupprecht <rupprecht@google.com>2019-05-14 21:58:59 +0000
committerJordan Rupprecht <rupprecht@google.com>2019-05-14 21:58:59 +0000
commitb35a2aa71f76a334a9c98c0a3c3995b5d902d2b9 (patch)
treecdff4a5d1a715d4ad622fd8f190128b54bebe440 /unittests/Basic
parent3748d41833787fcbf59cc5624e8d2b042a8991bc (diff)
parent741e05796da92b46d4f7bcbee00702ff37df6489 (diff)
Creating branches/google/stable and tags/google/stable/2019-05-14 from r360103upstream/google/stable
git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/google/stable@360714 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Basic')
-rw-r--r--unittests/Basic/CMakeLists.txt1
-rw-r--r--unittests/Basic/CharInfoTest.cpp7
-rw-r--r--unittests/Basic/DiagnosticTest.cpp20
-rw-r--r--unittests/Basic/FileManagerTest.cpp99
-rw-r--r--unittests/Basic/FixedPointTest.cpp7
-rw-r--r--unittests/Basic/MemoryBufferCacheTest.cpp94
-rw-r--r--unittests/Basic/SourceManagerTest.cpp17
7 files changed, 73 insertions, 172 deletions
diff --git a/unittests/Basic/CMakeLists.txt b/unittests/Basic/CMakeLists.txt
index 537f3ba5fc..d883c362e2 100644
--- a/unittests/Basic/CMakeLists.txt
+++ b/unittests/Basic/CMakeLists.txt
@@ -7,7 +7,6 @@ add_clang_unittest(BasicTests
DiagnosticTest.cpp
FileManagerTest.cpp
FixedPointTest.cpp
- MemoryBufferCacheTest.cpp
SourceManagerTest.cpp
)
diff --git a/unittests/Basic/CharInfoTest.cpp b/unittests/Basic/CharInfoTest.cpp
index 7a9d17fce6..4f84bebec3 100644
--- a/unittests/Basic/CharInfoTest.cpp
+++ b/unittests/Basic/CharInfoTest.cpp
@@ -1,9 +1,8 @@
//===- unittests/Basic/CharInfoTest.cpp -- ASCII classification tests -----===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
diff --git a/unittests/Basic/DiagnosticTest.cpp b/unittests/Basic/DiagnosticTest.cpp
index 3068e1c340..ffb750bdaa 100644
--- a/unittests/Basic/DiagnosticTest.cpp
+++ b/unittests/Basic/DiagnosticTest.cpp
@@ -1,9 +1,8 @@
//===- unittests/Basic/DiagnosticTest.cpp -- Diagnostic engine tests ------===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -47,13 +46,13 @@ TEST(DiagnosticTest, suppressAndTrap) {
EXPECT_FALSE(Diags.hasUnrecoverableErrorOccurred());
}
-// Check that SuppressAfterFatalError works as intended
-TEST(DiagnosticTest, suppressAfterFatalError) {
- for (unsigned Suppress = 0; Suppress != 2; ++Suppress) {
+// Check that FatalsAsError works as intended
+TEST(DiagnosticTest, fatalsAsError) {
+ for (unsigned FatalsAsError = 0; FatalsAsError != 2; ++FatalsAsError) {
DiagnosticsEngine Diags(new DiagnosticIDs(),
new DiagnosticOptions,
new IgnoringDiagConsumer());
- Diags.setSuppressAfterFatalError(Suppress);
+ Diags.setFatalsAsError(FatalsAsError);
// Diag that would set UnrecoverableErrorOccurred and ErrorOccurred.
Diags.Report(diag::err_cannot_open_file) << "file" << "error";
@@ -63,16 +62,15 @@ TEST(DiagnosticTest, suppressAfterFatalError) {
Diags.Report(diag::warn_mt_message) << "warning";
EXPECT_TRUE(Diags.hasErrorOccurred());
- EXPECT_TRUE(Diags.hasFatalErrorOccurred());
+ EXPECT_EQ(Diags.hasFatalErrorOccurred(), FatalsAsError ? 0u : 1u);
EXPECT_TRUE(Diags.hasUncompilableErrorOccurred());
EXPECT_TRUE(Diags.hasUnrecoverableErrorOccurred());
// The warning should be emitted and counted only if we're not suppressing
// after fatal errors.
- EXPECT_EQ(Diags.getNumWarnings(), Suppress ? 0u : 1u);
+ EXPECT_EQ(Diags.getNumWarnings(), FatalsAsError);
}
}
-
TEST(DiagnosticTest, diagnosticError) {
DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
new IgnoringDiagConsumer());
diff --git a/unittests/Basic/FileManagerTest.cpp b/unittests/Basic/FileManagerTest.cpp
index 746d9ad5e8..19e2180d3f 100644
--- a/unittests/Basic/FileManagerTest.cpp
+++ b/unittests/Basic/FileManagerTest.cpp
@@ -1,9 +1,8 @@
//===- unittests/Basic/FileMangerTest.cpp ------------ FileManger tests ---===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -27,7 +26,7 @@ class FakeStatCache : public FileSystemStatCache {
private:
// Maps a file/directory path to its desired stat result. Anything
// not in this map is considered to not exist in the file system.
- llvm::StringMap<FileData, llvm::BumpPtrAllocator> StatCalls;
+ llvm::StringMap<llvm::vfs::Status, llvm::BumpPtrAllocator> StatCalls;
void InjectFileOrDirectory(const char *Path, ino_t INode, bool IsFile) {
#ifndef _WIN32
@@ -36,15 +35,14 @@ private:
Path = NormalizedPath.c_str();
#endif
- FileData Data;
- Data.Name = Path;
- Data.Size = 0;
- Data.ModTime = 0;
- Data.UniqueID = llvm::sys::fs::UniqueID(1, INode);
- Data.IsDirectory = !IsFile;
- Data.IsNamedPipe = false;
- Data.InPCH = false;
- StatCalls[Path] = Data;
+ auto fileType = IsFile ?
+ llvm::sys::fs::file_type::regular_file :
+ llvm::sys::fs::file_type::directory_file;
+ llvm::vfs::Status Status(Path, llvm::sys::fs::UniqueID(1, INode),
+ /*MTime*/{}, /*User*/0, /*Group*/0,
+ /*Size*/0, fileType,
+ llvm::sys::fs::perms::all_all);
+ StatCalls[Path] = Status;
}
public:
@@ -59,9 +57,10 @@ public:
}
// Implement FileSystemStatCache::getStat().
- LookupResult getStat(StringRef Path, FileData &Data, bool isFile,
- std::unique_ptr<llvm::vfs::File> *F,
- llvm::vfs::FileSystem &FS) override {
+ std::error_code getStat(StringRef Path, llvm::vfs::Status &Status,
+ 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);
@@ -69,11 +68,11 @@ public:
#endif
if (StatCalls.count(Path) != 0) {
- Data = StatCalls[Path];
- return CacheExists;
+ Status = StatCalls[Path];
+ return std::error_code();
}
- return CacheMissing; // This means the file/directory doesn't exist.
+ return std::make_error_code(std::errc::no_such_file_or_directory);
}
};
@@ -222,33 +221,6 @@ TEST_F(FileManagerTest, getFileReturnsNULLForNonexistentFile) {
EXPECT_EQ(nullptr, file);
}
-// When calling getFile(OpenFile=false); getFile(OpenFile=true) the file is
-// opened for the second call.
-TEST_F(FileManagerTest, getFileDefersOpen) {
- llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS(
- new llvm::vfs::InMemoryFileSystem());
- FS->addFile("/tmp/test", 0, llvm::MemoryBuffer::getMemBufferCopy("test"));
- FS->addFile("/tmp/testv", 0, llvm::MemoryBuffer::getMemBufferCopy("testv"));
- FileManager manager(options, FS);
-
- const FileEntry *file = manager.getFile("/tmp/test", /*OpenFile=*/false);
- ASSERT_TRUE(file != nullptr);
- ASSERT_TRUE(file->isValid());
- // "real path name" reveals whether the file was actually opened.
- EXPECT_FALSE(file->isOpenForTests());
-
- file = manager.getFile("/tmp/test", /*OpenFile=*/true);
- ASSERT_TRUE(file != nullptr);
- ASSERT_TRUE(file->isValid());
- EXPECT_TRUE(file->isOpenForTests());
-
- // However we should never try to open a file previously opened as virtual.
- ASSERT_TRUE(manager.getVirtualFile("/tmp/testv", 5, 0));
- ASSERT_TRUE(manager.getFile("/tmp/testv", /*OpenFile=*/false));
- file = manager.getFile("/tmp/testv", /*OpenFile=*/true);
- EXPECT_FALSE(file->isOpenForTests());
-}
-
// The following tests apply to Unix-like system only.
#ifndef _WIN32
@@ -374,4 +346,37 @@ TEST_F(FileManagerTest, getVirtualFileFillsRealPathName) {
EXPECT_EQ(file->tryGetRealPathName(), ExpectedResult);
}
+TEST_F(FileManagerTest, getFileDontOpenRealPath) {
+ SmallString<64> CustomWorkingDir;
+#ifdef _WIN32
+ CustomWorkingDir = "C:/";
+#else
+ CustomWorkingDir = "/";
+#endif
+
+ auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>(
+ new llvm::vfs::InMemoryFileSystem);
+ // setCurrentworkingdirectory must finish without error.
+ ASSERT_TRUE(!FS->setCurrentWorkingDirectory(CustomWorkingDir));
+
+ FileSystemOptions Opts;
+ FileManager Manager(Opts, FS);
+
+ // Inject fake files into the file system.
+ auto statCache = llvm::make_unique<FakeStatCache>();
+ statCache->InjectDirectory("/tmp", 42);
+ statCache->InjectFile("/tmp/test", 43);
+
+ 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());
+ SmallString<64> ExpectedResult = CustomWorkingDir;
+
+ llvm::sys::path::append(ExpectedResult, "tmp", "test");
+ EXPECT_EQ(file->tryGetRealPathName(), ExpectedResult);
+}
+
} // anonymous namespace
diff --git a/unittests/Basic/FixedPointTest.cpp b/unittests/Basic/FixedPointTest.cpp
index 8e184a7af8..5d991c0720 100644
--- a/unittests/Basic/FixedPointTest.cpp
+++ b/unittests/Basic/FixedPointTest.cpp
@@ -1,9 +1,8 @@
//===- unittests/Basic/FixedPointTest.cpp -- fixed point number tests -----===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
diff --git a/unittests/Basic/MemoryBufferCacheTest.cpp b/unittests/Basic/MemoryBufferCacheTest.cpp
deleted file mode 100644
index 99178f8150..0000000000
--- a/unittests/Basic/MemoryBufferCacheTest.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-//===- MemoryBufferCacheTest.cpp - MemoryBufferCache tests ----------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/Basic/MemoryBufferCache.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include "gtest/gtest.h"
-
-using namespace llvm;
-using namespace clang;
-
-namespace {
-
-std::unique_ptr<MemoryBuffer> getBuffer(int I) {
- SmallVector<char, 8> Bytes;
- raw_svector_ostream(Bytes) << "data:" << I;
- return MemoryBuffer::getMemBuffer(StringRef(Bytes.data(), Bytes.size()), "",
- /* RequiresNullTerminator = */ false);
-}
-
-TEST(MemoryBufferCacheTest, addBuffer) {
- auto B1 = getBuffer(1);
- auto B2 = getBuffer(2);
- auto B3 = getBuffer(3);
- auto *RawB1 = B1.get();
- auto *RawB2 = B2.get();
- auto *RawB3 = B3.get();
-
- // Add a few buffers.
- MemoryBufferCache Cache;
- EXPECT_EQ(RawB1, &Cache.addBuffer("1", std::move(B1)));
- EXPECT_EQ(RawB2, &Cache.addBuffer("2", std::move(B2)));
- EXPECT_EQ(RawB3, &Cache.addBuffer("3", std::move(B3)));
- EXPECT_EQ(RawB1, Cache.lookupBuffer("1"));
- EXPECT_EQ(RawB2, Cache.lookupBuffer("2"));
- EXPECT_EQ(RawB3, Cache.lookupBuffer("3"));
- EXPECT_FALSE(Cache.isBufferFinal("1"));
- EXPECT_FALSE(Cache.isBufferFinal("2"));
- EXPECT_FALSE(Cache.isBufferFinal("3"));
-
- // Remove the middle buffer.
- EXPECT_FALSE(Cache.tryToRemoveBuffer("2"));
- EXPECT_EQ(nullptr, Cache.lookupBuffer("2"));
- EXPECT_FALSE(Cache.isBufferFinal("2"));
-
- // Replace the middle buffer.
- B2 = getBuffer(2);
- RawB2 = B2.get();
- EXPECT_EQ(RawB2, &Cache.addBuffer("2", std::move(B2)));
-
- // Check that nothing is final.
- EXPECT_FALSE(Cache.isBufferFinal("1"));
- EXPECT_FALSE(Cache.isBufferFinal("2"));
- EXPECT_FALSE(Cache.isBufferFinal("3"));
-}
-
-TEST(MemoryBufferCacheTest, finalizeCurrentBuffers) {
- // Add a buffer.
- MemoryBufferCache Cache;
- auto B1 = getBuffer(1);
- auto *RawB1 = B1.get();
- Cache.addBuffer("1", std::move(B1));
- ASSERT_FALSE(Cache.isBufferFinal("1"));
-
- // Finalize it.
- Cache.finalizeCurrentBuffers();
- EXPECT_TRUE(Cache.isBufferFinal("1"));
- EXPECT_TRUE(Cache.tryToRemoveBuffer("1"));
- EXPECT_EQ(RawB1, Cache.lookupBuffer("1"));
- EXPECT_TRUE(Cache.isBufferFinal("1"));
-
- // Repeat.
- auto B2 = getBuffer(2);
- auto *RawB2 = B2.get();
- Cache.addBuffer("2", std::move(B2));
- EXPECT_FALSE(Cache.isBufferFinal("2"));
-
- Cache.finalizeCurrentBuffers();
- EXPECT_TRUE(Cache.isBufferFinal("1"));
- EXPECT_TRUE(Cache.isBufferFinal("2"));
- EXPECT_TRUE(Cache.tryToRemoveBuffer("1"));
- EXPECT_TRUE(Cache.tryToRemoveBuffer("2"));
- EXPECT_EQ(RawB1, Cache.lookupBuffer("1"));
- EXPECT_EQ(RawB2, Cache.lookupBuffer("2"));
- EXPECT_TRUE(Cache.isBufferFinal("1"));
- EXPECT_TRUE(Cache.isBufferFinal("2"));
-}
-
-} // namespace
diff --git a/unittests/Basic/SourceManagerTest.cpp b/unittests/Basic/SourceManagerTest.cpp
index b548bf5752..ff8a364736 100644
--- a/unittests/Basic/SourceManagerTest.cpp
+++ b/unittests/Basic/SourceManagerTest.cpp
@@ -1,9 +1,8 @@
//===- unittests/Basic/SourceManagerTest.cpp ------ SourceManager tests ---===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -12,7 +11,6 @@
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/LangOptions.h"
-#include "clang/Basic/MemoryBufferCache.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Lex/HeaderSearch.h"
@@ -61,11 +59,10 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnit) {
SourceMgr.setMainFileID(mainFileID);
TrivialModuleLoader ModLoader;
- MemoryBufferCache PCMCache;
HeaderSearch HeaderInfo(std::make_shared<HeaderSearchOptions>(), SourceMgr,
Diags, LangOpts, &*Target);
Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, PCMCache, HeaderInfo, ModLoader,
+ SourceMgr, HeaderInfo, ModLoader,
/*IILookup =*/nullptr,
/*OwnsHeaderSearch =*/false);
PP.Initialize(*Target);
@@ -230,11 +227,10 @@ TEST_F(SourceManagerTest, getMacroArgExpandedLocation) {
SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf));
TrivialModuleLoader ModLoader;
- MemoryBufferCache PCMCache;
HeaderSearch HeaderInfo(std::make_shared<HeaderSearchOptions>(), SourceMgr,
Diags, LangOpts, &*Target);
Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, PCMCache, HeaderInfo, ModLoader,
+ SourceMgr, HeaderInfo, ModLoader,
/*IILookup =*/nullptr,
/*OwnsHeaderSearch =*/false);
PP.Initialize(*Target);
@@ -349,11 +345,10 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnitWithMacroInInclude) {
SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf));
TrivialModuleLoader ModLoader;
- MemoryBufferCache PCMCache;
HeaderSearch HeaderInfo(std::make_shared<HeaderSearchOptions>(), SourceMgr,
Diags, LangOpts, &*Target);
Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, PCMCache, HeaderInfo, ModLoader,
+ SourceMgr, HeaderInfo, ModLoader,
/*IILookup =*/nullptr,
/*OwnsHeaderSearch =*/false);
PP.Initialize(*Target);