summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Basic/VirtualFileSystemTest.cpp
diff options
context:
space:
mode:
authorBen Langmuir <blangmuir@apple.com>2014-02-24 20:56:37 +0000
committerBen Langmuir <blangmuir@apple.com>2014-02-24 20:56:37 +0000
commit97882e7b7fc761140d36858ace9437e9e2039cdd (patch)
treed70e12d29922531874ca9d90075cb4c84766cdbf /clang/unittests/Basic/VirtualFileSystemTest.cpp
parent5b2f7c5f604da111060cec778e59c89e017ac1e4 (diff)
downloadbcm5719-llvm-97882e7b7fc761140d36858ace9437e9e2039cdd.tar.gz
bcm5719-llvm-97882e7b7fc761140d36858ace9437e9e2039cdd.zip
Pass through context for DiagHandler in VFS
This allows the unit tests to not use global state when checking diagnostics. llvm-svn: 202072
Diffstat (limited to 'clang/unittests/Basic/VirtualFileSystemTest.cpp')
-rw-r--r--clang/unittests/Basic/VirtualFileSystemTest.cpp58
1 files changed, 31 insertions, 27 deletions
diff --git a/clang/unittests/Basic/VirtualFileSystemTest.cpp b/clang/unittests/Basic/VirtualFileSystemTest.cpp
index 50d11019f30..1231c949885 100644
--- a/clang/unittests/Basic/VirtualFileSystemTest.cpp
+++ b/clang/unittests/Basic/VirtualFileSystemTest.cpp
@@ -218,28 +218,36 @@ TEST(VirtualFileSystemTest, MergedDirPermissions) {
EXPECT_EQ(0200, Status->getPermissions());
}
-static int NumDiagnostics = 0;
-static void CountingDiagHandler(const SMDiagnostic &, void *) {
- ++NumDiagnostics;
-}
+class VFSFromYAMLTest : public ::testing::Test {
+public:
+ int NumDiagnostics;
+ void SetUp() {
+ NumDiagnostics = 0;
+ }
-static IntrusiveRefCntPtr<vfs::FileSystem>
-getFromYAMLRawString(StringRef Content,
- IntrusiveRefCntPtr<vfs::FileSystem> ExternalFS) {
- MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Content);
- return getVFSFromYAML(Buffer, CountingDiagHandler, ExternalFS);
-}
+ static void CountingDiagHandler(const SMDiagnostic &, void *Context) {
+ VFSFromYAMLTest *Test = static_cast<VFSFromYAMLTest *>(Context);
+ ++Test->NumDiagnostics;
+ }
-static IntrusiveRefCntPtr<vfs::FileSystem> getFromYAMLString(
- StringRef Content,
- IntrusiveRefCntPtr<vfs::FileSystem> ExternalFS = new DummyFileSystem()) {
- std::string VersionPlusContent("{\n 'version':0,\n");
- VersionPlusContent += Content.slice(Content.find('{') + 1, StringRef::npos);
- return getFromYAMLRawString(VersionPlusContent, ExternalFS);
-}
+ IntrusiveRefCntPtr<vfs::FileSystem>
+ getFromYAMLRawString(StringRef Content,
+ IntrusiveRefCntPtr<vfs::FileSystem> ExternalFS) {
+ MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Content);
+ return getVFSFromYAML(Buffer, CountingDiagHandler, this, ExternalFS);
+ }
+
+ IntrusiveRefCntPtr<vfs::FileSystem> getFromYAMLString(
+ StringRef Content,
+ IntrusiveRefCntPtr<vfs::FileSystem> ExternalFS = new DummyFileSystem()) {
+ std::string VersionPlusContent("{\n 'version':0,\n");
+ VersionPlusContent += Content.slice(Content.find('{') + 1, StringRef::npos);
+ return getFromYAMLRawString(VersionPlusContent, ExternalFS);
+ }
+
+};
-TEST(VirtualFileSystemTest, BasicVFSFromYAML) {
- NumDiagnostics = 0;
+TEST_F(VFSFromYAMLTest, BasicVFSFromYAML) {
IntrusiveRefCntPtr<vfs::FileSystem> FS;
FS = getFromYAMLString("");
EXPECT_EQ(NULL, FS.getPtr());
@@ -250,8 +258,7 @@ TEST(VirtualFileSystemTest, BasicVFSFromYAML) {
EXPECT_EQ(3, NumDiagnostics);
}
-TEST(VirtualFileSystemTest, MappedFiles) {
- NumDiagnostics = 0;
+TEST_F(VFSFromYAMLTest, MappedFiles) {
IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
Lower->addRegularFile("/foo/bar/a");
IntrusiveRefCntPtr<vfs::FileSystem> FS =
@@ -301,8 +308,7 @@ TEST(VirtualFileSystemTest, MappedFiles) {
EXPECT_EQ(0, NumDiagnostics);
}
-TEST(VirtualFileSystemTest, CaseInsensitive) {
- NumDiagnostics = 0;
+TEST_F(VFSFromYAMLTest, CaseInsensitive) {
IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
Lower->addRegularFile("/foo/bar/a");
IntrusiveRefCntPtr<vfs::FileSystem> FS =
@@ -338,8 +344,7 @@ TEST(VirtualFileSystemTest, CaseInsensitive) {
EXPECT_EQ(0, NumDiagnostics);
}
-TEST(VirtualFileSystemTest, CaseSensitive) {
- NumDiagnostics = 0;
+TEST_F(VFSFromYAMLTest, CaseSensitive) {
IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
Lower->addRegularFile("/foo/bar/a");
IntrusiveRefCntPtr<vfs::FileSystem> FS =
@@ -371,8 +376,7 @@ TEST(VirtualFileSystemTest, CaseSensitive) {
EXPECT_EQ(0, NumDiagnostics);
}
-TEST(VirtualFileSystemTest, IllegalVFSFile) {
- NumDiagnostics = 0;
+TEST_F(VFSFromYAMLTest, IllegalVFSFile) {
IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
// invalid YAML at top-level
OpenPOWER on IntegriCloud