aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/Path.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2021-09-15 20:48:57 -0400
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2021-10-29 11:46:44 -0700
commit4e4883e1f394f7c47ff3adee48039aa8374bb8d0 (patch)
treeae16f9ea2e10878a1cf37f8f6b26164cb0cb03da /llvm/unittests/Support/Path.cpp
parentd0e9879d9627c82a9c1b97cdf0d8da8829905574 (diff)
downloadllvm-4e4883e1f394f7c47ff3adee48039aa8374bb8d0.zip
llvm-4e4883e1f394f7c47ff3adee48039aa8374bb8d0.tar.gz
llvm-4e4883e1f394f7c47ff3adee48039aa8374bb8d0.tar.bz2
Support: Expose sys::path::is_style_{posix,windows,native}()
Expose three helpers in namespace llvm::sys::path to detect the path rules followed by sys::path::Style. - is_style_posix() - is_style_windows() - is_style_native() This are constexpr functions that that will allow a bunch of path-related code to stop checking `_WIN32`. Originally I looked at adding system_style(), analogous to sys::endian::system_endianness(), but future patches (from others) will add more Windows style variants for slash preferences. These helpers should be resilient to that change, allowing callers to detect basic path rules. Differential Revision: https://reviews.llvm.org/D112288
Diffstat (limited to 'llvm/unittests/Support/Path.cpp')
-rw-r--r--llvm/unittests/Support/Path.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp
index 7f95e6c..59d3f21 100644
--- a/llvm/unittests/Support/Path.cpp
+++ b/llvm/unittests/Support/Path.cpp
@@ -69,6 +69,29 @@ struct FileDescriptorCloser {
int FD;
};
+TEST(is_style_Style, Works) {
+ using namespace llvm::sys::path;
+ // Check platform-independent results.
+ EXPECT_TRUE(is_style_posix(Style::posix));
+ EXPECT_TRUE(is_style_windows(Style::windows));
+ EXPECT_FALSE(is_style_posix(Style::windows));
+ EXPECT_FALSE(is_style_windows(Style::posix));
+
+ // Check platform-dependent results.
+#if defined(_WIN32)
+ EXPECT_FALSE(is_style_posix(Style::native));
+ EXPECT_TRUE(is_style_windows(Style::native));
+#else
+ EXPECT_TRUE(is_style_posix(Style::native));
+ EXPECT_FALSE(is_style_windows(Style::native));
+#endif
+
+ // Check is_style_native().
+ EXPECT_TRUE(is_style_native(Style::native));
+ EXPECT_EQ(is_style_posix(Style::native), is_style_native(Style::posix));
+ EXPECT_EQ(is_style_windows(Style::native), is_style_native(Style::windows));
+}
+
TEST(is_separator, Works) {
EXPECT_TRUE(path::is_separator('/'));
EXPECT_FALSE(path::is_separator('\0'));
@@ -78,11 +101,8 @@ TEST(is_separator, Works) {
EXPECT_TRUE(path::is_separator('\\', path::Style::windows));
EXPECT_FALSE(path::is_separator('\\', path::Style::posix));
-#ifdef _WIN32
- EXPECT_TRUE(path::is_separator('\\'));
-#else
- EXPECT_FALSE(path::is_separator('\\'));
-#endif
+ EXPECT_EQ(path::is_style_windows(path::Style::native),
+ path::is_separator('\\'));
}
TEST(is_absolute_gnu, Works) {
@@ -107,6 +127,10 @@ TEST(is_absolute_gnu, Works) {
std::get<1>(Path));
EXPECT_EQ(path::is_absolute_gnu(std::get<0>(Path), path::Style::windows),
std::get<2>(Path));
+
+ constexpr int Native = is_style_posix(path::Style::native) ? 1 : 2;
+ EXPECT_EQ(path::is_absolute_gnu(std::get<0>(Path), path::Style::native),
+ std::get<Native>(Path));
}
}