[llvm] r250506 - Fix path::home_directory() unit test.
Pawel Bylica via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 16 03:11:07 PDT 2015
Author: chfast
Date: Fri Oct 16 05:11:07 2015
New Revision: 250506
URL: http://llvm.org/viewvc/llvm-project?rev=250506&view=rev
Log:
Fix path::home_directory() unit test.
It turns out that constructing std::string from null pointer is not the very best idea.
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=250506&r1=250505&r2=250506&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Path.cpp (original)
+++ llvm/trunk/unittests/Support/Path.cpp Fri Oct 16 05:11:07 2015
@@ -302,18 +302,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)};
- convertUTF16ToUTF8String(ref, expected);
+ if (wchar_t const *path = ::_wgetenv(L"USERPROFILE")) {
+ auto pathLen = ::wcslen(path);
+ ArrayRef<char> ref{reinterpret_cast<char const *>(path),
+ pathLen * sizeof(wchar_t)};
+ convertUTF16ToUTF8String(ref, expected);
+ }
#else
- if (char const *home = ::getenv("HOME"))
- expected = home;
+ if (char const *path = ::getenv("HOME"))
+ expected = path;
#endif
- if (expected.length() > 0) {
+ // Do not try to test it if we don't know what to expect.
+ // On Windows we use something better than env vars.
+ if (!expected.empty()) {
SmallString<128> HomeDir;
auto status = path::home_directory(HomeDir);
- EXPECT_TRUE(status ^ HomeDir.empty());
+ EXPECT_TRUE(status);
EXPECT_EQ(expected, HomeDir);
}
}
More information about the llvm-commits
mailing list