diff options
author | Zachary Turner <zturner@google.com> | 2017-03-22 15:24:59 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-03-22 15:24:59 +0000 |
commit | a3cf70bfa0f11d7da90f11e148be8f9c285c79ac (patch) | |
tree | 475cc356d0425942d77062c822a0c4f531c2c0d2 /llvm/unittests/Support/Path.cpp | |
parent | 50a066b3138a2cda4be733fdc51b35aaf631bfce (diff) | |
download | bcm5719-llvm-a3cf70bfa0f11d7da90f11e148be8f9c285c79ac.tar.gz bcm5719-llvm-a3cf70bfa0f11d7da90f11e148be8f9c285c79ac.zip |
Make home_directory look in the password database in addition to $HOME.
This is something of an edge case, but when the $HOME environment
variable is not set, we can still look in the password database
to get the current user's home directory.
Added a test for this by getting the value of $HOME, then unsetting
it, then calling home_directory() and verifying that it succeeds
and that the value is the same as what we originally read from
the environment.
llvm-svn: 298513
Diffstat (limited to 'llvm/unittests/Support/Path.cpp')
-rw-r--r-- | llvm/unittests/Support/Path.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index 4883adef165..afa5a5a0d46 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -328,6 +328,26 @@ TEST(Support, HomeDirectory) { } } +#ifndef LLVM_ON_WIN32 +TEST(Support, HomeDirectoryWithNoEnv) { + std::string Original; + char const *path = ::getenv("HOME"); + // Don't try to test if we don't have something to compare against. + if (!path) + return; + Original = path; + ::unsetenv("HOME"); + + SmallString<128> HomeDir; + auto status = path::home_directory(HomeDir); + EXPECT_TRUE(status); + EXPECT_EQ(Original, HomeDir); + + // Now put the original environment variable back + ::setenv("HOME", Original.c_str(), 1); +} +#endif + TEST(Support, UserCacheDirectory) { SmallString<13> CacheDir; SmallString<20> CacheDir2; |