From 75f094ca568d0efe44961613d8a748acbc8eb7c0 Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Wed, 5 Mar 2014 21:32:20 +0000 Subject: [PATCH] Attempt to re-enable the VFS unittests on Windows Using a //net/ path to hopefully avoid problems with non-absolute paths on Windows. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203010 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/VirtualFileSystem.cpp | 6 +- unittests/Basic/VirtualFileSystemTest.cpp | 144 +++++++++++----------- 2 files changed, 76 insertions(+), 74 deletions(-) diff --git a/lib/Basic/VirtualFileSystem.cpp b/lib/Basic/VirtualFileSystem.cpp index dc0f52f72b..28bb598934 100644 --- a/lib/Basic/VirtualFileSystem.cpp +++ b/lib/Basic/VirtualFileSystem.cpp @@ -582,9 +582,11 @@ class VFSFromYAMLParser { return NULL; } - // Remove trailing slash(es) + // Remove trailing slash(es), being careful not to remove the root path StringRef Trimmed(Name); - while (Trimmed.size() > 1 && sys::path::is_separator(Trimmed.back())) + size_t RootPathLen = sys::path::root_path(Trimmed).size(); + while (Trimmed.size() > RootPathLen && + sys::path::is_separator(Trimmed.back())) Trimmed = Trimmed.slice(0, Trimmed.size()-1); // Get the last component StringRef LastComponent = sys::path::filename(Trimmed); diff --git a/unittests/Basic/VirtualFileSystemTest.cpp b/unittests/Basic/VirtualFileSystemTest.cpp index 8e0ce24635..c03ae6bd6c 100644 --- a/unittests/Basic/VirtualFileSystemTest.cpp +++ b/unittests/Basic/VirtualFileSystemTest.cpp @@ -17,7 +17,6 @@ using namespace clang; using namespace llvm; using llvm::sys::fs::UniqueID; -#if !defined(_WIN32) // FIXME: Investigating. namespace { class DummyFileSystem : public vfs::FileSystem { int FSID; // used to produce UniqueIDs @@ -219,9 +218,12 @@ TEST(VirtualFileSystemTest, MergedDirPermissions) { EXPECT_EQ(0200, Status->getPermissions()); } +// NOTE: in the tests below, we use '//root/' as our root directory, since it is +// a legal *absolute* path on Windows as well as *nix. class VFSFromYAMLTest : public ::testing::Test { public: int NumDiagnostics; + void SetUp() { NumDiagnostics = 0; } @@ -245,7 +247,6 @@ public: VersionPlusContent += Content.slice(Content.find('{') + 1, StringRef::npos); return getFromYAMLRawString(VersionPlusContent, ExternalFS); } - }; TEST_F(VFSFromYAMLTest, BasicVFSFromYAML) { @@ -261,21 +262,21 @@ TEST_F(VFSFromYAMLTest, BasicVFSFromYAML) { TEST_F(VFSFromYAMLTest, MappedFiles) { IntrusiveRefCntPtr Lower(new DummyFileSystem()); - Lower->addRegularFile("/foo/bar/a"); + Lower->addRegularFile("//root/foo/bar/a"); IntrusiveRefCntPtr FS = getFromYAMLString("{ 'roots': [\n" "{\n" " 'type': 'directory',\n" - " 'name': '/',\n" + " 'name': '//root/',\n" " 'contents': [ {\n" " 'type': 'file',\n" " 'name': 'file1',\n" - " 'external-contents': '/foo/bar/a'\n" + " 'external-contents': '//root/foo/bar/a'\n" " },\n" " {\n" " 'type': 'file',\n" " 'name': 'file2',\n" - " 'external-contents': '/foo/b'\n" + " 'external-contents': '//root/foo/b'\n" " }\n" " ]\n" "}\n" @@ -289,38 +290,38 @@ TEST_F(VFSFromYAMLTest, MappedFiles) { O->pushOverlay(FS); // file - ErrorOr S = O->status("/file1"); + ErrorOr S = O->status("//root/file1"); ASSERT_EQ(errc::success, S.getError()); - EXPECT_EQ("/foo/bar/a", S->getName()); + EXPECT_EQ("//root/foo/bar/a", S->getName()); - ErrorOr SLower = O->status("/foo/bar/a"); - EXPECT_EQ("/foo/bar/a", SLower->getName()); + ErrorOr SLower = O->status("//root/foo/bar/a"); + EXPECT_EQ("//root/foo/bar/a", SLower->getName()); EXPECT_TRUE(S->equivalent(*SLower)); // directory - S = O->status("/"); + S = O->status("//root/"); ASSERT_EQ(errc::success, S.getError()); EXPECT_TRUE(S->isDirectory()); - EXPECT_TRUE(S->equivalent(*O->status("/"))); // non-volatile UniqueID + EXPECT_TRUE(S->equivalent(*O->status("//root/"))); // non-volatile UniqueID // broken mapping - EXPECT_EQ(errc::no_such_file_or_directory, O->status("/file2").getError()); + EXPECT_EQ(errc::no_such_file_or_directory, O->status("//root/file2").getError()); EXPECT_EQ(0, NumDiagnostics); } TEST_F(VFSFromYAMLTest, CaseInsensitive) { IntrusiveRefCntPtr Lower(new DummyFileSystem()); - Lower->addRegularFile("/foo/bar/a"); + Lower->addRegularFile("//root/foo/bar/a"); IntrusiveRefCntPtr FS = getFromYAMLString("{ 'case-sensitive': 'false',\n" " 'roots': [\n" "{\n" " 'type': 'directory',\n" - " 'name': '/',\n" + " 'name': '//root/',\n" " 'contents': [ {\n" " 'type': 'file',\n" " 'name': 'XX',\n" - " 'external-contents': '/foo/bar/a'\n" + " 'external-contents': '//root/foo/bar/a'\n" " }\n" " ]\n" "}]}", @@ -331,32 +332,32 @@ TEST_F(VFSFromYAMLTest, CaseInsensitive) { new vfs::OverlayFileSystem(Lower)); O->pushOverlay(FS); - ErrorOr S = O->status("/XX"); + ErrorOr S = O->status("//root/XX"); ASSERT_EQ(errc::success, S.getError()); - ErrorOr SS = O->status("/xx"); + ErrorOr SS = O->status("//root/xx"); ASSERT_EQ(errc::success, SS.getError()); EXPECT_TRUE(S->equivalent(*SS)); - SS = O->status("/xX"); + SS = O->status("//root/xX"); EXPECT_TRUE(S->equivalent(*SS)); - SS = O->status("/Xx"); + SS = O->status("//root/Xx"); EXPECT_TRUE(S->equivalent(*SS)); EXPECT_EQ(0, NumDiagnostics); } TEST_F(VFSFromYAMLTest, CaseSensitive) { IntrusiveRefCntPtr Lower(new DummyFileSystem()); - Lower->addRegularFile("/foo/bar/a"); + Lower->addRegularFile("//root/foo/bar/a"); IntrusiveRefCntPtr FS = getFromYAMLString("{ 'case-sensitive': 'true',\n" " 'roots': [\n" "{\n" " 'type': 'directory',\n" - " 'name': '/',\n" + " 'name': '//root/',\n" " 'contents': [ {\n" " 'type': 'file',\n" " 'name': 'XX',\n" - " 'external-contents': '/foo/bar/a'\n" + " 'external-contents': '//root/foo/bar/a'\n" " }\n" " ]\n" "}]}", @@ -367,11 +368,11 @@ TEST_F(VFSFromYAMLTest, CaseSensitive) { new vfs::OverlayFileSystem(Lower)); O->pushOverlay(FS); - ErrorOr SS = O->status("/xx"); + ErrorOr SS = O->status("//root/xx"); EXPECT_EQ(errc::no_such_file_or_directory, SS.getError()); - SS = O->status("/xX"); + SS = O->status("//root/xX"); EXPECT_EQ(errc::no_such_file_or_directory, SS.getError()); - SS = O->status("/Xx"); + SS = O->status("//root/Xx"); EXPECT_EQ(errc::no_such_file_or_directory, SS.getError()); EXPECT_EQ(0, NumDiagnostics); } @@ -469,113 +470,112 @@ TEST_F(VFSFromYAMLTest, IllegalVFSFile) { TEST_F(VFSFromYAMLTest, UseExternalName) { IntrusiveRefCntPtr Lower(new DummyFileSystem()); - Lower->addRegularFile("/external/file"); + Lower->addRegularFile("//root/external/file"); IntrusiveRefCntPtr FS = getFromYAMLString( "{ 'roots': [\n" - " { 'type': 'file', 'name': '/A',\n" - " 'external-contents': '/external/file'\n" + " { 'type': 'file', 'name': '//root/A',\n" + " 'external-contents': '//root/external/file'\n" " },\n" - " { 'type': 'file', 'name': '/B',\n" + " { 'type': 'file', 'name': '//root/B',\n" " 'use-external-name': true,\n" - " 'external-contents': '/external/file'\n" + " 'external-contents': '//root/external/file'\n" " },\n" - " { 'type': 'file', 'name': '/C',\n" + " { 'type': 'file', 'name': '//root/C',\n" " 'use-external-name': false,\n" - " 'external-contents': '/external/file'\n" + " 'external-contents': '//root/external/file'\n" " }\n" "] }", Lower); ASSERT_TRUE(NULL != FS.getPtr()); // default true - EXPECT_EQ("/external/file", FS->status("/A")->getName()); + EXPECT_EQ("//root/external/file", FS->status("//root/A")->getName()); // explicit - EXPECT_EQ("/external/file", FS->status("/B")->getName()); - EXPECT_EQ("/C", FS->status("/C")->getName()); + EXPECT_EQ("//root/external/file", FS->status("//root/B")->getName()); + EXPECT_EQ("//root/C", FS->status("//root/C")->getName()); // global configuration FS = getFromYAMLString( "{ 'use-external-names': false,\n" " 'roots': [\n" - " { 'type': 'file', 'name': '/A',\n" - " 'external-contents': '/external/file'\n" + " { 'type': 'file', 'name': '//root/A',\n" + " 'external-contents': '//root/external/file'\n" " },\n" - " { 'type': 'file', 'name': '/B',\n" + " { 'type': 'file', 'name': '//root/B',\n" " 'use-external-name': true,\n" - " 'external-contents': '/external/file'\n" + " 'external-contents': '//root/external/file'\n" " },\n" - " { 'type': 'file', 'name': '/C',\n" + " { 'type': 'file', 'name': '//root/C',\n" " 'use-external-name': false,\n" - " 'external-contents': '/external/file'\n" + " 'external-contents': '//root/external/file'\n" " }\n" "] }", Lower); ASSERT_TRUE(NULL != FS.getPtr()); // default - EXPECT_EQ("/A", FS->status("/A")->getName()); + EXPECT_EQ("//root/A", FS->status("//root/A")->getName()); // explicit - EXPECT_EQ("/external/file", FS->status("/B")->getName()); - EXPECT_EQ("/C", FS->status("/C")->getName()); + EXPECT_EQ("//root/external/file", FS->status("//root/B")->getName()); + EXPECT_EQ("//root/C", FS->status("//root/C")->getName()); } TEST_F(VFSFromYAMLTest, MultiComponentPath) { IntrusiveRefCntPtr Lower(new DummyFileSystem()); - Lower->addRegularFile("/other"); + Lower->addRegularFile("//root/other"); // file in roots IntrusiveRefCntPtr FS = getFromYAMLString( "{ 'roots': [\n" - " { 'type': 'file', 'name': '/path/to/file',\n" - " 'external-contents': '/other' }]\n" + " { 'type': 'file', 'name': '//root/path/to/file',\n" + " 'external-contents': '//root/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()); + EXPECT_EQ(errc::success, FS->status("//root/path/to/file").getError()); + EXPECT_EQ(errc::success, FS->status("//root/path/to").getError()); + EXPECT_EQ(errc::success, FS->status("//root/path").getError()); + EXPECT_EQ(errc::success, FS->status("//root/").getError()); // at the start FS = getFromYAMLString( "{ 'roots': [\n" - " { 'type': 'directory', 'name': '/path/to',\n" + " { 'type': 'directory', 'name': '//root/path/to',\n" " 'contents': [ { 'type': 'file', 'name': 'file',\n" - " 'external-contents': '/other' }]}]\n" + " 'external-contents': '//root/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()); + EXPECT_EQ(errc::success, FS->status("//root/path/to/file").getError()); + EXPECT_EQ(errc::success, FS->status("//root/path/to").getError()); + EXPECT_EQ(errc::success, FS->status("//root/path").getError()); + EXPECT_EQ(errc::success, FS->status("//root/").getError()); // at the end FS = getFromYAMLString( "{ 'roots': [\n" - " { 'type': 'directory', 'name': '/',\n" + " { 'type': 'directory', 'name': '//root/',\n" " 'contents': [ { 'type': 'file', 'name': 'path/to/file',\n" - " 'external-contents': '/other' }]}]\n" + " 'external-contents': '//root/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()); + EXPECT_EQ(errc::success, FS->status("//root/path/to/file").getError()); + EXPECT_EQ(errc::success, FS->status("//root/path/to").getError()); + EXPECT_EQ(errc::success, FS->status("//root/path").getError()); + EXPECT_EQ(errc::success, FS->status("//root/").getError()); } TEST_F(VFSFromYAMLTest, TrailingSlashes) { IntrusiveRefCntPtr Lower(new DummyFileSystem()); - Lower->addRegularFile("/other"); + Lower->addRegularFile("//root/other"); // file in roots IntrusiveRefCntPtr FS = getFromYAMLString( "{ 'roots': [\n" - " { 'type': 'directory', 'name': '/path/to////',\n" + " { 'type': 'directory', 'name': '//root/path/to////',\n" " 'contents': [ { 'type': 'file', 'name': 'file',\n" - " 'external-contents': '/other' }]}]\n" + " 'external-contents': '//root/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()); + EXPECT_EQ(errc::success, FS->status("//root/path/to/file").getError()); + EXPECT_EQ(errc::success, FS->status("//root/path/to").getError()); + EXPECT_EQ(errc::success, FS->status("//root/path").getError()); + EXPECT_EQ(errc::success, FS->status("//root/").getError()); } -#endif -- 2.40.0