[llvm] r250505 - SupportTests::HomeDirectory: Don't try tests when $HOME is undefined.

NAKAMURA Takumi via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 16 02:40:02 PDT 2015


Author: chapuni
Date: Fri Oct 16 04:40:01 2015
New Revision: 250505

URL: http://llvm.org/viewvc/llvm-project?rev=250505&view=rev
Log:
SupportTests::HomeDirectory: Don't try tests when $HOME is undefined.

Lit sanitizes env vars. $HOME is not exported in Lit tests.

Modified:
    llvm/trunk/unittests/Support/Path.cpp

Modified: llvm/trunk/unittests/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Path.cpp?rev=250505&r1=250504&r2=250505&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Path.cpp (original)
+++ llvm/trunk/unittests/Support/Path.cpp Fri Oct 16 04:40:01 2015
@@ -300,19 +300,22 @@ TEST(Support, AbsolutePathIteratorEnd) {
 }
 
 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)};
-  std::string expected;
   convertUTF16ToUTF8String(ref, expected);
 #else
-  std::string expected{::getenv("HOME")};
+  if (char const *home = ::getenv("HOME"))
+    expected = home;
 #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 {




More information about the llvm-commits mailing list