From 612a7d28c1f6ae5372d4a8ed395c37eed8b3fc49 Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Sat, 19 Feb 2022 00:00:00 +0000 Subject: [PATCH] Tests: Respect TEST_TMPDIR, TMPDIR, TMP environmental variables Use GetExistingTempDirectories() (which uses GetTempDirectories() which respects TEST_TMPDIR, TMPDIR, TMP environmental variables) for FLAGS_test_tmpdir variable used in some tests. Fixes: #793 --- src/glog/logging.h.in | 2 +- src/googletest.h | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in index be6d3e5..62a465c 100644 --- a/src/glog/logging.h.in +++ b/src/glog/logging.h.in @@ -1819,7 +1819,7 @@ GLOG_EXPORT const std::vector& GetLoggingDirectories(); void TestOnly_ClearLoggingDirectoriesList(); // Returns a set of existing temporary directories, which will be a -// subset of the directories returned by GetLogginDirectories(). +// subset of the directories returned by GetLoggingDirectories(). // Thread-safe. GLOG_EXPORT void GetExistingTempDirectories( std::vector* list); diff --git a/src/googletest.h b/src/googletest.h index 5e9e7b8..acad8fc 100644 --- a/src/googletest.h +++ b/src/googletest.h @@ -76,13 +76,16 @@ _END_GOOGLE_NAMESPACE_ #define GLOG_EXPORT static inline string GetTempDir() { -#ifndef GLOG_OS_WINDOWS - return "/tmp"; -#else - char tmp[MAX_PATH]; - GetTempPathA(MAX_PATH, tmp); - return tmp; -#endif + vector temp_directories_list; + google::GetExistingTempDirectories(&temp_directories_list); + + if (temp_directories_list.empty()) { + fprintf(stderr, "No temporary directory found\n"); + exit(EXIT_FAILURE); + } + + // Use first directory from list of existing temporary directories. + return temp_directories_list.front(); } #if defined(GLOG_OS_WINDOWS) && defined(_MSC_VER) && !defined(TEST_SRC_DIR)