summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2016-10-28 11:28:01 +0000
committerPavel Labath <labath@google.com>2016-10-28 11:28:01 +0000
commit10c606295ffe6800558566718c6332355097efa2 (patch)
tree3385b11662ddc022ba281c26fd93f55023a3a2d0
parenta32a961b1087646d74ad65ed953f998496ad1ed6 (diff)
downloadbcm5719-llvm-10c606295ffe6800558566718c6332355097efa2.tar.gz
bcm5719-llvm-10c606295ffe6800558566718c6332355097efa2.zip
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. llvm-svn: 285393
-rw-r--r--lldb/unittests/Host/FileSpecTest.cpp91
1 files changed, 82 insertions, 9 deletions
diff --git a/lldb/unittests/Host/FileSpecTest.cpp b/lldb/unittests/Host/FileSpecTest.cpp
index 765dd9e0b5b..f8a887492f0 100644
--- a/lldb/unittests/Host/FileSpecTest.cpp
+++ b/lldb/unittests/Host/FileSpecTest.cpp
@@ -109,19 +109,92 @@ TEST(FileSpecTest, CopyByAppendingPathComponent) {
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
OpenPOWER on IntegriCloud