Googletest export

Use environment variable TEST_TMPDIR in Linux environments
for temporary directory if available otherwise use /tmp/.

Bazel sets the environment variable TEST_TMPDIR when launching tests.

PiperOrigin-RevId: 342058921
This commit is contained in:
Abseil Team 2020-11-12 12:00:28 -05:00 committed by Mark Barolak
parent a1adec799a
commit 0e202cdbe3

View File

@ -6557,18 +6557,27 @@ std::string TempDir() {
return "\\temp\\";
#elif GTEST_OS_WINDOWS
const char* temp_dir = internal::posix::GetEnv("TEMP");
if (temp_dir == nullptr || temp_dir[0] == '\0')
if (temp_dir == nullptr || temp_dir[0] == '\0') {
return "\\temp\\";
else if (temp_dir[strlen(temp_dir) - 1] == '\\')
} else if (temp_dir[strlen(temp_dir) - 1] == '\\') {
return temp_dir;
else
} else {
return std::string(temp_dir) + "\\";
}
#elif GTEST_OS_LINUX_ANDROID
const char* temp_dir = internal::posix::GetEnv("TEST_TMPDIR");
if (temp_dir == nullptr || temp_dir[0] == '\0')
if (temp_dir == nullptr || temp_dir[0] == '\0') {
return "/data/local/tmp/";
else
} else {
return temp_dir;
}
#elif GTEST_OS_LINUX
const char* temp_dir = internal::posix::GetEnv("TEST_TMPDIR");
if (temp_dir == nullptr || temp_dir[0] == '\0') {
return "/tmp/";
} else {
return temp_dir;
}
#else
return "/tmp/";
#endif // GTEST_OS_WINDOWS_MOBILE