[Lldb-commits] [lldb] d1a561d - [lldb] Simplify and improve FileSpecTest
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu Nov 28 05:43:41 PST 2019
Author: Pavel Labath
Date: 2019-11-28T14:31:29+01:00
New Revision: d1a561d446809cc3b5c11c163b9aa5ba4957af68
URL: https://github.com/llvm/llvm-project/commit/d1a561d446809cc3b5c11c163b9aa5ba4957af68
DIFF: https://github.com/llvm/llvm-project/commit/d1a561d446809cc3b5c11c163b9aa5ba4957af68.diff
LOG: [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
Added:
Modified:
lldb/unittests/Utility/FileSpecTest.cpp
Removed:
################################################################################
diff --git a/lldb/unittests/Utility/FileSpecTest.cpp b/lldb/unittests/Utility/FileSpecTest.cpp
index 0f5b1652d298..4f91d11fdf1e 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());
}
}
More information about the lldb-commits
mailing list