diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2018-11-13 18:23:32 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2018-11-13 18:23:32 +0000 |
commit | b23f430ec9d09e9bef611a393f0aeab86b063217 (patch) | |
tree | 9a5284fec47fd118d4082b4aec714789e877b4c5 /llvm/unittests/Support/Path.cpp | |
parent | 7716ddf18d967018c62b2c1dd20a1efda756fed9 (diff) | |
download | bcm5719-llvm-b23f430ec9d09e9bef611a393f0aeab86b063217.tar.gz bcm5719-llvm-b23f430ec9d09e9bef611a393f0aeab86b063217.zip |
[FileSystem] Add expand_tilde function
In D54435 there was some discussion about the expand_tilde flag for
real_path that I wanted to expose through the VFS. The consensus is that
these two things should be separate functions. Since we already have the
code for this I went ahead and added a function expand_tilde that does
just that.
Differential revision: https://reviews.llvm.org/D54448
llvm-svn: 346776
Diffstat (limited to 'llvm/unittests/Support/Path.cpp')
-rw-r--r-- | llvm/unittests/Support/Path.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index c18eb929e91..854b69b6825 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -516,6 +516,8 @@ TEST_F(FileSystemTest, RealPath) { EXPECT_EQ(Expected, Actual); SmallString<64> HomeDir; + + // This can fail if $HOME is not set and getpwuid fails. bool Result = llvm::sys::path::home_directory(HomeDir); if (Result) { ASSERT_NO_ERROR(fs::real_path(HomeDir, Expected)); @@ -528,6 +530,25 @@ TEST_F(FileSystemTest, RealPath) { ASSERT_NO_ERROR(fs::remove_directories(Twine(TestDirectory) + "/test1")); } +TEST_F(FileSystemTest, ExpandTilde) { + SmallString<64> Expected; + SmallString<64> Actual; + SmallString<64> HomeDir; + + // This can fail if $HOME is not set and getpwuid fails. + bool Result = llvm::sys::path::home_directory(HomeDir); + if (Result) { + fs::expand_tilde(HomeDir, Expected); + + fs::expand_tilde("~", Actual); + EXPECT_EQ(Expected, Actual); + + path::append(Expected, "foo"); + fs::expand_tilde("~/foo", Actual); + EXPECT_EQ(Expected, Actual); + } +} + #ifdef LLVM_ON_UNIX TEST_F(FileSystemTest, RealPathNoReadPerm) { SmallString<64> Expanded; |