SupportTests::HomeDirectory: Don't try tests when $HOME is undefined.
authorNAKAMURA Takumi <geek4civic@gmail.com>
Fri, 16 Oct 2015 09:40:01 +0000 (09:40 +0000)
committerNAKAMURA Takumi <geek4civic@gmail.com>
Fri, 16 Oct 2015 09:40:01 +0000 (09:40 +0000)
Lit sanitizes env vars. $HOME is not exported in Lit tests.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250505 91177308-0d34-0410-b5e6-96231b3b80d8

unittests/Support/Path.cpp

index e8cd98b8cfa2b15408bf800f9f173ae70e9a68e3..044e80fe363dec1747a6fc0dd3de41b6f7fde9ae 100644 (file)
@@ -300,19 +300,22 @@ TEST(Support, AbsolutePathIteratorEnd) {
 }
 
 TEST(Support, HomeDirectory) {
 }
 
 TEST(Support, HomeDirectory) {
+  std::string expected;
 #ifdef LLVM_ON_WIN32
   wchar_t *path = ::_wgetenv(L"USERPROFILE");
   auto pathLen = ::wcslen(path);
   ArrayRef<char> ref{reinterpret_cast<char *>(path), pathLen * sizeof(wchar_t)};
 #ifdef LLVM_ON_WIN32
   wchar_t *path = ::_wgetenv(L"USERPROFILE");
   auto pathLen = ::wcslen(path);
   ArrayRef<char> ref{reinterpret_cast<char *>(path), pathLen * sizeof(wchar_t)};
-  std::string expected;
   convertUTF16ToUTF8String(ref, expected);
 #else
   convertUTF16ToUTF8String(ref, expected);
 #else
-  std::string expected{::getenv("HOME")};
+  if (char const *home = ::getenv("HOME"))
+    expected = home;
 #endif
 #endif
-  SmallString<128> HomeDir;
-  auto status = path::home_directory(HomeDir);
-  EXPECT_TRUE(status ^ HomeDir.empty());
-  EXPECT_EQ(expected, HomeDir);
+  if (expected.length() > 0) {
+    SmallString<128> HomeDir;
+    auto status = path::home_directory(HomeDir);
+    EXPECT_TRUE(status ^ HomeDir.empty());
+    EXPECT_EQ(expected, HomeDir);
+  }
 }
 
 class FileSystemTest : public testing::Test {
 }
 
 class FileSystemTest : public testing::Test {