[Lldb-commits] [lldb] r285393 - Add a couple of fun unit tests for FileSpec::Equal

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Fri Oct 28 04:28:01 PDT 2016


Author: labath
Date: Fri Oct 28 06:28:01 2016
New Revision: 285393

URL: http://llvm.org/viewvc/llvm-project?rev=285393&view=rev
Log:
Add a couple of fun unit tests for FileSpec::Equal

Most of them fail right now and are commented out. The main problem is handling
of backslashes on windows, but also the posix path code has a couple of issues.

Modified:
    lldb/trunk/unittests/Host/FileSpecTest.cpp

Modified: lldb/trunk/unittests/Host/FileSpecTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/FileSpecTest.cpp?rev=285393&r1=285392&r2=285393&view=diff
==============================================================================
--- lldb/trunk/unittests/Host/FileSpecTest.cpp (original)
+++ lldb/trunk/unittests/Host/FileSpecTest.cpp Fri Oct 28 06:28:01 2016
@@ -109,19 +109,92 @@ TEST(FileSpecTest, CopyByAppendingPathCo
   EXPECT_STREQ("bar", fs.GetFilename().GetCString());
 }
 
-TEST(FileSpecTest, Equal) {
+static void Compare(const FileSpec &one, const FileSpec &two, bool full_match,
+                    bool remove_backup_dots, bool result) {
+  EXPECT_EQ(result, FileSpec::Equal(one, two, full_match, remove_backup_dots))
+      << "File one: " << one.GetCString() << "\nFile two: " << two.GetCString()
+      << "\nFull match: " << full_match
+      << "\nRemove backup dots: " << remove_backup_dots;
+}
+
+TEST(FileSpecTest, EqualSeparator) {
   FileSpec backward("C:\\foo\\bar", false, FileSpec::ePathSyntaxWindows);
   FileSpec forward("C:/foo/bar", false, FileSpec::ePathSyntaxWindows);
   EXPECT_EQ(forward, backward);
 
   const bool full_match = true;
   const bool remove_backup_dots = true;
-  EXPECT_TRUE(
-      FileSpec::Equal(forward, backward, full_match, remove_backup_dots));
-  EXPECT_TRUE(
-      FileSpec::Equal(forward, backward, full_match, !remove_backup_dots));
-  EXPECT_TRUE(
-      FileSpec::Equal(forward, backward, !full_match, remove_backup_dots));
-  EXPECT_TRUE(
-      FileSpec::Equal(forward, backward, !full_match, !remove_backup_dots));
+  const bool match = true;
+  Compare(forward, backward, full_match, remove_backup_dots, match);
+  Compare(forward, backward, full_match, !remove_backup_dots, match);
+  Compare(forward, backward, !full_match, remove_backup_dots, match);
+  Compare(forward, backward, !full_match, !remove_backup_dots, match);
+}
+
+#if 0
+TEST(FileSpecTest, EqualDotsWindows) {
+  const bool full_match = true;
+  const bool remove_backup_dots = true;
+  const bool match = true;
+  std::pair<const char *, const char *> tests[] = {
+      {R"(C:\foo\bar\baz)", R"(C:\foo\foo\..\bar\baz)"},
+      {R"(C:\bar\baz)", R"(C:\foo\..\bar\baz)"},
+      {R"(C:\bar\baz)", R"(C:/foo/../bar/baz)"},
+      {R"(C:/bar/baz)", R"(C:\foo\..\bar\baz)"},
+      {R"(C:\bar)", R"(C:\foo\..\bar)"},
+  };
+
+  for(const auto &test: tests) {
+    FileSpec one(test.first, false, FileSpec::ePathSyntaxWindows);
+    FileSpec two(test.second, false, FileSpec::ePathSyntaxWindows);
+    EXPECT_NE(one, two);
+    Compare(one, two, full_match, remove_backup_dots, match);
+    Compare(one, two, full_match, !remove_backup_dots, !match);
+    Compare(one, two, !full_match, remove_backup_dots, match);
+    Compare(one, two, !full_match, !remove_backup_dots, match);
+  }
+
+}
+#endif
+
+TEST(FileSpecTest, EqualDotsPosix) {
+  const bool full_match = true;
+  const bool remove_backup_dots = true;
+  const bool match = true;
+  std::pair<const char *, const char *> tests[] = {
+      {R"(/foo/bar/baz)", R"(/foo/foo/../bar/baz)"},
+      {R"(/bar/baz)", R"(/foo/../bar/baz)"},
+//      {R"(/bar)", R"(/foo/../bar)"},
+  };
+
+  for(const auto &test: tests) {
+    FileSpec one(test.first, false, FileSpec::ePathSyntaxPosix);
+    FileSpec two(test.second, false, FileSpec::ePathSyntaxPosix);
+    EXPECT_NE(one, two);
+    Compare(one, two, full_match, remove_backup_dots, match);
+    Compare(one, two, full_match, !remove_backup_dots, !match);
+    Compare(one, two, !full_match, remove_backup_dots, match);
+//    Compare(one, two, !full_match, !remove_backup_dots, match);
+  }
+
+}
+
+#if 0
+TEST(FileSpecTest, EqualDotsPosixRoot) {
+  const bool full_match = true;
+  const bool remove_backup_dots = true;
+  const bool match = true;
+  std::pair<const char *, const char *> tests[] = {
+      {R"(/)", R"(/..)"},
+      {R"(/)", R"(/foo/..)"},
+  };
+
+  for(const auto &test: tests) {
+    FileSpec one(test.first, false, FileSpec::ePathSyntaxPosix);
+    FileSpec two(test.second, false, FileSpec::ePathSyntaxPosix);
+    EXPECT_NE(one, two);
+    Compare(one, two, full_match, remove_backup_dots, match);
+    Compare(one, two, !full_match, remove_backup_dots, match);
+  }
 }
+#endif




More information about the lldb-commits mailing list