r203010 - Attempt to re-enable the VFS unittests on Windows

Ben Langmuir blangmuir at apple.com
Wed Mar 5 13:32:20 PST 2014


Author: benlangmuir
Date: Wed Mar  5 15:32:20 2014
New Revision: 203010

URL: http://llvm.org/viewvc/llvm-project?rev=203010&view=rev
Log:
Attempt to re-enable the VFS unittests on Windows

Using a //net/ path to hopefully avoid problems with non-absolute paths
on Windows.

Modified:
    cfe/trunk/lib/Basic/VirtualFileSystem.cpp
    cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=203010&r1=203009&r2=203010&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Wed Mar  5 15:32:20 2014
@@ -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);

Modified: cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp?rev=203010&r1=203009&r2=203010&view=diff
==============================================================================
--- cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp (original)
+++ cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Wed Mar  5 15:32:20 2014
@@ -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, MergedDirPer
   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<DummyFileSystem> Lower(new DummyFileSystem());
-  Lower->addRegularFile("/foo/bar/a");
+  Lower->addRegularFile("//root/foo/bar/a");
   IntrusiveRefCntPtr<vfs::FileSystem> 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<vfs::Status> S = O->status("/file1");
+  ErrorOr<vfs::Status> 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<vfs::Status> SLower = O->status("/foo/bar/a");
-  EXPECT_EQ("/foo/bar/a", SLower->getName());
+  ErrorOr<vfs::Status> 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<DummyFileSystem> Lower(new DummyFileSystem());
-  Lower->addRegularFile("/foo/bar/a");
+  Lower->addRegularFile("//root/foo/bar/a");
   IntrusiveRefCntPtr<vfs::FileSystem> 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<vfs::Status> S = O->status("/XX");
+  ErrorOr<vfs::Status> S = O->status("//root/XX");
   ASSERT_EQ(errc::success, S.getError());
 
-  ErrorOr<vfs::Status> SS = O->status("/xx");
+  ErrorOr<vfs::Status> 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<DummyFileSystem> Lower(new DummyFileSystem());
-  Lower->addRegularFile("/foo/bar/a");
+  Lower->addRegularFile("//root/foo/bar/a");
   IntrusiveRefCntPtr<vfs::FileSystem> 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<vfs::Status> SS = O->status("/xx");
+  ErrorOr<vfs::Status> 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<DummyFileSystem> Lower(new DummyFileSystem());
-  Lower->addRegularFile("/external/file");
+  Lower->addRegularFile("//root/external/file");
 
   IntrusiveRefCntPtr<vfs::FileSystem> 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<DummyFileSystem> Lower(new DummyFileSystem());
-  Lower->addRegularFile("/other");
+  Lower->addRegularFile("//root/other");
 
   // file in roots
   IntrusiveRefCntPtr<vfs::FileSystem> 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<DummyFileSystem> Lower(new DummyFileSystem());
-  Lower->addRegularFile("/other");
+  Lower->addRegularFile("//root/other");
 
   // file in roots
   IntrusiveRefCntPtr<vfs::FileSystem> 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





More information about the cfe-commits mailing list