summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2019-11-28 13:30:39 +0100
committerPavel Labath <pavel@labath.sk>2019-11-28 14:31:29 +0100
commitd1a561d446809cc3b5c11c163b9aa5ba4957af68 (patch)
tree0bab27f620d2cf8d5015603b28151a36608d29e4
parent50e2ffa18da4247e4d45f421c3271b58b936c869 (diff)
downloadbcm5719-llvm-d1a561d446809cc3b5c11c163b9aa5ba4957af68.tar.gz
bcm5719-llvm-d1a561d446809cc3b5c11c163b9aa5ba4957af68.zip
[lldb] Simplify and improve FileSpecTest
Summary: A most of these tests create FileSpecs with a hardcoded style. Add utility functions which create a file spec of a given style to simplify things. While in there add SCOPED_TRACE messages to tests which loop over multiple inputs to ensure it's clear which of the inputs failed. Reviewers: teemperor Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D70814
-rw-r--r--lldb/unittests/Utility/FileSpecTest.cpp48
1 files changed, 24 insertions, 24 deletions
diff --git a/lldb/unittests/Utility/FileSpecTest.cpp b/lldb/unittests/Utility/FileSpecTest.cpp
index 0f5b1652d29..4f91d11fdf1 100644
--- a/lldb/unittests/Utility/FileSpecTest.cpp
+++ b/lldb/unittests/Utility/FileSpecTest.cpp
@@ -12,6 +12,14 @@
using namespace lldb_private;
+static FileSpec PosixSpec(llvm::StringRef path) {
+ return FileSpec(path, FileSpec::Style::posix);
+}
+
+static FileSpec WindowsSpec(llvm::StringRef path) {
+ return FileSpec(path, FileSpec::Style::windows);
+}
+
TEST(FileSpecTest, FileAndDirectoryComponents) {
FileSpec fs_posix("/foo/bar", FileSpec::Style::posix);
EXPECT_STREQ("/foo/bar", fs_posix.GetCString());
@@ -106,8 +114,7 @@ TEST(FileSpecTest, AppendPathComponent) {
}
TEST(FileSpecTest, CopyByAppendingPathComponent) {
- FileSpec fs = FileSpec("/foo", FileSpec::Style::posix)
- .CopyByAppendingPathComponent("bar");
+ FileSpec fs = PosixSpec("/foo").CopyByAppendingPathComponent("bar");
EXPECT_STREQ("/foo/bar", fs.GetCString());
EXPECT_STREQ("/foo", fs.GetDirectory().GetCString());
EXPECT_STREQ("bar", fs.GetFilename().GetCString());
@@ -136,9 +143,7 @@ TEST(FileSpecTest, PrependPathComponent) {
}
TEST(FileSpecTest, EqualSeparator) {
- FileSpec backward("C:\\foo\\bar", FileSpec::Style::windows);
- FileSpec forward("C:/foo/bar", FileSpec::Style::windows);
- EXPECT_EQ(forward, backward);
+ EXPECT_EQ(WindowsSpec("C:\\foo\\bar"), WindowsSpec("C:/foo/bar"));
}
TEST(FileSpecTest, EqualDotsWindows) {
@@ -153,9 +158,8 @@ TEST(FileSpecTest, EqualDotsWindows) {
};
for (const auto &test : tests) {
- FileSpec one(test.first, FileSpec::Style::windows);
- FileSpec two(test.second, FileSpec::Style::windows);
- EXPECT_EQ(one, two);
+ SCOPED_TRACE(llvm::Twine(test.first) + " <=> " + test.second);
+ EXPECT_EQ(WindowsSpec(test.first), WindowsSpec(test.second));
}
}
@@ -169,9 +173,8 @@ TEST(FileSpecTest, EqualDotsPosix) {
};
for (const auto &test : tests) {
- FileSpec one(test.first, FileSpec::Style::posix);
- FileSpec two(test.second, FileSpec::Style::posix);
- EXPECT_EQ(one, two);
+ SCOPED_TRACE(llvm::Twine(test.first) + " <=> " + test.second);
+ EXPECT_EQ(PosixSpec(test.first), PosixSpec(test.second));
}
}
@@ -183,9 +186,8 @@ TEST(FileSpecTest, EqualDotsPosixRoot) {
};
for (const auto &test : tests) {
- FileSpec one(test.first, FileSpec::Style::posix);
- FileSpec two(test.second, FileSpec::Style::posix);
- EXPECT_EQ(one, two);
+ SCOPED_TRACE(llvm::Twine(test.first) + " <=> " + test.second);
+ EXPECT_EQ(PosixSpec(test.first), PosixSpec(test.second));
}
}
@@ -200,7 +202,7 @@ TEST(FileSpecTest, GuessPathStyle) {
EXPECT_EQ(llvm::None, FileSpec::GuessPathStyle("foo/bar.txt"));
}
-TEST(FileSpecTest, GetNormalizedPath) {
+TEST(FileSpecTest, GetPath) {
std::pair<const char *, const char *> posix_tests[] = {
{"/foo/.././bar", "/bar"},
{"/foo/./../bar", "/bar"},
@@ -230,8 +232,7 @@ TEST(FileSpecTest, GetNormalizedPath) {
};
for (auto test : posix_tests) {
SCOPED_TRACE(llvm::Twine("test.first = ") + test.first);
- EXPECT_EQ(test.second,
- FileSpec(test.first, FileSpec::Style::posix).GetPath());
+ EXPECT_EQ(test.second, PosixSpec(test.first).GetPath());
}
std::pair<const char *, const char *> windows_tests[] = {
@@ -262,9 +263,8 @@ TEST(FileSpecTest, GetNormalizedPath) {
{R"(..\..\foo)", R"(..\..\foo)"},
};
for (auto test : windows_tests) {
- EXPECT_EQ(test.second,
- FileSpec(test.first, FileSpec::Style::windows).GetPath())
- << "Original path: " << test.first;
+ SCOPED_TRACE(llvm::Twine("test.first = ") + test.first);
+ EXPECT_EQ(test.second, WindowsSpec(test.first).GetPath());
}
}
@@ -315,8 +315,8 @@ TEST(FileSpecTest, IsRelative) {
"/foo/../.",
};
for (const auto &path: not_relative) {
- FileSpec spec(path, FileSpec::Style::posix);
- EXPECT_FALSE(spec.IsRelative());
+ SCOPED_TRACE(path);
+ EXPECT_FALSE(PosixSpec(path).IsRelative());
}
llvm::StringRef is_relative[] = {
".",
@@ -333,8 +333,8 @@ TEST(FileSpecTest, IsRelative) {
"./foo/bar.c"
};
for (const auto &path: is_relative) {
- FileSpec spec(path, FileSpec::Style::posix);
- EXPECT_TRUE(spec.IsRelative());
+ SCOPED_TRACE(path);
+ EXPECT_TRUE(PosixSpec(path).IsRelative());
}
}
OpenPOWER on IntegriCloud