diff options
author | Pawel Bylica <chfast@gmail.com> | 2015-10-16 10:11:07 +0000 |
---|---|---|
committer | Pawel Bylica <chfast@gmail.com> | 2015-10-16 10:11:07 +0000 |
commit | 2fa025cdcf35b2c92fda7f1d47bfc33102bea0ac (patch) | |
tree | b70a8c54ecad8c4f723ea763af2127a4eb3c5d3b /llvm/unittests/Support | |
parent | cc275e428dd2a4a2401992a857f1610d7dbff993 (diff) | |
download | bcm5719-llvm-2fa025cdcf35b2c92fda7f1d47bfc33102bea0ac.tar.gz bcm5719-llvm-2fa025cdcf35b2c92fda7f1d47bfc33102bea0ac.zip |
Fix path::home_directory() unit test.
It turns out that constructing std::string from null pointer is not the very best idea.
llvm-svn: 250506
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r-- | llvm/unittests/Support/Path.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index 044e80fe363..992bba6bcd1 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -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); } } |