diff options
author | Ben Langmuir <blangmuir@apple.com> | 2014-02-25 04:34:14 +0000 |
---|---|---|
committer | Ben Langmuir <blangmuir@apple.com> | 2014-02-25 04:34:14 +0000 |
commit | 47ff9ab1be165d83063036f2630df794db008b4b (patch) | |
tree | 23fc268b80e878499354bf66e26308b0665dad44 /clang/unittests/Basic/VirtualFileSystemTest.cpp | |
parent | f45fa3dca568a72758c5e7b978a2a09b3a50ce4b (diff) | |
download | bcm5719-llvm-47ff9ab1be165d83063036f2630df794db008b4b.tar.gz bcm5719-llvm-47ff9ab1be165d83063036f2630df794db008b4b.zip |
Allow multi-component paths in VFS file nodes
This allows the 'name' field to contain a path, like
{ 'type': 'directory',
'name': '/path/to/dir',
'contents': [ ... ] }
which not only simplifies reading and writing these files (for humans),
but makes it possible to easily modify locations via textual
replacement, which would not have worked in the old scheme.
E.g. sed s:<ROOT>:<NEW ROOT>
llvm-svn: 202109
Diffstat (limited to 'clang/unittests/Basic/VirtualFileSystemTest.cpp')
-rw-r--r-- | clang/unittests/Basic/VirtualFileSystemTest.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/clang/unittests/Basic/VirtualFileSystemTest.cpp b/clang/unittests/Basic/VirtualFileSystemTest.cpp index de09cfbd520..334b1a45ddf 100644 --- a/clang/unittests/Basic/VirtualFileSystemTest.cpp +++ b/clang/unittests/Basic/VirtualFileSystemTest.cpp @@ -466,3 +466,64 @@ TEST_F(VFSFromYAMLTest, IllegalVFSFile) { EXPECT_EQ(NULL, FS.getPtr()); EXPECT_EQ(24, NumDiagnostics); } + +TEST_F(VFSFromYAMLTest, MultiComponentPath) { + IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + Lower->addRegularFile("/other"); + + // file in roots + IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString( + "{ 'roots': [\n" + " { 'type': 'file', 'name': '/path/to/file',\n" + " 'external-contents': '/other' }]\n" + "}", Lower); + ASSERT_TRUE(NULL != FS.getPtr()); + EXPECT_EQ(errc::success, FS->status("/path/to/file").getError()); + EXPECT_EQ(errc::success, FS->status("/path/to").getError()); + EXPECT_EQ(errc::success, FS->status("/path").getError()); + EXPECT_EQ(errc::success, FS->status("/").getError()); + + // at the start + FS = getFromYAMLString( + "{ 'roots': [\n" + " { 'type': 'directory', 'name': '/path/to',\n" + " 'contents': [ { 'type': 'file', 'name': 'file',\n" + " 'external-contents': '/other' }]}]\n" + "}", Lower); + ASSERT_TRUE(NULL != FS.getPtr()); + EXPECT_EQ(errc::success, FS->status("/path/to/file").getError()); + EXPECT_EQ(errc::success, FS->status("/path/to").getError()); + EXPECT_EQ(errc::success, FS->status("/path").getError()); + EXPECT_EQ(errc::success, FS->status("/").getError()); + + // at the end + FS = getFromYAMLString( + "{ 'roots': [\n" + " { 'type': 'directory', 'name': '/',\n" + " 'contents': [ { 'type': 'file', 'name': 'path/to/file',\n" + " 'external-contents': '/other' }]}]\n" + "}", Lower); + ASSERT_TRUE(NULL != FS.getPtr()); + EXPECT_EQ(errc::success, FS->status("/path/to/file").getError()); + EXPECT_EQ(errc::success, FS->status("/path/to").getError()); + EXPECT_EQ(errc::success, FS->status("/path").getError()); + EXPECT_EQ(errc::success, FS->status("/").getError()); +} + +TEST_F(VFSFromYAMLTest, TrailingSlashes) { + IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + Lower->addRegularFile("/other"); + + // file in roots + IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString( + "{ 'roots': [\n" + " { 'type': 'directory', 'name': '/path/to////',\n" + " 'contents': [ { 'type': 'file', 'name': 'file',\n" + " 'external-contents': '/other' }]}]\n" + "}", Lower); + ASSERT_TRUE(NULL != FS.getPtr()); + EXPECT_EQ(errc::success, FS->status("/path/to/file").getError()); + EXPECT_EQ(errc::success, FS->status("/path/to").getError()); + EXPECT_EQ(errc::success, FS->status("/path").getError()); + EXPECT_EQ(errc::success, FS->status("/").getError()); +} |