Use TempDir() in CapturedStream on all non‐Windows platforms

This is more consistent and makes tests using output capture behave
as expected in environments with custom values of `$TEST_TMPDIR`
or `$TMPDIR`, including fixing them in ones where `/tmp` may not be
accessible, such as sandboxed build environments on macOS.
This commit is contained in:
Emily 2025-09-13 19:41:08 +01:00
parent 4ef9218150
commit 7a60b1abe8

View File

@ -1076,13 +1076,7 @@ class CapturedStream {
#else #else
// There's no guarantee that a test has write access to the current // There's no guarantee that a test has write access to the current
// directory, so we create the temporary file in a temporary directory. // directory, so we create the temporary file in a temporary directory.
std::string name_template; std::string name_template = TempDir();
#if defined(GTEST_OS_LINUX_ANDROID) || defined(GTEST_OS_IOS)
name_template = TempDir();
#else
name_template = "/tmp/";
#endif
name_template.append("gtest_captured_stream.XXXXXX"); name_template.append("gtest_captured_stream.XXXXXX");
// mkstemp() modifies the string bytes in place, and does not go beyond the // mkstemp() modifies the string bytes in place, and does not go beyond the